Skip to content

Commit

Permalink
fix: edge cases for Basic CC values in combination with compat flags
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Jun 25, 2024
1 parent dcc791f commit 51823e1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
51 changes: 48 additions & 3 deletions packages/cc/src/cc/BasicCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/cc/src/cc/VersionCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]} (${
Expand Down

0 comments on commit 51823e1

Please sign in to comment.