Skip to content

Commit

Permalink
feat: make timeout to send devices back to sleep configurable, lower …
Browse files Browse the repository at this point in the history
…default to 250 ms (#6312)

Signed-off-by: Bob Eckhoff <[email protected]>
Co-authored-by: Dominic Griesel <[email protected]>
  • Loading branch information
apella12 and AlCalzone authored Sep 25, 2023
1 parent 2d00ea5 commit 9b9f43f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit 9b9f43f

Please sign in to comment.