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:
@@ -39,6 +39,10 @@
|
||||
<dt>gateway <span class="property-type">xiaomi-configurator</span></dt>
|
||||
<dd>The gateway.</dd>
|
||||
</dl>
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">json</span></dt>
|
||||
<dd>Data from gateway, with computed data.</dd>
|
||||
</dl>
|
||||
</li>
|
||||
</ol>
|
||||
</script>
|
||||
|
||||
@@ -12,8 +12,30 @@ module.exports = function(RED) {
|
||||
|
||||
if (this.gateway) {
|
||||
node.on('input', function(msg) {
|
||||
msg.gateway = node.gateway;
|
||||
node.send(msg);
|
||||
// var payload = JSON.parse(msg);
|
||||
var payload = msg.payload;
|
||||
node.log("Received message from: " + payload.model + " sid: " + payload.sid + " payload: " + payload.data);
|
||||
|
||||
// Input from gateway
|
||||
if(payload.sid) {
|
||||
if (payload.sid == node.gateway.sid && ["gateway"].indexOf(payload.model) >= 0) {
|
||||
if(payload.data.rgb) {
|
||||
var decomposed = miDevicesUtils.computeColor(payload.data.rgb);
|
||||
payload.data.brightness = decomposed.brightness;
|
||||
payload.data.color = decomposed.color;
|
||||
}
|
||||
node.send([msg]);
|
||||
}
|
||||
}
|
||||
// Prepare for request
|
||||
else {
|
||||
msg.gateway = node.gateway;
|
||||
msg.sid = node.gateway.sid;
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
|
||||
node.on("close", function() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user