diff --git a/nodes/device.js b/nodes/device.js index 4c69b60..a0929d3 100644 --- a/nodes/device.js +++ b/nodes/device.js @@ -55,7 +55,7 @@ module.exports = function HubitatDeviceModule(RED) { // delete attribute.currentValue; // kept for compatibility node.currentAttributes = device.attributes.reduce((obj, item) => { - obj[item.name] = { ...item, value: item.currentValue }; + obj[item.name] = { ...item, value: item.currentValue, deviceId: node.deviceId }; return obj; }, {}); @@ -101,7 +101,7 @@ module.exports = function HubitatDeviceModule(RED) { node.log('Attributes refreshed'); } if (node.sendEvent) { - const msg = { ...attribute, deviceId: node.deviceId }; + const msg = { ...attribute }; node.send({ payload: msg, topic: node.name }); } } @@ -122,7 +122,7 @@ module.exports = function HubitatDeviceModule(RED) { const attributeSearched = msg.attribute || node.attribute; if (!attributeSearched) { - msg.payload = { ...node.currentAttributes }; // FIXME add deviceId + msg.payload = { ...node.currentAttributes }; msg.topic = node.name; send(msg); node.status({}); @@ -137,7 +137,7 @@ module.exports = function HubitatDeviceModule(RED) { return; } - msg.payload = { ...attribute, deviceId: node.deviceId }; + msg.payload = { ...attribute }; msg.topic = node.name; send(msg); if (!node.attribute) { diff --git a/test/nodes/device_spec.js b/test/nodes/device_spec.js index b1db41d..4cefc23 100644 --- a/test/nodes/device_spec.js +++ b/test/nodes/device_spec.js @@ -60,7 +60,7 @@ describe('Hubitat Device Node', () => { helper.load([deviceNode, configNode], flow, () => { const n1 = helper.getNode('n1'); const n2 = helper.getNode('n2'); - n1.currentAttributes = { testAttribute: { name: 'testAttribute', value: 'old-value' } }; + n1.currentAttributes = { testAttribute: { name: 'testAttribute', value: 'old-value', deviceId: '42' } }; n2.on('input', (msg) => { try { msg.should.have.property('payload', { ...hubitatEvent, currentValue: hubitatEvent.value });