2
0
Files
node-red-contrib-mi-devices/src/nodes/yeelight/YeelightOut.ts
Pierre CLEMENT 13d4282923 feat(yeelight): move to yeelight-wifi
Also add the configurator node, typescript & ejs.
Close #29 #25 #24
2018-01-20 13:23:08 +01:00

53 lines
1.9 KiB
TypeScript

import { Red, Node, NodeProperties, NodeStatus, ClearNodeStatus } from "node-red";
import { Constants } from "../constants";
import { IYeelightConfiguratorNode } from "./YeelightConfigurator";
export interface IYeelightOutNode {
yeelightNode:IYeelightConfiguratorNode;
}
export default (RED:Red) => {
class YeelightOut implements IYeelightOutNode {
yeelightNode:IYeelightConfiguratorNode;
constructor(props: NodeProperties) {
RED.nodes.createNode(<any> this, props);
this.yeelightNode = <any> RED.nodes.getNode((<any> props).yeelight);
(<any> this).status({fill: "red", shape: "ring", text: "offline"});
this.yeelightNode && this.yeelightNode.on('bulbFound', () => {
(<any>this).status({fill:"blue", shape:"dot", text: "online"});
});
this.setListener();
}
protected setListener() {
(<any> 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.NODES_PREFIX}-yeelight out`, <any> YeelightOut);
};