UNPKG

node-red-dashboard-2-t86

Version:

Set of Node-RED nodes to controll home automation based on Unipi Patron and DALI.

45 lines (44 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = main; class DimmLightDashboard { constructor(RED, node, config) { this.RED = RED; this.node = node; RED.nodes.createNode(node, config); this.group = RED.nodes.getNode(config.group); if (!this.group) { this.node.error(`Node ${config.name}(${config.id}) hasn't configured Group`); return; } this.base = this.group.getBase(); this.group.register(node, config, { onChange: true, beforeSend: this.beforeSend.bind(this) }); } beforeSend(msg) { const updates = msg.ui_update; if (updates) { if (typeof updates.brightnessMin === 'number') { this.base.state.set(this.base, this.node, msg, 'brightnessMin', updates.brightnessMin); } if (typeof updates.brightnessMax === 'number') { this.base.state.set(this.base, this.node, msg, 'brightnessMax', updates.brightnessMax); } if (typeof updates.temperatureMin === 'number') { this.base.state.set(this.base, this.node, msg, 'temperatureMin', updates.temperatureMin); } if (typeof updates.temperatureMax === 'number') { this.base.state.set(this.base, this.node, msg, 'temperatureMax', updates.temperatureMax); } } return msg; } } // Register constructor function with Node-RED function main(RED) { RED.nodes.registerType('ui-dimm-light', function (config) { new DimmLightDashboard(RED, this, config); }); }