Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cc): implement Inclusion Controller CC #4851

Merged
merged 15 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/api/CCs/InclusionController.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Inclusion Controller CC

?> CommandClass ID: `0x74`

## Inclusion Controller CC methods

### `initiateStep`

```ts
async initiateStep(
nodeId: number,
step: InclusionControllerStep,
): Promise<void>;
```

Instruct the target to initiate the given inclusion step for the given node.

### `completeStep`

```ts
async completeStep(
step: InclusionControllerStep,
status: InclusionControllerStatus,
): Promise<void>;
```

Indicate to the other node that the given inclusion step has been completed.
1 change: 1 addition & 0 deletions docs/api/CCs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- [Humidity Control Mode CC](api/CCs/HumidityControlMode.md)
- [Humidity Control Operating State CC](api/CCs/HumidityControlOperatingState.md)
- [Humidity Control Setpoint CC](api/CCs/HumidityControlSetpoint.md)
- [Inclusion Controller CC](api/CCs/InclusionController.md)
- [Indicator CC](api/CCs/Indicator.md)
- [Irrigation CC](api/CCs/Irrigation.md)
- [Language CC](api/CCs/Language.md)
Expand Down
1 change: 1 addition & 0 deletions docs/api/CCs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The **Command Classes API** provides a high-to-mid level entrypoint which allows
- [Humidity Control Mode CC](api/CCs/HumidityControlMode.md) · `0x6d`
- [Humidity Control Operating State CC](api/CCs/HumidityControlOperatingState.md) · `0x6e`
- [Humidity Control Setpoint CC](api/CCs/HumidityControlSetpoint.md) · `0x64`
- [Inclusion Controller CC](api/CCs/InclusionController.md) · `0x74`
- [Indicator CC](api/CCs/Indicator.md) · `0x87`
- [Irrigation CC](api/CCs/Irrigation.md) · `0x6b`
- [Language CC](api/CCs/Language.md) · `0x89`
Expand Down
243 changes: 103 additions & 140 deletions packages/cc/api.md

Large diffs are not rendered by default.

177 changes: 177 additions & 0 deletions packages/cc/src/cc/InclusionControllerCC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import {
CommandClasses,
Maybe,
MessageOrCCLogEntry,
validatePayload,
} from "@zwave-js/core";
import type { ZWaveApplicationHost, ZWaveHost } from "@zwave-js/host";
import { getEnumMemberName } from "@zwave-js/shared";
import { CCAPI } from "../lib/API";
import {
CommandClass,
gotDeserializationOptions,
type CCCommandOptions,
type CommandClassDeserializationOptions,
} from "../lib/CommandClass";
import {
API,
CCCommand,
commandClass,
implementedVersion,
} from "../lib/CommandClassDecorators";
import {
InclusionControllerCommand,
InclusionControllerStatus,
InclusionControllerStep,
} from "../lib/_Types";

@commandClass(CommandClasses["Inclusion Controller"])
@implementedVersion(1)
export class InclusionControllerCC extends CommandClass {
declare ccCommand: InclusionControllerCommand;
}

@API(CommandClasses["Inclusion Controller"])
export class InclusionControllerCCAPI extends CCAPI {
public supportsCommand(cmd: InclusionControllerCommand): Maybe<boolean> {
switch (cmd) {
case InclusionControllerCommand.Initiate:
case InclusionControllerCommand.Complete:
return true; // This is mandatory
}
return super.supportsCommand(cmd);
}

/** Instruct the target to initiate the given inclusion step for the given node */
public async initiateStep(
nodeId: number,
step: InclusionControllerStep,
): Promise<void> {
this.assertSupportsCommand(
InclusionControllerCommand,
InclusionControllerCommand.Initiate,
);

const cc = new InclusionControllerCCInitiate(this.applHost, {
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
includedNodeId: nodeId,
step,
});
await this.applHost.sendCommand(cc, this.commandOptions);
}

/** Indicate to the other node that the given inclusion step has been completed */
public async completeStep(
step: InclusionControllerStep,
status: InclusionControllerStatus,
): Promise<void> {
this.assertSupportsCommand(
InclusionControllerCommand,
InclusionControllerCommand.Complete,
);

const cc = new InclusionControllerCCComplete(this.applHost, {
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
step,
status,
});
await this.applHost.sendCommand(cc, this.commandOptions);
}
}

interface InclusionControllerCCCompleteOptions extends CCCommandOptions {
step: InclusionControllerStep;
status: InclusionControllerStatus;
}

@CCCommand(InclusionControllerCommand.Complete)
export class InclusionControllerCCComplete extends InclusionControllerCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| InclusionControllerCCCompleteOptions,
) {
super(host, options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
this.step = this.payload[0];
validatePayload.withReason("Invalid inclusion controller step")(
this.step in InclusionControllerStep,
);
this.status = this.payload[1];
} else {
this.step = options.step;
this.status = options.status;
}
}

public step: InclusionControllerStep;
public status: InclusionControllerStatus;

public serialize(): Buffer {
this.payload = Buffer.from([this.step, this.status]);
return super.serialize();
}

public toLogEntry(applHost: ZWaveApplicationHost): MessageOrCCLogEntry {
return {
...super.toLogEntry(applHost),
message: {
step: getEnumMemberName(InclusionControllerStep, this.step),
status: getEnumMemberName(
InclusionControllerStatus,
this.status,
),
},
};
}
}

interface InclusionControllerCCInitiateOptions extends CCCommandOptions {
includedNodeId: number;
step: InclusionControllerStep;
}

@CCCommand(InclusionControllerCommand.Initiate)
export class InclusionControllerCCInitiate extends InclusionControllerCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| InclusionControllerCCInitiateOptions,
) {
super(host, options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
this.includedNodeId = this.payload[0];
this.step = this.payload[1];
validatePayload.withReason("Invalid inclusion controller step")(
this.step in InclusionControllerStep,
);
} else {
this.includedNodeId = options.includedNodeId;
this.step = options.step;
}
}

public includedNodeId: number;
public step: InclusionControllerStep;

public serialize(): Buffer {
this.payload = Buffer.from([this.includedNodeId, this.step]);
return super.serialize();
}

public toLogEntry(applHost: ZWaveApplicationHost): MessageOrCCLogEntry {
return {
...super.toLogEntry(applHost),
message: {
"included node id": this.includedNodeId,
step: getEnumMemberName(InclusionControllerStep, this.step),
},
};
}
}
5 changes: 5 additions & 0 deletions packages/cc/src/cc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ export {
HumidityControlSetpointCCSupportedReport,
HumidityControlSetpointCCValues,
} from "./HumidityControlSetpointCC";
export {
InclusionControllerCC,
InclusionControllerCCComplete,
InclusionControllerCCInitiate,
} from "./InclusionControllerCC";
export {
IndicatorCC,
IndicatorCCGet,
Expand Down
2 changes: 2 additions & 0 deletions packages/cc/src/lib/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ type CCNameMap = {
"Humidity Control Mode": typeof CommandClasses["Humidity Control Mode"];
"Humidity Control Operating State": typeof CommandClasses["Humidity Control Operating State"];
"Humidity Control Setpoint": typeof CommandClasses["Humidity Control Setpoint"];
"Inclusion Controller": typeof CommandClasses["Inclusion Controller"];
Indicator: typeof CommandClasses["Indicator"];
Irrigation: typeof CommandClasses["Irrigation"];
Language: typeof CommandClasses["Language"];
Expand Down Expand Up @@ -646,6 +647,7 @@ export interface CCAPIs {
"Humidity Control Mode": import("../cc/HumidityControlModeCC").HumidityControlModeCCAPI;
"Humidity Control Operating State": import("../cc/HumidityControlOperatingStateCC").HumidityControlOperatingStateCCAPI;
"Humidity Control Setpoint": import("../cc/HumidityControlSetpointCC").HumidityControlSetpointCCAPI;
"Inclusion Controller": import("../cc/InclusionControllerCC").InclusionControllerCCAPI;
Indicator: import("../cc/IndicatorCC").IndicatorCCAPI;
Irrigation: import("../cc/IrrigationCC").IrrigationCCAPI;
Language: import("../cc/LanguageCC").LanguageCCAPI;
Expand Down