Skip to content

Commit

Permalink
Fix delay when trying to dock
Browse files Browse the repository at this point in the history
  • Loading branch information
karlvr committed Sep 22, 2021
1 parent d93e25b commit 5399dbb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wet-monkeys-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"homebridge-roomba2": patch
---

Fix delay when trying to dock
10 changes: 9 additions & 1 deletion src/accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ type CachedStatus = Status | StatusError;

type CharacteristicGetter = (callback: CharacteristicGetCallback, context: unknown, connection?: unknown) => void

async function delay(duration: number) {
return new Promise((resolve) => {
setTimeout(resolve, duration);
});
}

export default class RoombaAccessory implements AccessoryPlugin {

private api: API
Expand Down Expand Up @@ -407,7 +413,9 @@ export default class RoombaAccessory implements AccessoryPlugin {
case "run":
this.log("Roomba is still running. Will check again in %is", pollingInterval / 1000);

await setTimeout(() => this.log.debug("Trying to dock again..."), pollingInterval);
await delay(pollingInterval);

this.log.debug("Trying to dock again...");
await this.dockWhenStopped(roomba, pollingInterval);

break;
Expand Down

0 comments on commit 5399dbb

Please sign in to comment.