2
0

feat(gateway): move to lumi-aqara

Also add gateway search and subdevices discovery.
Closes #28, closes #27, closes #26, closes #17 and fixes #12
This commit is contained in:
Pierre CLEMENT
2018-01-23 10:48:48 +01:00
parent 13d4282923
commit c1299336cb
35 changed files with 725 additions and 176 deletions

View File

@@ -0,0 +1,49 @@
import { Red, NodeProperties } from "node-red";
import { LumiAqara } from "../../../typings/index";
import { Constants } from "../constants";
export interface IGatewayOutNode extends Node {
gatewayConf:any;
gateway: LumiAqara.Gateway;
setGateway(gateway:LumiAqara.Gateway);
}
export default (RED:Red) => {
class GatewayOut {
protected gatewayConf: any;
protected gateway: LumiAqara.Gateway;
constructor(props:NodeProperties) {
RED.nodes.createNode(<any> this, props);
this.gatewayConf= RED.nodes.getNode((<any> props).gateway);
(<any> this).status({fill:"red", shape:"ring", text: "offline"});
this.setMessageListener();
}
protected setMessageListener() {
(<any> this).on("input", (msg) => {
if (msg.hasOwnProperty("payload") && this.gateway) {
if(msg.payload.cmd === "write" && !msg.payload.data.key && this.gateway && this.gateway.sid && this.gateway._key) {
msg.payload.data.key = this.gateway._key;
}
this.gateway._sendUnicast(JSON.stringify(msg.payload));
}
});
}
setGateway(gateway) {
this.gateway = gateway;
this.gateway.setPassword(this.gatewayConf.password);
(<any> this).status({fill:"blue", shape:"dot", text: "online"});
this.gateway.on('offline', () => {
this.gateway = null;
(<any> this).status({fill:"red", shape:"ring", text: "offline"});
});
}
}
RED.nodes.registerType(`${Constants.NODES_PREFIX}-gateway out`, <any> GatewayOut);
};