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: make timeout to send devices back to sleep configurable, lower default to 250 ms #6312

Merged
merged 4 commits into from
Sep 25, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const defaultOptions: ZWaveOptions = {
report: 1000, // ReportTime timeout SHOULD be set to CommandTime + 1 second
nonce: 5000,
sendDataCallback: 65000, // as defined in INS13954
sendToSleep: 250, // The default should be enough time for applications to react to devices waking up
refreshValue: 5000, // Default should handle most slow devices until we have a better solution
refreshValueAfterTransition: 1000, // To account for delays in the device
serialAPIStarted: 5000,
Expand Down Expand Up @@ -312,6 +313,14 @@ function checkOptions(options: ZWaveOptions): void {
ZWaveErrorCodes.Driver_InvalidOptions,
);
}
if (
options.timeouts.sendToSleep < 10 || options.timeouts.sendToSleep > 5000
) {
throw new ZWaveError(
`The Send To Sleep timeout must be between 10 and 5000 milliseconds!`,
ZWaveErrorCodes.Driver_InvalidOptions,
);
}
if (options.timeouts.sendDataCallback < 10000) {
throw new ZWaveError(
`The Send Data Callback timeout must be at least 10000 milliseconds!`,
Expand Down Expand Up @@ -5882,7 +5891,10 @@ ${handlers.length} left`,
if (wakeUpInterval !== 0) {
this.sendNodeToSleepTimers.set(
node.id,
setTimeout(() => sendNodeToSleep(node), 1000).unref(),
setTimeout(
() => sendNodeToSleep(node),
this.options.timeouts.sendToSleep,
).unref(),
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/zwave-js/src/lib/driver/ZWaveOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export interface ZWaveOptions extends ZWaveHostOptions {
/** How long generated nonces are valid */
nonce: number; // [3000...20000], default: 5000 ms

/**
* How long to wait without pending commands before sending a node back to sleep.
* Should be as short as possible to save battery, but long enough to give applications time to react.
*/
sendToSleep: number; // [10...5000], default: 250 ms

/**
* **!!! INTERNAL !!!**
*
Expand Down