Skip to content

Commit

Permalink
fix: only auto-refresh Meter and Multilevel Sensor CC values if n…
Browse files Browse the repository at this point in the history
…one were updated recently (#6398)
  • Loading branch information
AlCalzone authored Oct 13, 2023
1 parent 246f1f4 commit 9818c58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/cc/src/cc/MeterCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,16 @@ supports reset: ${suppResp.supportsReset}`;
this: SinglecastCC<this>,
applHost: ZWaveApplicationHost,
): boolean {
// Check when any of the supported values was last updated longer than 6 hours ago.
// This may lead to some unnecessary queries, but at least the values are up to date then
// Poll the device when all of the supported values were last updated longer than 6 hours ago.
// This may lead to some values not being updated, but the user may have disabled some unnecessary
// reports to reduce traffic.
const valueDB = applHost.tryGetValueDB(this.nodeId);
if (!valueDB) return true;

const values = this.getDefinedValueIDs(applHost).filter((v) =>
MeterCCValues.value.is(v)
);
return values.some((v) => {
return values.every((v) => {
const lastUpdated = valueDB.getTimestamp(v);
return (
lastUpdated == undefined
Expand Down
7 changes: 4 additions & 3 deletions packages/cc/src/cc/MultilevelSensorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,16 @@ value: ${mlsResponse.value} ${sensorScale.unit || ""}`;
this: SinglecastCC<this>,
applHost: ZWaveApplicationHost,
): boolean {
// Check when any of the supported values was last updated longer than 6 hours ago.
// This may lead to some unnecessary queries, but at least the values are up to date then
// Poll the device when all of the supported values were last updated longer than 6 hours ago.
// This may lead to some values not being updated, but the user may have disabled some unnecessary
// reports to reduce traffic.
const valueDB = applHost.tryGetValueDB(this.nodeId);
if (!valueDB) return true;

const values = this.getDefinedValueIDs(applHost).filter((v) =>
MultilevelSensorCCValues.value.is(v)
);
return values.some((v) => {
return values.every((v) => {
const lastUpdated = valueDB.getTimestamp(v);
return (
lastUpdated == undefined
Expand Down

0 comments on commit 9818c58

Please sign in to comment.