diff --git a/config.schema.json b/config.schema.json index 2d9932e..50ec193 100644 --- a/config.schema.json +++ b/config.schema.json @@ -47,6 +47,20 @@ "required": false, "description": "If dimming is a valid action on a device, it will be included as additional switch on the accessory. Since this is an odd solution to dimming, it's off by default." }, + "request_timeout": { + "title": "Timeout for requests to the bond bridge.", + "type": "number", + "default": 1000, + "required": false, + "description": "Request timeout for network requests to the bond bridge." + }, + "delay_in_seconds": { + "title": "Delay in seconds between commands issued by the bond.", + "type": "number", + "default": 0, + "required": false, + "description": "A delay in seconds between commands issued by the bridge. This solves issues with too many commands being issued on automations and signals not getting to devices" + }, "include_toggle_state": { "title": "Include toggle switch for fixing device state.", "type": "boolean", @@ -63,4 +77,4 @@ } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 69efeeb..7b11535 100644 --- a/package.json +++ b/package.json @@ -56,4 +56,4 @@ }, "homepage": "https://github.com/aarons22/homebridge-bond#readme", "author": "Aaron Sapp" -} \ No newline at end of file +} diff --git a/src/BondApi.ts b/src/BondApi.ts index aa4a4d8..ccd86d5 100644 --- a/src/BondApi.ts +++ b/src/BondApi.ts @@ -23,13 +23,16 @@ const flakeIdGen = new FlakeId(); export class BondApi { private bondToken: string; private uri: BondUri; + private requestTimeout: number; constructor( private readonly platform: BondPlatform, bondToken: string, - ipAddress: string) { + ipAddress: string, + ) { this.bondToken = bondToken; this.uri = new BondUri(ipAddress); + this.requestTimeout = platform.config.requestTimeout; axiosRetry(axios, { retries: 10, @@ -345,7 +348,7 @@ export class BondApi { 'Bond-UUID': bondUuid, }, data: body, - timeout: 10000, + timeout: this.requestTimeout, }) .then(response => { this.platform.log.debug(`Response (${bondUuid}) [${method} ${uri}] - ${JSON.stringify(response.data)}`); diff --git a/src/interface/Bond.ts b/src/interface/Bond.ts index 064a862..9b438db 100644 --- a/src/interface/Bond.ts +++ b/src/interface/Bond.ts @@ -156,4 +156,4 @@ export enum BPUPMethod { PUT = 2, DELETE = 3, PATCH = 4 -} \ No newline at end of file +} diff --git a/src/interface/config.ts b/src/interface/config.ts index 9133331..5b3d832 100644 --- a/src/interface/config.ts +++ b/src/interface/config.ts @@ -12,6 +12,8 @@ export interface BondPlatformConfig extends PlatformConfig { include_dimmer?: boolean; fan_speed_values?: boolean; include_toggle_state?: boolean; + delay_in_seconds?: number; + request_timeout?: number; } // eslint-disable-next-line @typescript-eslint/no-namespace @@ -31,6 +33,8 @@ export namespace BondPlatformConfig { const validDimmer = evaluate('boolean', 'include_dimmer'); const validFanSpeed = evaluate('boolean', 'fan_speed_values'); const validToggleState = evaluate('boolean', 'include_toggle_state'); + const validDelayInSeconds = evaluate('number', 'delay_in_seconds'); + const validRequestTimeout = evaluate('number', 'request_timeout'); if (cast.bonds === undefined || cast.bonds.length === 0) { platform.log.error('Missing bonds in config'); @@ -40,7 +44,8 @@ export namespace BondPlatformConfig { const bondsValid = cast.bonds.map(bond => { return BondConfig.isValid(platform, bond); }).every(v => v === true); - return validDimmer && validFanSpeed && validToggleState && bondsValid; + return validDimmer && validFanSpeed && validToggleState && + validDelayInSeconds && validRequestTimeout && bondsValid; } } @@ -75,4 +80,4 @@ export namespace BondConfig { return validIP && validToken && validHideDeviceIds; } -} \ No newline at end of file +}