@greenapsis/greenetwork-attributes

1.4.1 • Public • Published

Greenetwork Atributtes

Javascript library to manipulate attributes in greenetwork.

Description

In greenetwork there are multiple types of attributes, each of one with differents validations and restrictions. This library helps to handle all of them.

The module can be used as a CommonJS and ES

Usage

Installing

npm i @greenapsis/greenetwork-attributes

Create attribute

To use a attribute and validate, create an instance of it

const { AttributeInteger, AttributeLevelState  } = require('@greenapsis/greenetwork-attributes')

try {
    const voltageSupply = new AttributeInteger(150)
    const level = new AttributeLevelState(0)
} catch (error) {
    //The value was invalid for one attribute
    console.log(error)
}

Attribute's value

The actual value can be read and changed

const {
    AttributeInteger,
    AttributeLevelState,
} = require('@greenapsis/greenetwork-attributes')

const voltageSupply = new AttributeInteger(150)

//get the actual value
console.log(voltageSupply.value)

//change value
voltageSupply.value = 170

//get the new value
console.log(voltageSupply.value)

Attributes names list

Get the list of valids attributes importing the default value of the module

CommonJS
const { attributesNames } = require('@greenapsis/greenetwork-attributes')

//Log the array list of the valid attributes
console.log(Attributes)
ES Modules
import Attributes = from '@greenapsis/greenetwork-attributes'

//Log the array list of the valid attributes
console.log(Attributes)

Validate attribute name

There are a function to check if an attribute name is valid

const { validAttribute } = require('@greenapsis/greenetwork-attributes')

const attributeName = 'AttributeInteger'

//Log the array list of the valid attributes
console.log(validAttribute(attributeName))
// true: valid ; false: invalid

Valid Atrributes types

Each function in greenetwork uses different attributes, check the function - attribute relationships to correctly use each of them

AttributeBinary

Attribute that representes the status of ON and OFF

Valid Values:

  • Integer: 0 - 1
  • String: ["ON", "OFF"]

AttributeBoolean

Attribute that stores a boolean value

Valid values:

  • Boolean: any boolean value

AttributeCommandArray

Attribute that contains an array of device's commands

Valid values:

  • Array: Array of commands

AttributeDateTime

Attribute that stores a date time type value

Valid values:

  • Date: Any Date Object

AttributeFloat

Attribute that stores an float number, this attribute can be integer

Valid values:

  • Number: any number

AttributeInteger

Attribute that stores an integer number, dont accept float values

Valid values:

  • Integer: any integer value

AttributeLevelState

Attribute that stores a level state data type

Valid values:

  • Level State Data Type : The level state has to be in the range: [0 - 3]

AttributeLocation

Attribute that stores a Location data type

Valid values:

  • The Location data type: The Location has to have the following structure
{
    longitude: number,
    latitude: number
}

AttributeParkingSlotOccupancyStatus

Attribute that stores a Occupancy Status data type

Valid values:

  • Occupancy Status data type: ['Closed', 'Vacant','Occupied','Partially Occupied','Forbidden Vehicle','Unknown']

The Ocuppancy list of the valids status is avaible in: AttributeParkingSlotOccupancyStatus.occupancyStatus

AttributeString

Attribute that stores a string value

Valid values:

  • String: any string value

AttributeStringDays

Attribute that stores a week days in string

Valid values:

  • String: list if valid days separate by commas 'Mon,Tue,Wed,Thu,Fri,Sat,Sun'

AttributeStringTime

Attribute that stores a time in string

Valid values:

  • String: with the format '00:00:00', with a valid 24 format hours

Readme

Keywords

Package Sidebar

Install

npm i @greenapsis/greenetwork-attributes

Weekly Downloads

16

Version

1.4.1

License

ISC

Unpacked Size

19.6 kB

Total Files

20

Last publish

Collaborators

  • gadiel_greenapsis
  • gadiel_hdz