Skip to content

Commit

Permalink
Also reset sync state in the hub
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBoyer committed Aug 4, 2024
1 parent 7595aa0 commit 64b74d3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
16 changes: 2 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Konnected BlaQ",
"name": "homebridge-blaq",
"version": "0.2.29",
"version": "0.2.31",
"description": "Control and view your garage door(s) remotely with real-time updates using Konnected's BlaQ hardware",
"license": "Apache-2.0",
"type": "module",
Expand Down Expand Up @@ -36,7 +36,6 @@
],
"dependencies": {
"bonjour-service": "^1.2.1",
"debounce": "^2.1.0",
"eventsource": "^2.0.2",
"node-fetch": "^3.3.2",
"strip-ansi": "^7.1.0"
Expand Down
24 changes: 1 addition & 23 deletions src/accessory/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CharacteristicValue, Logger, PlatformAccessory, Service, WithUUID } from 'homebridge';
import debounce, { DebouncedFunction } from 'debounce';
import { LogMessageEvent, PingMessageEvent, StateUpdateMessageEvent, StateUpdateRecord } from '../utils/eventsource';
import { BlaQHomebridgePluginPlatform } from '../platform';
import { BlaQTextSensorEvent } from '../types';
Expand Down Expand Up @@ -31,11 +30,6 @@ export const correctAPIBaseURL = (inputURL: string) => {
return correctedAPIBaseURL;
};

type DebouncedService = (typeof Service | Service) & {
setCharacteristic: DebouncedFunction<(name: string, value: CharacteristicValue) => Service>;
updateCharacteristic: DebouncedFunction<(name: string, value: CharacteristicValue) => Service>;
};

export class BaseBlaQAccessory implements BaseBlaQAccessoryInterface {
protected apiBaseURL: string;
protected firmwareVersion?: string;
Expand Down Expand Up @@ -85,9 +79,8 @@ export class BaseBlaQAccessory implements BaseBlaQAccessoryInterface {
}

protected getOrAddService(service: WithUUID<typeof Service> | Service): Service {
const retService = this.accessory.getService(service as WithUUID<typeof Service>) ||
return this.accessory.getService(service as WithUUID<typeof Service>) ||
this.accessory.addService(service as Service);
return this.debounceService(retService);
}

protected removeService(service: WithUUID<typeof Service> | Service): void{
Expand All @@ -97,21 +90,6 @@ export class BaseBlaQAccessory implements BaseBlaQAccessoryInterface {
}
}

protected debounceService(service: Service): Service {
const originalSet = service.setCharacteristic.bind(service);
const originalUpdate = service.updateCharacteristic.bind(service);
const retService: DebouncedService = service as DebouncedService;
retService.setCharacteristic = debounce(
(name: string, value: CharacteristicValue) => originalSet(name, value),
100,
);
retService.updateCharacteristic = debounce(
(name: string, value: CharacteristicValue) => originalUpdate(name, value),
100,
);
return retService as Service;
}

processQueuedEvents() {
while(this.queuedEvents.length){
const event = this.queuedEvents.shift()!;
Expand Down

0 comments on commit 64b74d3

Please sign in to comment.