Skip to content

Commit

Permalink
fix handling of cached values (#140 #143)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Mar 5, 2021
1 parent f849794 commit 3eb91b5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions nodes/ccu-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,14 @@ module.exports = function (RED) {
loadValues() {
return new Promise(resolve => {
try {
const valuesdata = JSON.parse(fs.readFileSync(this.valuesFile));
const {values} = JSON.parse(fs.readFileSync(this.valuesFile));
this.logger.info('values loaded from', this.valuesFile);
Object.assign(this.values, valuesdata.values);

/* eslint-disable-next-line guard-for-in */
for (const datapointName in values) {
this.values[datapointName] = {...values[datapointName], cache: true, change: false, uncertain: true};
}

resolve();
} catch (error) {
this.logger.error('error loading values ' + error.message);
Expand Down Expand Up @@ -2421,6 +2426,7 @@ module.exports = function (RED) {

if (
description.TYPE === 'ACTION' ||
this.values[datapointName].cache ||
this.values[datapointName].payload !== payload ||
this.values[datapointName].valueStable !== valueStable
) {
Expand Down Expand Up @@ -2731,7 +2737,8 @@ module.exports = function (RED) {
});
const datapointName = iface + '.' + address + '.' + datapoint;
const currentValue = this.values[datapointName] && this.values[datapointName].value;
if (force || (value !== currentValue) || datapoint.startsWith('PRESS_')) {
const cache = this.values[datapointName] && this.values[datapointName].cache;
if (force || (value !== currentValue) || cache || datapoint.startsWith('PRESS_')) {
this.setValueQueue.push({iface, address, datapoint, value, burst, resolve, reject});
this.setValueShiftQueue();
} else {
Expand Down

0 comments on commit 3eb91b5

Please sign in to comment.