Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding config options for delays and timeouts #245

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to maintain the existing values, you'll need to change this to 10000

Suggested change
"default": 1000,
"default": 10000,

"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",
Expand All @@ -63,4 +77,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
},
"homepage": "https://github.com/aarons22/homebridge-bond#readme",
"author": "Aaron Sapp"
}
}
7 changes: 5 additions & 2 deletions src/BondApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, retryDelay: axiosRetry.exponentialDelay });
}
Expand Down Expand Up @@ -329,7 +332,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)}`);
Expand Down
2 changes: 1 addition & 1 deletion src/interface/Bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ export enum BPUPMethod {
PUT = 2,
DELETE = 3,
PATCH = 4
}
}
9 changes: 7 additions & 2 deletions src/interface/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -75,4 +80,4 @@ export namespace BondConfig {

return validIP && validToken && validHideDeviceIds;
}
}
}