node-red-contrib-mi-sensors
Version:
A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway, and the Gateway itself.
40 lines (39 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../constants");
exports.default = (RED) => {
class YeelightOut {
constructor(props) {
RED.nodes.createNode(this, props);
this.yeelightNode = RED.nodes.getNode(props.yeelight);
this.status({ fill: "red", shape: "ring", text: "offline" });
this.yeelightNode && this.yeelightNode.on('bulbFound', () => {
this.status({ fill: "blue", shape: "dot", text: "online" });
});
this.setListener();
}
setListener() {
this.on('input', (msg) => {
if (this.yeelightNode.bulb) {
if (msg.payload === "on") {
this.yeelightNode.bulb.turnOn();
}
else if (msg.payload === "off") {
this.yeelightNode.bulb.turnOff();
}
else if (msg.payload === "toggle") {
this.yeelightNode.bulb.toggle();
}
if (msg.payload.color !== undefined) {
// TODO: revoir la couleur
this.yeelightNode.bulb.setRGB(msg.payload.color);
}
if (msg.payload.brightness !== undefined) {
this.yeelightNode.bulb.setBrightness(msg.payload.brightness);
}
}
});
}
}
RED.nodes.registerType(`${constants_1.Constants.NODES_PREFIX}-yeelight out`, YeelightOut);
};