From a035c8c9f5c2d8fead8dd21c51b8edd92ab906e6 Mon Sep 17 00:00:00 2001 From: Teodor Ivanov Date: Mon, 21 Jan 2019 00:21:43 +0200 Subject: [PATCH] Fix input of Amazon Echo Hub Node --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0a5669b..cba7dab 100644 --- a/index.js +++ b/index.js @@ -60,21 +60,24 @@ module.exports = function(RED) { hubNode.on('input', function(msg) { - if (config.enableinput && "nodeid" in msg.payload && msg.payload.nodeid !== null){ + if (config.enableinput && + typeof msg.payload === "object" && "nodeid" in msg.payload && msg.payload.nodeid !== null){ + msg.payload.deviceid = formatUUID(msg.payload.nodeid); delete msg.payload["nodeid"]; // Send payload if state is changed var stateChanged = false; - var deviceAttributes = setDeviceAttributes(msg.payload.deviceid, msg.payload, hubNode.context()); + var deviceAttributes = getDeviceAttributes(msg.payload.deviceid, hubNode.context()); for (var key in msg.payload) { - if (deviceAttributes[key] !== undefined && msg.payload[key] !== deviceAttributes[key]){ + if (key in deviceAttributes && msg.payload[key] !== deviceAttributes[key]){ stateChanged = true; } } if (stateChanged){ + setDeviceAttributes(msg.payload.deviceid, msg.payload, hubNode.context()); payloadHandler(hubNode, msg.payload.deviceid); } }