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

View File

@@ -22,43 +22,45 @@ module.exports = function(RED) {
// var payload = JSON.parse(msg);
var payload = msg.payload;
if (payload.sid == node.sid && payload.model == "motion") {
var data = payload.data;
if (payload.sid) {
if (payload.sid == node.sid && payload.model == "motion") {
var data = payload.data;
// if (data.status && data.status == "open") {
// node.status({fill:"green", shape:"dot", text:"open"});
// state = "open";
// } else if (data.status && data.status == "close") {
// node.status({fill:"red", shape:"dot", text:"closed"});
// state = "closed";
// }
miDevicesUtils.setStatus(node, data);
// if (data.status && data.status == "open") {
// node.status({fill:"green", shape:"dot", text:"open"});
// state = "open";
// } else if (data.status && data.status == "close") {
// node.status({fill:"red", shape:"dot", text:"closed"});
// state = "closed";
// }
miDevicesUtils.setStatus(node, data);
if (node.output == "0") {
node.send([msg]);
} else if (node.output == "1") {
var status = null;
var duration = null;
if (node.output == "0") {
node.send([msg]);
} else if (node.output == "1") {
var status = null;
var duration = null;
if (data.status) {
status = {"payload": data.status};
if (data.status) {
status = {"payload": data.status};
}
if (data.no_motion) {
status = {"payload": "no_motion"};
duration = {"payload": {"no_motion": data.no_motion}};
}
node.send([[status], [duration]]);
} else if (node.output == "2") {
var status = null;
if (data.status === 'motion') {
status = {"payload": mustache.render(node.motionmsg, data)}
} else {
status = {"payload": mustache.render(node.nomotionmsg, data)}
}
node.send([status]);
}
if (data.no_motion) {
status = {"payload": "no_motion"};
duration = {"payload": {"no_motion": data.no_motion}};
}
node.send([[status], [duration]]);
} else if (node.output == "2") {
var status = null;
if (data.status === 'motion') {
status = {"payload": mustache.render(node.motionmsg, data)}
} else {
status = {"payload": mustache.render(node.nomotionmsg, data)}
}
node.send([status]);
}
}
// Prepare for request