Skip to content

Commit

Permalink
Use sendCommand in NoOperationCC (#678)
Browse files Browse the repository at this point in the history
* build: upgrade to TypeScript 3.8 (Beta)

* build: replace type-only imports with `import type`

* refactor: eliminate IDriver, use import type instead

* refactor: eliminate IZWaveNode, use import type instead

* fix: fix build errors

* test: remove obsolete test files

* build: use pre-release Babel version to fix tests

* fix: use type imports in tests

* refactor: extract constants and types from Node.ts

* refactor: import CCs in the main entry point

* fix: use transpile-only version of ts-node

* style: apply Prettier formatting

* fix: fix build

* refactor: use sendCommand in NoOperationCC

* style: formatting
  • Loading branch information
AlCalzone committed Mar 22, 2020
1 parent 8cdb70c commit f58fe44
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 74 deletions.
76 changes: 15 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions src/lib/commandclass/NoOperationCC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SendDataRequest } from "../controller/SendDataMessages";
import { MessagePriority } from "../message/Constants";
import type { Message } from "../message/Message";
import { CCAPI } from "./API";
Expand All @@ -17,27 +16,25 @@ import { isCommandClassContainer } from "./ICommandClassContainer";
@API(CommandClasses["No Operation"])
export class NoOperationCCAPI extends CCAPI {
public async send(): Promise<void> {
const request = new SendDataRequest(this.driver, {
command: new NoOperationCC(this.driver, {
await this.driver.sendCommand(
new NoOperationCC(this.driver, {
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
}),
});
// Don't retry sending ping packets
request.maxSendAttempts = 1;
// set the priority manually, as SendData can be Application level too
await this.driver.sendMessage<SendDataRequest>(request, {
priority: MessagePriority.NodeQuery,
});
{
// Don't retry sending ping packets
maxSendAttempts: 1,
// set the priority manually, as SendData can be Application level too
priority: MessagePriority.NodeQuery,
},
);
}
}

@commandClass(CommandClasses["No Operation"])
@implementedVersion(1)
export class NoOperationCC extends CommandClass {
declare ccCommand: undefined;
// Force singlecast
declare nodeId: number;
}

/** Tests if a given message is a ping */
Expand Down
10 changes: 9 additions & 1 deletion src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export interface SendMessageOptions {
supportCheck?: boolean;
}

export interface SendCommandOptions extends SendMessageOptions {
/** How many times the driver should try to send the message. Defaults to `MAX_SEND_ATTEMPTS` */
maxSendAttempts?: number;
}

export type SupervisionUpdateHandler = (
status: SupervisionStatus,
remainingDuration?: Duration,
Expand Down Expand Up @@ -1629,7 +1634,7 @@ ${handlers.length} left`,
// wotan-disable-next-line no-misused-generics
public async sendCommand<TResponse extends CommandClass = CommandClass>(
command: CommandClass,
options: SendMessageOptions = {},
options: SendCommandOptions = {},
): Promise<TResponse | undefined> {
let msg: Message;
if (command.isSinglecast()) {
Expand All @@ -1642,6 +1647,9 @@ ${handlers.length} left`,
ZWaveErrorCodes.Argument_Invalid,
);
}
// Specify the number of send attempts for the request
msg.maxSendAttempts = options.maxSendAttempts;

const resp = await this.sendMessage(msg, options);
if (isCommandClassContainer(resp)) {
return resp.command as TResponse;
Expand Down

0 comments on commit f58fe44

Please sign in to comment.