Skip to content

Commit

Permalink
v2.1.0 (#515)
Browse files Browse the repository at this point in the history
## [Version 2.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.1.0) (2022-10-13)

## What's Changed

- Added `pushRatePress` config to set how many seconds inbetween doublePresses.
  - Also if `doublePress` isn't set it will not wait to pushChanges.
- Added `customize` config option which will allow for custom On and off commands for IR Devices.
  - Added `customOn` & `customOff` to set custom commands for IR Devices.
- Removed `Other`: `commandOn` & `commandOff` you will have to change your commands to the new `customOn` & `customOff` config under the `customize` config.
- Fixed issue where devices are not exposed to Homekit. [#507](#507), [#508](#508), [#513](#513)
- Fixed issue with Non-group Curtains being removed or not displaying in Homekit. [#510](#510)
- Fixed issue were Plugin was waiting 15 seconds before sending command to SwitchBot API. [#509](#509)
- Housekeeping and updated dependencies.

**Full Changelog**: v2.0.0...v2.1.0
  • Loading branch information
donavanbecker authored Oct 13, 2022
1 parent 54f06d3 commit c582a86
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 284 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

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

## [Version 2.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.1.0) (2022-10-13)

## What's Changed

- Added `pushRatePress` config to set how many seconds inbetween doublePresses.
- Also if `doublePress` isn't set it will not wait to pushChanges.
- Added `customize` config option which will allow for custom On and off commands for IR Devices.
- Added `customOn` & `customOff` to set custom commands for IR Devices.
- Removed `Other`: `commandOn` & `commandOff` you will have to change your commands to the new `customOn` & `customOff` config under the `customize` config.
- Fixed issue where devices are not exposed to Homekit. [#507](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/507), [#508](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/508), [#513](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/513)
- Fixed issue with Non-group Curtains being removed or not displaying in Homekit. [#510](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/510)
- Fixed issue were Plugin was waiting 15 seconds before sending command to SwitchBot API. [#509](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/509)
- Housekeeping and updated dependencies.

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.0.0...v2.1.0

## [Version 2.0.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.0.0) (2022-10-12)

## What's Changed
Expand Down
44 changes: 41 additions & 3 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@
"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);"
}
},
"pushRatePress": {
"title": "Double Press Push Rate",
"type": "number",
"placeholder": "15",
"description": "Indicates the number of seconds between pushes for double presses to SwitchBot API",
"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 && model.options.devices[arrayIndices].bot.doublePress > 1);"
}
},
"maxRetry": {
"title": "Max Retries",
"type": "number",
Expand Down Expand Up @@ -756,7 +765,31 @@
],
"description": "Enables OpenAPI, if disabled will leave device in HomeKit and commands will not be sent to OpenAPI.",
"condition": {
"functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device);"
"functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId && !model.options.irdevices[arrayIndices].hide_device && model.options.irdevices[arrayIndices].configRemoteType);"
}
},
"customize": {
"title": "Custom IR Commands",
"type": "boolean",
"description": "Enables Custom IR Commands",
"condition": {
"functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId && !model.options.irdevices[arrayIndices].hide_device && model.options.irdevices[arrayIndices].configRemoteType);"
}
},
"customOn": {
"title": "Custom On Command",
"type": "string",
"placeholder": "On",
"condition": {
"functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId && !model.options.irdevices[arrayIndices].hide_device && model.options.irdevices[arrayIndices].configRemoteType && model.options.irdevices[arrayIndices].customize);"
}
},
"customOff": {
"title": "Custom Off Command",
"type": "string",
"placeholder": "Off",
"condition": {
"functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId && !model.options.irdevices[arrayIndices].hide_device && model.options.irdevices[arrayIndices].configRemoteType && model.options.irdevices[arrayIndices].customize);"
}
},
"irair": {
Expand Down Expand Up @@ -954,7 +987,7 @@
},
{
"type": "fieldset",
"title": "Optional SwitchBot Device Settings",
"title": "SwitchBot Device Settings",
"expandable": true,
"expanded": false,
"items": [
Expand All @@ -977,6 +1010,7 @@
"options.devices[].bot.deviceType",
"options.devices[].bot.allowPush",
"options.devices[].bot.doublePress",
"options.devices[].bot.pushRatePress",
"options.devices[].bot.maxRetry",
"options.devices[].meter.hide_temperature",
"options.devices[].meter.hide_humidity",
Expand Down Expand Up @@ -1016,7 +1050,7 @@
},
{
"type": "fieldset",
"title": "Optional IR Device Settings",
"title": "IR Device Settings",
"expandable": true,
"expanded": false,
"items": [
Expand All @@ -1033,6 +1067,10 @@
"options.irdevices[].deviceId",
"options.irdevices[].hide_device",
"options.irdevices[].configRemoteType",
"options.irdevices[].connectionType",
"options.irdevices[].customize",
"options.irdevices[].customOn",
"options.irdevices[].customOff",
"options.irdevices[].irair.hide_automode",
"options.irdevices[].irair.pushOn",
"options.irdevices[].irfan.rotation_speed",
Expand Down
68 changes: 34 additions & 34 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge SwitchBot",
"name": "@switchbot/homebridge-switchbot",
"version": "2.0.0",
"version": "2.1.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 All @@ -14,7 +14,7 @@
},
"engines": {
"homebridge": "^1.5.0",
"node": "^14.20.0 || ^16.17.1 || ^18.10.0"
"node": "^14.20.1 || ^16.18.0 || ^18.10.0"
},
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"rxjs": "^7.5.7"
},
"devDependencies": {
"@types/node": "^18.8.4",
"@types/node": "^18.8.5",
"@types/crypto-js": "^4.1.1",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
Expand Down
43 changes: 31 additions & 12 deletions src/device/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ export class Bot {
// Config
botMode!: string;
allowPush?: boolean;
doublePress!: number;
pushRatePress!: number;
scanDuration!: number;
deviceLogging!: string;
deviceRefreshRate!: number;

// Others
doublePress!: number;

// Updates
botUpdateInProgress!: boolean;
doBotUpdate!: Subject<void>;
Expand Down Expand Up @@ -346,11 +345,15 @@ export class Bot {
)
.subscribe(async () => {
try {
interval(15000)
.pipe(take(this.doublePress!))
.subscribe(async () => {
await this.pushChanges();
});
if (this.doublePress > 1) {
interval(this.pushRatePress * 1000)
.pipe(take(this.doublePress!))
.subscribe(async () => {
await this.pushChanges();
});
} else {
await this.pushChanges();
}
} catch (e: any) {
this.apiError(e);
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
Expand All @@ -364,7 +367,9 @@ export class Bot {
* Parse the device status from the SwitchBot api
*/
async parseStatus(): Promise<void> {
if (this.BLE) {
if (!this.device.enableCloudService && this.OpenAPI) {
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
} else if (this.BLE) {
await this.BLEparseStatus();
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
await this.openAPIparseStatus();
Expand Down Expand Up @@ -419,7 +424,9 @@ export class Bot {
* Asks the SwitchBot API for the latest device information
*/
async refreshStatus(): Promise<void> {
if (this.BLE) {
if (!this.device.enableCloudService && this.OpenAPI) {
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
} else if (this.BLE) {
await this.BLERefreshStatus();
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
await this.openAPIRefreshStatus();
Expand Down Expand Up @@ -554,15 +561,19 @@ export class Bot {
* Bot - "command" "press" "default" = trigger press
*/
async pushChanges(): Promise<void> {
if (this.BLE) {
if (!this.device.enableCloudService && this.OpenAPI) {
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
} else if (this.BLE) {
await this.BLEpushChanges();
} else if (this.OpenAPI) {
await this.openAPIpushChanges();
} else {
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
}
interval(5000)
// Refresh the status from the API
interval(15000)
.pipe(skipWhile(() => this.botUpdateInProgress))
.pipe(take(1))
.subscribe(async () => {
await this.refreshStatus();
Expand Down Expand Up @@ -1290,6 +1301,14 @@ export class Bot {
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
}
// pushRatePress
if (device?.bot?.pushRatePress) {
this.pushRatePress = device?.bot?.pushRatePress;
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
} else {
this.pushRatePress = 15;
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Bot pushRatePress: ${this.pushRatePress}`);
}
}

async config(device: device & devicesConfig): Promise<void> {
Expand Down
Loading

0 comments on commit c582a86

Please sign in to comment.