2.0.0 • Published 2 years ago

@mangar2/devices v2.0.0

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

Abstract

Access device configuration of a json data structure used for a device config file

Contents

Meta

Filedevices.js
AbstractAccess device configuration of a json data structure used for a device config file
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 .

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

NameTypeDescription
configobjectdevice configuration structure

Devices Methods

attributeToDevices

attributeToDevices (attributeName, attributeValue) => {Array.<object>, undefined}

Maps an attribute to a device

attributeToDevices Parameters
NameTypeDescription
attributeNamestringname of the attribute to look foor
attributeValuestringvalue of the attribute
attributeToDevices returns
TypeDescription
Array.<object>, undefinedarray of devices with the same value for attributeName

iterate

iterate (attributeName, callback)

private Iterates through all configured devices

iterate Parameters
NameTypeDescription
attributeNamestringname of the attribute to look for
callbackiterateCallbackfunction called for each topic

topicToDevice

topicToDevice (topic) => {object}

Maps a topic to a device

topicToDevice Parameters
NameTypeDescription
topicstringtopic to search for
topicToDevice returns
TypeDescription
objectdevice info object