feat(yeelight): move to yeelight-wifi
Also add the configurator node, typescript & ejs. Close #29 #25 #24
This commit is contained in:
52
src/nodes/yeelight/YeelightOut.ts
Normal file
52
src/nodes/yeelight/YeelightOut.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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);
|
||||
};
|
||||
Reference in New Issue
Block a user