Skip to content

Commit

Permalink
v1.12.0
Browse files Browse the repository at this point in the history
## [Version 1.12.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.0) (2022-01-29)

## What's Changed
* Add option `maxRetry` for bots so you can set the number of retries for sending on or off for Bot.

**Full Changelog**: v1.11.2...v1.12.0
  • Loading branch information
donavanbecker committed Jan 30, 2022
1 parent 76daa7f commit 32eaab8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)

## [Version 1.12.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.0) (2022-01-29)

## What's Changed
* Add option `maxRetry` for bots so you can set the number of retries for sending on or off for Bot.

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.2...v1.12.0

## [Version 1.11.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.2) (2022-01-29)

## What's Changed
Expand Down
9 changes: 9 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@
"condition": {
"functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);"
}
},
"maxRetry": {
"title": "Max Retries",
"type": "number",
"placeholder": "5",
"condition": {
"functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);"
}
}
}
},
Expand Down Expand Up @@ -965,6 +973,7 @@
"options.devices[].bot.deviceType",
"options.devices[].bot.allowPush",
"options.devices[].bot.doublePress",
"options.devices[].bot.maxRetry",
"options.devices[].meter.hide_temperature",
"options.devices[].meter.hide_humidity",
"options.devices[].humidifier.set_minStep",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge SwitchBot",
"name": "@switchbot/homebridge-switchbot",
"version": "1.11.2",
"version": "1.12.0",
"description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
"author": "SwitchBot <[email protected]> (https://github.com/SwitchBot)",
"license": "ISC",
Expand Down
37 changes: 32 additions & 5 deletions src/device/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,16 @@ export class Bot {
}

async turnOnOff(device_list: any): Promise<any> {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
}
return await this.retry({
max: await this.maxRetry(),
fn: () => {
if (this.On) {
return device_list[0].turnOn({ id: this.device.bleMac });
} else {
return device_list[0].turnOff({ id: this.device.bleMac });
}
},
});
}

async openAPIpushChanges(): Promise<void> {
Expand Down Expand Up @@ -1046,6 +1051,28 @@ export class Bot {
this.doBotUpdate.next();
}

async retry({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
return fn().catch(async (err: any) => {
if (max === 0) {
throw err;
}
this.infoLog(err);
this.infoLog('Retrying');
await this.switchbot.wait(1000);
return this.retry({ max: max - 1, fn });
});
}

async maxRetry(): Promise<number> {
let maxRetry: number;
if (this.device.bot?.maxRetry) {
maxRetry = this.device.bot?.maxRetry;
} else {
maxRetry = 5;
}
return maxRetry;
}

async config(device: device & devicesConfig): Promise<void> {
let config = {};
if (device.bot) {
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type bot = {
deviceType?: string;
doublePress?: number;
allowPush?: boolean;
maxRetry?: number;
};

export type humidifier = {
Expand Down

0 comments on commit 32eaab8

Please sign in to comment.