UNPKG

node-red-contrib-voice-assistant

Version:

一个小度-小爱-猫精音箱控制NODE-RED自定义设备的节点

73 lines (72 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class GetDeviceManager { constructor(models) { this.models = models; } //获取设略去单前名称 getCurState({ name, id }) { const model = this.models.find((it) => it.id === id); if (!model) return -1; this.attributes = model.attributes; this.state = model.state; this.domain = model.domain; switch (name) { case 'target-temperature': return this.attributes.temperature; break; case 'mode': if (this.domain === 'climate') { return this.attributes.hvac_modes.indexOf(this.state); } return -1; break; case 'power': return this.state === 'off' ? false : true; break; case 'fan-level': if (this.domain === 'climate') { return this.attributes.fan_modes.indexOf(this.attributes.fan_mode); } if (this.domain === 'fan') { return this.attributes.percentage > 60 ? 3 : this.attributes.percentage <= 60 && this.attributes.percentage > 30 ? 2 : 1; } return -1; break; case 'color': return this.attributes.rgb_color; break; case 'brightness': return Math.floor((this.attributes.brightness / 255) * 100); break; case 'oscillate': return this.attributes.oscillating; break; case 'target-position': return this.attributes.set_position; break; case 'current_position': return this.attributes.current_position; break; default: return -1; break; } } //云获取 getProps(data) { return data.map((it) => { try { it.value = this.getCurState(it); if (it.value === undefined || it.value === -1) it.value = 'null'; } catch (_a) { it.value = 'null'; } return it; }); } } exports.default = GetDeviceManager;