From 0c10a0e601d030bd40d65104c3fe133975517866 Mon Sep 17 00:00:00 2001 From: Evgenii Abramov Date: Sun, 21 Mar 2021 20:19:25 +0300 Subject: [PATCH] Some refactoring --- device.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/device.js b/device.js index caaf437..90596fd 100644 --- a/device.js +++ b/device.js @@ -25,7 +25,7 @@ function convertToYandexValue(val, actType) { /* Device class defenition */ class Device { constructor(options) { - var id = global.devices.length; + const id = global.devices.length; this.data = { id: options.id || String(id), name: options.name || 'Без названия', @@ -41,6 +41,7 @@ class Device { } } + /* Create init state on device object create */ initState(cp) { const {type, parameters} = cp; const actType = String(type).split('.')[2]; @@ -77,26 +78,6 @@ class Device { } } - - getInfo() { - const {id, name, description, room, type, capabilities, properties} = this.data; - return {id, name, description, room, type, capabilities, properties}; - } - - /* Find capability by type */ - findCapability(type) { - return this.data.capabilities.find(c => c.type === type); - } - - /* Unused for now */ - findProperty(type) { - return this.data.properties.find(p => p.type === type); - } - - /* Find topic by instance*/ - findTopicByInstance(instance) { - return this.data.custom_data.mqtt.find(i => i.instance === instance).set; - } /* Get mapped value (if exist) for capability type */ /** @@ -117,6 +98,26 @@ class Device { return (mappedValue != undefined) ? mappedValue : val; } + /* Find capability by type */ + findCapability(type) { + return this.data.capabilities.find(c => c.type === type); + } + + /* Unused for now */ + findProperty(type) { + return this.data.properties.find(p => p.type === type); + } + + /* Find 'set' topic by instance*/ + findTopicByInstance(instance) { + return this.data.custom_data.mqtt.find(i => i.instance === instance).set; + } + + getInfo() { + const {id, name, description, room, type, capabilities, properties} = this.data; + return {id, name, description, room, type, capabilities, properties}; + } + /* Get only needed for response device info (bun not full device defenition) */ getState () { const {id, capabilities, properties} = this.data;