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

Use sendCommand in NoOperationCC #678

Merged
merged 21 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
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