giri-sector-control v2.4.1
giri-sector-control
This is a seneca plugin, that contains the sector level microservices of the giri system.
Prerequisites
The plugin needs the following seneca plugins to be used:
Installation
Run the install command:
npm install
Run tests:
$ npm test
To see the coverage, run:
npm run coverage
Usage
To load the plugin:
seneca.use('giri-sector-control')
Options
There are no options for this plugin.
Actions
All actions provide results via the standard callback format: function(error,data){ ... }
.
role: giri-sector-control, cmd: getSectors
Get a list on all of the sectors available.
Parameters:
- None
Response:
- The array of available sector objects.
role: giri-sector-control, cmd: getClusterSectors
Get a list on all of the sectors available and belongs to the selected cluster.
Parameters:
clusterId
: Theid
of the cluster the sectors belong to. It is theclusterId
property of the sector object.
Response:
- The array of available sector objects with the given
clusterId
.
role: giri-sector-control, cmd: getSector
Get the sector selected by its id
Parameters:
payload
:idx
: the index of the sector in the cluster,
Response:
payload
: The sector object, incl. the properties listed below.name
: the name of the sector,clusterId
: the id of the cluster the sector belongs to,idx
: the index of the sector in the cluster,config
: the actual configuration of the sector:mode
: The working mode of the sector, that is one of the following value:INACTIVE
,MANUAL
,AUTO
,startAt
: cron pattern string of start the active period, ifmode
isAUTO
,duration
: length of period in minutes, ifmode
isAUTO
,
state
: the required state of the sector,port
: the port configuration parameters, the sector is using, including:deviceId
: the physical device id of the port device used by the sector to switch the solenoid,portIdx
: the index of the port on the physical device.
role: giri-sector-control, cmd: createSector
Create a new sector, with a generated unique id
.
Parameters:
payload
: The sector object, to create. The sector object may have the following properties:name
: the name of the sector,clusterId
: the id of the cluster the sector belongs to,idx
: the index of the sector in the cluster,config
: the actual configuration of the sector:mode
: The working mode of the sector, that is one of the following value:INACTIVE
,MANUAL
,AUTO
,startAt
: cron pattern string of start the active period, ifmode
isAUTO
,duration
: length of period in minutes, ifmode
isAUTO
,
state
: the required state of the sector,port
: the port configuration parameters, the sector is using, including:deviceId
: the physical device id of the port device used by the sector to switch the solenoid,portIdx
: the index of the port on the physical device.
Response:
- The sector object, which equals to the incoming message
payload
object, incl. the properties listed above, plus theid
.
After creation the sector immediately goes into the working mode that is defined by the config
and state
properties.
role: giri-sector-control, cmd: updateSector
Updates the properties of a sector, selected by its id
.
If there is no sector found with the given id
, then it creates a new one with this id
,
and sets its actual properties according to the input parameters.
Parameters:
payload
: The sector object, to create. The sector object may have the following properties:id
: the unique id of the sector,name
: the name of the sector,clusterId
: the id of the cluster the sector belongs to,idx
: the index of the sector in the cluster,config
: the actual configuration of the sector:mode
: The working mode of the sector, that is one of the following value:INACTIVE
,MANUAL
,AUTO
,startAt
: cron pattern string of start the active period, ifmode
isAUTO
,duration
: length of period in minutes, ifmode
isAUTO
,
state
: the required state of the sector,port
: the port configuration parameters, the sector is using, including:deviceId
: the physical device id of the port device used by the sector to switch the solenoid,portIdx
: the index of the port on the physical device.
Response:
- The updated sector object which equals to the incoming message
payload
object.
The update may cause state transition of the sector, depending on its actual state before the update, and the incoming
payload. The current state and the payload's config
and state
properties will determine the new mode
and state
accoring to the execution of the following steps:
- If the actual
config.mode
isAUTO
, then change toINACTIVE
mode:
1.1 stop the timer, that is actually running,
1.2 set config.mode
to INACTIVE
,
1.3 remove the timer parameters.
- The
config.mode
is set to the new value, which is the value ofpayload.config.mode
property. - If the new
payload.config.mode
isINACTIVE
orAUTO
, then thestate
of the sector is always has to be set toOFF
. In case it isMANUAL
, then it is set to the value ofpayload.state
. - Send a
setState
command to the valve according to the new value of thestate
property of the sector. - If the new
config.mode
isAUTO
, then start the timer, with itsstartAt
andduration
parameters.
In AUTO
mode, the timer will activate the valve, when the active period starts, and will deactivate, when the period ends.
role: giri-sector-control, cmd: resetSector
Reset the sector selected by its id
.
The sector will be set to INACTIVE
mode, and the state
to OFF
.
Parameters:
payload
: An object, which holds theid
of the sector to reset.id
. Theid
of the sector to reset.
Response:
- An empty
{}
object.
References
- giri home page
- Seneca.js
- How to Write a Seneca Plugin
- Seneca plugins
- Chai Assertion Library / BDD API Reference
- node-schedule
- cron-parser
This project was generated from the seneca-plugin-archetype by the kickoff utility.