Skip to content

Commit

Permalink
fix: consolidate heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Jul 8, 2024
1 parent 92589dc commit 612619f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
32 changes: 8 additions & 24 deletions packages/zwave-js/src/lib/node/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,15 @@ export class Endpoint implements IZWaveEndpoint {
}
}

/** Removes the BasicCC from the supported CCs if the device type forbids it */
public removeBasicCCSupportIfForbidden(): void {
/** Removes the BasicCC from the supported CCs if necessary */
public hideBasicCCSupportIfForbidden(): void {
if (!this.supportsCC(CommandClasses.Basic)) return;

if (
this.supportsCC(CommandClasses.Basic)
&& !this.maySupportBasicCC()
// Basic CC must not be offered if any other actuator CC is supported
actuatorCCs.some((cc) => this.supportsCC(cc))
// ...or the device class forbids it
|| !this.maySupportBasicCC()
) {
// We assume that the device reports support for this CC in error, and that it actually controls it.
// TODO: Consider if we should check additional sources, like the issued commands in AGI CC
Expand All @@ -209,26 +213,6 @@ export class Endpoint implements IZWaveEndpoint {
}
}

/** Removes the BasicCC from the supported CCs if any other actuator CCs are supported */
public hideBasicCCInFavorOfActuatorCCs(): void {
// This behavior is defined in SDS14223
if (
this.supportsCC(CommandClasses.Basic)
&& actuatorCCs.some((cc) => this.supportsCC(cc))
) {
// Mark the CC as not supported, but remember if it is controlled
this.addCC(CommandClasses.Basic, { isSupported: false });

// If the record is now only a dummy, remove the CC entirely
if (
!this.supportsCC(CommandClasses.Basic)
&& !this.controlsCC(CommandClasses.Basic)
) {
this.removeCC(CommandClasses.Basic);
}
}
}

/** Determines if support for a CC was force-removed via config file */
public wasCCRemovedViaConfig(cc: CommandClasses): boolean {
if (this.supportsCC(cc)) return false;
Expand Down
6 changes: 3 additions & 3 deletions packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ export class ZWaveNode extends Endpoint
// Some device types are not allowed to support it, but there are devices that do.
// If a device type is forbidden to support Basic CC, remove the "support" portion of it
for (const endpoint of this.getAllEndpoints()) {
endpoint.removeBasicCCSupportIfForbidden();
endpoint.hideBasicCCSupportIfForbidden();
}

this.setInterviewStage(InterviewStage.CommandClasses);
Expand Down Expand Up @@ -2997,7 +2997,7 @@ protocol version: ${this.protocolVersion}`;
}

// Mark Basic CC as not supported if any other actuator CC is supported
endpoint.hideBasicCCInFavorOfActuatorCCs();
endpoint.hideBasicCCSupportIfForbidden();

// Window Covering CC:
// CL:006A.01.51.01.2: A controlling node MUST NOT interview and provide controlling functionalities for the
Expand Down Expand Up @@ -6309,7 +6309,7 @@ protocol version: ${this.protocolVersion}`;
// compat?.mapBasicReport !== false && compat?.mapBasicSet !== "event"
// ) {
for (const endpoint of this.getAllEndpoints()) {
endpoint.hideBasicCCInFavorOfActuatorCCs();
endpoint.hideBasicCCSupportIfForbidden();
}
// }

Expand Down

0 comments on commit 612619f

Please sign in to comment.