Skip to content

Commit

Permalink
feat: Improve garage door status pooling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KieraDOG committed Aug 1, 2024
1 parent 89f98f9 commit 5040af1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/CGDGarageDoor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ export class CGDGarageDoor {
return;
}

if (this.status && this.isStatusEqual(this.status, data as Status)) {
return;
}

this.status = data as Status;
this.statusUpdateListener?.();
};

private isStatusEqual = (a: Status, b: Status) => {
const values = ['lamp', 'door', 'vacation'];
return values.every((value) => a[value] === b[value]);
};

private poolStatus = async () => {
await this.refreshStatus();
this.statusUpdateListener?.();

setTimeout(this.poolStatus, 2000);
};

Expand Down

0 comments on commit 5040af1

Please sign in to comment.