mirror of
https://github.com/lasthead0/yandex2mqtt.git
synced 2025-08-08 09:01:00 +03:00
Some refactoring
This commit is contained in:
43
device.js
43
device.js
@@ -25,7 +25,7 @@ function convertToYandexValue(val, actType) {
|
|||||||
/* Device class defenition */
|
/* Device class defenition */
|
||||||
class Device {
|
class Device {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
var id = global.devices.length;
|
const id = global.devices.length;
|
||||||
this.data = {
|
this.data = {
|
||||||
id: options.id || String(id),
|
id: options.id || String(id),
|
||||||
name: options.name || 'Без названия',
|
name: options.name || 'Без названия',
|
||||||
@@ -41,6 +41,7 @@ class Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create init state on device object create */
|
||||||
initState(cp) {
|
initState(cp) {
|
||||||
const {type, parameters} = cp;
|
const {type, parameters} = cp;
|
||||||
const actType = String(type).split('.')[2];
|
const actType = String(type).split('.')[2];
|
||||||
@@ -78,26 +79,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 */
|
/* Get mapped value (if exist) for capability type */
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -117,6 +98,26 @@ class Device {
|
|||||||
return (mappedValue != undefined) ? mappedValue : val;
|
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) */
|
/* Get only needed for response device info (bun not full device defenition) */
|
||||||
getState () {
|
getState () {
|
||||||
const {id, capabilities, properties} = this.data;
|
const {id, capabilities, properties} = this.data;
|
||||||
|
Reference in New Issue
Block a user