@mangar2/devices
v2.0.0
Published
device manager, access devices of a device.json config file
Downloads
2
Readme
Abstract
Access device configuration of a json data structure used for a device config file
Contents
Meta
| | | | --- | --- | | File | devices.js | | Abstract | Access device configuration of a json data structure used for a device config file | | Author | Volker Böhm | | Copyright | Copyright ( c ) 2020 Volker Böhm | | License | 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 . |
Class Devices
new Devices(config)
Constructs a new device and sets the device configuration
Example
const deviceJson = {
level0: {
room1: {
devices: {
device1: {
'Friendly name': 'Washing machine',
topic: 'cellar/washing machine',
id: 'Washingmachine',
interface: 'zwave'
}
}
}
}
const devices = new Devices(deviceJson)
const deviceByTopic = devices('cellar/washing machine')
const deviceByAttribute = devices('id', 'Washingmachine')
Devices Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| config
| object
| device configuration structure | |
Devices Methods
attributeToDevices
attributeToDevices (attributeName, attributeValue) => {Array.<object>, undefined}
Maps an attribute to a device
attributeToDevices Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| attributeName
| string
| name of the attribute to look foor | |
| attributeValue
| string
| value of the attribute | |
attributeToDevices returns
| Type | Description |
| ---- | ----------- |
| Array.<object>, undefined
| array of devices with the same value for attributeName |
iterate
iterate (attributeName, callback)
private Iterates through all configured devices
iterate Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| attributeName
| string
| name of the attribute to look for | |
| callback
| iterateCallback
| function called for each topic | |
topicToDevice
topicToDevice (topic) => {object}
Maps a topic to a device
topicToDevice Parameters
| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| topic
| string
| topic to search for | |
topicToDevice returns
| Type | Description |
| ---- | ----------- |
| object
| device info object |