Skip to content

Commit

Permalink
use setValueQueued
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Feb 2, 2019
1 parent 27adb65 commit 69d99d0
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions nodes/ccu-set-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = function (RED) {
this.whitelist = new Set();

this.on('input', msg => {
this.shiftQueue(this.createQueue(msg));
this.setValues(msg);
});

this.on('close', this._destructor);
Expand All @@ -58,8 +58,7 @@ module.exports = function (RED) {
statusHelper(this, data);
}

createQueue(msg) {
const queue = [];
setValues(msg) {
let count = 0;
Object.keys(this.ccu.metadata.devices).forEach(iface => {
if (this.iface && iface !== this.iface) {
Expand Down Expand Up @@ -210,25 +209,13 @@ module.exports = function (RED) {
const currentValue = this.ccu.values[datapointName] && this.ccu.values[datapointName].value;
count += 1;
if (dp.startsWith('PRESS_') || typeof currentValue === 'undefined' || currentValue !== msg.payload) {
queue.push({iface, params: [address, dp, msg.payload]});
this.ccu.setValueQueued(iface, address, dp, msg.payload);
}
});
}
});
});
this.status({fill: 'green', shape: 'ring', text: String(count) + ' datapoints'});
return queue;
}

shiftQueue(queue) {
if (queue.length > 0) {
const {iface, params} = queue.shift();
const [address, datapoint, value] = params;
this.ccu.setValue(iface, address, datapoint, value);
setTimeout(() => {
this.shiftQueue(queue);
}, this.delay);
}
}
}

Expand Down

0 comments on commit 69d99d0

Please sign in to comment.