1.1.0 • Published 2 years ago

@mangar2/zwave v1.1.0

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
github
Last release
2 years ago

Abstract

Provides an object to connect openzwave to the yaha mqtt-like broker

--------------------------------------------------------------------------------------------------- This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . File : zwave . js Author : Volker Böhm Copyright : Volker Böhm ---------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------- This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . File : zwavecontroller . js Author : Volker Böhm Copyright : Volker Böhm ---------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------- This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . File : zwave . js Author : Volker Böhm Copyright : Volker Böhm ---------------------------------------------------------------------------------------------------

Contents

Meta

Fileindex.js
AbstractProvides an object to connect openzwave to the yaha mqtt-like broker
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose .

Type definitions

ZwaveValue {Object}

NameTypeDescription
node_idnumberid of the zwave node
class_idnumberid of the zwave parameter class
labelstringlabel of the value changed
instancenumberoptional1index of device instance for a multi instance zwave device
indexnumberoptional0index of the feature for a multi-feature device class

Global functions

_addNode

_addNode (nodeId)

Adds a new zwave device node

_addNode Parameters

NameTypeDescription
nodeIdstringid of the zwave device node

_notification

_notification (node_id, notif)

_notification Parameters

NameTypeDescription
node_idstring, numberid of the node
notifnumbernotification number

_onValueAdded

_onValueAdded (nodeId, comClass, value)

Adds a value to the node tree

_onValueAdded Parameters

NameTypeDescription
nodeIdstringid of the zwave device
comClassstringparameter class
valuestringnew value of the device class

_onValueRemoved

_onValueRemoved (nodeId, comClass, index)

Handles a value removed event by removing the value from the node tree

_onValueRemoved Parameters

NameTypeDescription
nodeIdstringid of the zwave device
comClassstringparameter class
indexstringvalue index

_requestAllConfigParameter

_requestAllConfigParameter (node_id)

Requests all configuration parameter for a dedicated node

_requestAllConfigParameter Parameters

NameType
node_idvalue

_setConfigParam

_setConfigParam (nodeId, paramId, value)

Sets a parameter of a zwave node

_setConfigParam Parameters

NameTypeDescription
nodeIdnumberid of the node
paramIdnumberid of the parameter to set
valuenumberparameter value

_setValue

_setValue (zwaveObject, value)

Sets a value of a zwave object

_setValue Parameters

NameTypeDescription
zwaveObjectobjectzwave object to set the value to
valuestring, number, booleanvalue to set

addDevice

addDevice ()

Enable adding devices

close

async close ()

Disconnects from usb device

constructor

constructor (config)

Constructs a new zwave controller and binds it to an input device

constructor Parameters

NameTypeDescription
configobjectzwave controller configuration

config properties

NameTypeDescription
devicestringzwave controller device ( COM port )
topicstringzwave controller topic to send messages

logNode

logNode (nodeId)

Logs the infos of a zwave device node to console

logNode Parameters

NameTypeDescription
nodeIdstringid of the zwave device node

on

on (event, callback)

Sets a callback .

on Parameters

NameTypeDescription
eventstringevent name ( not case sensitive ) for the callback
callbackfunction( parameter )

on throws

TypeDescription
Errorif the event is not supported
Errorif the callback is not 'function'

prepare

prepare (config, zwave) => {Zwave}

Instantiates exactly one zwave object

prepare Parameters

NameTypeAttributeDefaultDescription
configObjectautomation configuration
zwaveZwaveoptionalnullexisting zwave class

prepare returns

TypeDescription
Zwavethe prepared zwave object

publishValue

publishValue (nodeId, zwaveValue, reasonString)

Publishes a value

publishValue Parameters

NameTypeDescription
nodeIdstringid of the zwave device
zwaveValueobjectnew value information structure of the device class
reasonStringstringthe reason string

publishValueChange

publishValueChange (nodeId, comClass, value)

Publishes a value change

publishValueChange Parameters

NameTypeDescription
nodeIdstringid of the zwave device
comClassstringparameter class
valueobjectnew value information structure of the device class

registerZwaveCallbacks

registerZwaveCallbacks ()

Register callbacks for zwave

removeFailedNode

removeFailedNode ()

Remove/delete a failed node or device

requestConfigParametersForAllNodes

requestConfigParametersForAllNodes ()

Iterates through all configurated nodes and requests their configuration parameters

setDeviceConfiguration

setDeviceConfiguration (devices)

Sets the zwave device configuration

setDeviceConfiguration Parameters

NameTypeDescription
devicesDevicestree of device configuration information

setNodeInfo

setNodeInfo (nodeId, nodeInfo)

Sets the node info

setNodeInfo Parameters

NameTypeDescription
nodeIdstringid of the zwave device node
nodeInfoobjectadditional information for the node

setValue

setValue (topic, value)

Sets a value

setValue Parameters

NameTypeDescription
topicstringname of the topic
valuestring, number, booleanto set

Class ZwaveDevices

new ZwaveDevices()

ZwaveDevices Methods

_calcMatch

_calcMatch (deviceConfig, zwaveValue) => {number}

Calculates the matching of a device and a value

_calcMatch Parameters
NameTypeDescription
deviceConfigDeviceConfignew value information structure of the device class
zwaveValueZwaveValuenew value information structure of the device class
_calcMatch returns
TypeDescription
numbernumber of matching sub-items

_completeDeviceConfig

_completeDeviceConfig (nodes, label, device) => {DeviceConfig}

Gets a full set of zwave identifiers based on the zwave device configuration , default values for instance , index and type - if they are undefined in the configuration and the class_id based on the label - if it is undefined in the configuration

_completeDeviceConfig Parameters
NameTypeDescription
nodesArray.<object>zwave nodes structure
labelstringlabel of the setting
deviceDeviceConfigdevice configuration
_completeDeviceConfig returns
TypeDescription
DeviceConfigdevice configuration filled with default values and label

_getObjectByLabel

_getObjectByLabel (nodes, label, nodeId, instanceId)

Gets a zwave controllable element by label

_getObjectByLabel Parameters
NameTypeAttributeDefaultDescription
nodesArray.<object>zwave nodes structure
labelstringlabel of the setting
nodeIdnumberid of the node
instanceIdnumberoptional1id of the instance

_getObjectByLabelRec

_getObjectByLabelRec (object, label, instance)

Recursively searches for an object in the zwave node tree

_getObjectByLabelRec Parameters
NameTypeDescription
objectobjectobject to search for the right zwave object
labelstringlabel of the zwave object to search for
instancenumberinstance number of the zwave object to search for

constructor

constructor (config)

Constructs a new zwave controller and binds it to an input device

constructor Parameters
NameTypeDescription
configobjectzwave controller configuration

config properties

NameTypeDescription
devicesobject, arraydevice definition structure

topicToZwaveId

topicToZwaveId (nodes, topic, label) => {DeviceConfig}

Gets a full set of zwave identifiers based on the zwave device configuration , default values for instance , index and type - if they are undefined in the configuration and the class_id based on the label - if it is undefined in the configuration

topicToZwaveId Parameters
NameTypeDescription
nodesArray.<object>zwave nodes structure
topictopictopic to look for
labelstringlabel of the setting
topicToZwaveId returns
TypeDescription
DeviceConfigzwaveId ( node_id , class_id , instance , index , type )

valueToTopicAndType

valueToTopicAndType (zwaveValue) => {Object.<topic:string, type:string>}

Gets the right topic for a value object

valueToTopicAndType Parameters
NameTypeDescription
zwaveValueZwaveValuenew value information structure of the device class
valueToTopicAndType returns
TypeDescription
Object.<topic:string, type:string>topic , if found and device type . Both can be undefined

Class ZwaveService

new ZwaveService(options)

Creates a remote service

ZwaveService Parameters

NameTypeDescription
optionsObjectconfiguration settings for zwave

options properties

NameTypeDescription
usbstringzwave usb device name
servicesArray.<Service>list of supported services

ZwaveService Methods

_setValueIdToDevices

_setValueIdToDevices ()

Iterates through the zwave devices adding value ids

close

async close ()

Closes the broker , stops listening

getSubscriptions

getSubscriptions () => {topic:qos}

Gets the list of required subscriptions for this service

getSubscriptions returns
TypeDescription
topic:qoslist of subscription strings

handleMessage

handleMessage (message)

Processes an incoming mqtt message

handleMessage Parameters
NameTypeDescription
messageMessagemqtt message

on

on (event, callback)

Sets a callback .

on Parameters
NameTypeDescription
eventstringevent name ( not case sensitive ) for the callback
callbackfunctionfunction ( . . . parameter )
on throws
TypeDescription
Errorif the event is not supported
Errorif the callback is not 'function'

run

run ()

Called once after registration to handle additional tasks

setDeviceConfiguration

setDeviceConfiguration (config)

setDeviceConfiguration Parameters
NameTypeDescription
configObjectconfiguration settings for zwave