Skip to content

Commit

Permalink
device: embedded deviceId in internal object
Browse files Browse the repository at this point in the history
reason: simplify logic
  • Loading branch information
fblackburn1 committed Apr 15, 2020
1 parent 02fb06d commit 8f0643f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions nodes/device.js
Expand Up @@ -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;
}, {});

Expand Down Expand Up @@ -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 });
}
}
Expand All @@ -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({});
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/nodes/device_spec.js
Expand Up @@ -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 });
Expand Down

0 comments on commit 8f0643f

Please sign in to comment.