Skip to content

Commit

Permalink
Fix infinite loop if Sonoff hardware button is pressed (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
datech committed Jan 19, 2019
1 parent 1b08e76 commit a03246c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,32 @@ module.exports = function(RED) {
if (config.enableinput && "nodeid" in msg.payload && msg.payload.nodeid !== null){
msg.payload.deviceid = formatUUID(msg.payload.nodeid);
delete msg.payload["nodeid"];
setDeviceAttributes(msg.payload.deviceid, msg.payload, hubNode.context());
payloadHandler(hubNode, msg.payload.deviceid);

// Send payload if state is changed
var stateChanged = false;
var deviceAttributes = setDeviceAttributes(msg.payload.deviceid, msg.payload, hubNode.context());

for (var key in msg.payload) {
if (deviceAttributes[key] !== undefined && msg.payload[key] !== deviceAttributes[key]){
stateChanged = true;
}
}

if (stateChanged){
payloadHandler(hubNode, msg.payload.deviceid);
}
}
});

hubNode.on('close', function(removed, doneFunction) {
httpServer.stop(function(){
if (typeof doneFunction === 'function')
doneFunction();
RED.log.info("Alexa Local Hub closing done...");
});
setImmediate(function(){
httpServer.emit('close');
});
httpServer.stop(function(){
if (typeof doneFunction === 'function')
doneFunction();
RED.log.info("Alexa Local Hub closing done...");
});
setImmediate(function(){
httpServer.emit('close');
});
});
}

Expand Down

0 comments on commit a03246c

Please sign in to comment.