2
0

feat(gateway): allow to change the light color

Major fix on devices, set output only when no payload.sid is present
This commit is contained in:
Pierre CLEMENT
2018-01-01 20:47:30 +01:00
parent 9da0427164
commit 5732c80039
13 changed files with 292 additions and 136 deletions
@@ -73,4 +73,29 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("xiaomi-actions double_click", XiaomiActionDoubleClick);
function XiaomiActionGatewayLight(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
var node = this;
node.on('input', function(msg) {
if(node.gateway && node.gateway.sid && node.gateway.key && node.gateway.lastToken) {
var rgb = miDevicesUtils.computeColorValue(msg.brightness, msg.color.red, msg.color.green, msg.color.blue);
msg.payload = {
cmd: "write",
data: {
rgb: rgb,
sid: node.gateway.sid,
key: miDevicesUtils.getGatewayKey(node.gateway.key, node.gateway.lastToken)
}
};
node.send(msg);
}
});
}
RED.nodes.registerType("xiaomi-actions gateway_light", XiaomiActionGatewayLight);
}