From 51823e190599564ec5287f7a23ff2edc325e69b4 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 25 Jun 2024 22:10:10 +0200 Subject: [PATCH] fix: edge cases for Basic CC values in combination with compat flags --- packages/cc/src/cc/BasicCC.ts | 51 +++++++++++++++++++++++++++++++-- packages/cc/src/cc/VersionCC.ts | 1 + 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/cc/src/cc/BasicCC.ts b/packages/cc/src/cc/BasicCC.ts index c9776dd75fed..36800873e9bb 100644 --- a/packages/cc/src/cc/BasicCC.ts +++ b/packages/cc/src/cc/BasicCC.ts @@ -332,9 +332,11 @@ remaining duration: ${basicResponse.duration?.toString() ?? "undefined"}`; // Add the compat event value if it should be exposed ret.push(BasicCCValues.compatEvent.endpoint(endpoint.index)); } else if ( - endpoint.controlsCC(CommandClasses.Basic) - || compat?.mapBasicReport === false - || compat?.mapBasicSet === "report" + !endpoint.supportsCC(CommandClasses.Basic) && ( + endpoint.controlsCC(CommandClasses.Basic) + || compat?.mapBasicReport === false + || compat?.mapBasicSet === "report" + ) ) { // Otherwise, only expose currentValue on devices that only control Basic CC, // or devices where a compat flag indicates that currentValue is meant to be exposed @@ -434,6 +436,49 @@ export class BasicCCReport extends BasicCC { @ccValue(BasicCCValues.duration) public readonly duration: Duration | undefined; + public persistValues(applHost: ZWaveApplicationHost): boolean { + // Basic CC Report persists its values itself, since there are some + // specific rules when which value may be persisted. + // These rules are essentially encoded in the getDefinedValueIDs overload, + // so we simply reuse that here. + + // Figure out which values may be persisted. + const definedValueIDs = this.getDefinedValueIDs(applHost); + const shouldPersistCurrentValue = definedValueIDs.some((vid) => + BasicCCValues.currentValue.is(vid) + ); + const shouldPersistTargetValue = definedValueIDs.some((vid) => + BasicCCValues.targetValue.is(vid) + ); + const shouldPersistDuration = definedValueIDs.some((vid) => + BasicCCValues.duration.is(vid) + ); + + if (this.currentValue !== undefined && shouldPersistCurrentValue) { + this.setValue( + applHost, + BasicCCValues.currentValue, + this.currentValue, + ); + } + if (this.targetValue !== undefined && shouldPersistTargetValue) { + this.setValue( + applHost, + BasicCCValues.targetValue, + this.targetValue, + ); + } + if (this.duration !== undefined && shouldPersistDuration) { + this.setValue( + applHost, + BasicCCValues.duration, + this.duration, + ); + } + + return true; + } + public serialize(): Buffer { this.payload = Buffer.from([ this.currentValue ?? 0xfe, diff --git a/packages/cc/src/cc/VersionCC.ts b/packages/cc/src/cc/VersionCC.ts index 12e74ae5d2aa..105976913938 100644 --- a/packages/cc/src/cc/VersionCC.ts +++ b/packages/cc/src/cc/VersionCC.ts @@ -472,6 +472,7 @@ export class VersionCC extends CommandClass { let logMessage: string; if (supportedVersion > 0) { endpoint.addCC(cc, { + isSupported: true, version: supportedVersion, }); logMessage = ` supports CC ${CommandClasses[cc]} (${