-
-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cc): implement Inclusion Controller CC (#4851)
- Loading branch information
Showing
17 changed files
with
946 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.