Skip to content

Commit

Permalink
v4.1.2
Browse files Browse the repository at this point in the history
## [4.1.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v4.1.2) (2024-11-04)

### What's Changed
- Fix refreshRate Issue

**Full Changelog**: v4.1.1...v4.1.2
  • Loading branch information
donavanbecker committed Nov 5, 2024
1 parent b73d9cd commit da56779
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 80 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/)

## [4.1.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v4.1.2) (2024-11-04)

### What's Changed
- Fix refreshRate Issue

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v4.1.1...v4.1.2

## [4.1.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v4.1.1) (2024-11-02)

### What's Changed
Expand Down
28 changes: 6 additions & 22 deletions package-lock.json

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

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@switchbot/homebridge-switchbot",
"displayName": "SwitchBot",
"type": "module",
"version": "4.1.1",
"version": "4.1.2",
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
"author": "SwitchBot <[email protected]> (https://github.com/SwitchBot)",
"contributors": [
Expand Down Expand Up @@ -60,7 +60,6 @@
},
"scripts": {
"check": "npm install && npm outdated",
"update": "ncu -u && npm update && npm install",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
"watch": "npm run build && npm run plugin-ui && npm link && nodemon",
Expand Down Expand Up @@ -90,7 +89,7 @@
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/mdast": "^4.0.4",
"@types/node": "^22.8.6",
"@types/node": "^22.9.0",
"@types/semver": "^7.5.8",
"@types/source-map-support": "^0.5.10",
"@vitest/coverage-v8": "^2.1.4",
Expand All @@ -99,7 +98,6 @@
"homebridge": "^1.8.5",
"homebridge-config-ui-x": "4.62.0",
"nodemon": "^3.1.7",
"npm-check-updates": "^17.1.9",
"shx": "^0.3.4",
"ts-node": "^10.9.2",
"typedoc": "^0.26.11",
Expand Down
55 changes: 15 additions & 40 deletions src/device/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ export abstract class deviceBase {
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI'
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI'

this.getDeviceLogSettings(accessory, device)
this.getDeviceRateSettings(accessory, device)
this.getDeviceLogSettings(device)
this.getDeviceRateSettings(device)
this.getDeviceConfigSettings(device)
this.getDeviceContext(accessory, device)
this.getDeviceScanDuration(accessory, device)
this.getMqttSettings(device)

// Set accessory information
Expand All @@ -85,35 +84,39 @@ export abstract class deviceBase {
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
}

async getDeviceLogSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
async getDeviceLogSettings(device: device & devicesConfig): Promise<void> {
this.deviceLogging = this.platform.debugMode ? 'debugMode' : device.logging ?? this.platform.platformLogging ?? 'standard'
const logging = this.platform.debugMode ? 'Debug Mode' : device.logging ? 'Device Config' : this.platform.platformLogging ? 'Platform Config' : 'Default'
accessory.context.deviceLogging = this.deviceLogging
this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`)
}

async getDeviceRateSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
async getDeviceRateSettings(device: device & devicesConfig): Promise<void> {
// refreshRate
this.deviceRefreshRate = device.refreshRate ?? this.platform.platformRefreshRate ?? 5
accessory.context.deviceRefreshRate = this.deviceRefreshRate
this.deviceRefreshRate = device.refreshRate ?? this.platform.platformRefreshRate ?? 360
const refreshRate = device.refreshRate ? 'Device Config' : this.platform.platformRefreshRate ? 'Platform Config' : 'Default'
// updateRate
this.deviceUpdateRate = device.updateRate ?? this.platform.platformUpdateRate ?? 5
accessory.context.deviceUpdateRate = this.deviceUpdateRate
const updateRate = device.updateRate ? 'Device Config' : this.platform.platformUpdateRate ? 'Platform Config' : 'Default'
// pushRate
this.devicePushRate = device.pushRate ?? this.platform.platformPushRate ?? 1
accessory.context.devicePushRate = this.devicePushRate
this.devicePushRate = device.pushRate ?? this.platform.platformPushRate ?? 0.1
const pushRate = device.pushRate ? 'Device Config' : this.platform.platformPushRate ? 'Platform Config' : 'Default'
this.debugLog(`Using ${refreshRate} refreshRate: ${this.deviceRefreshRate}, ${updateRate} updateRate: ${this.deviceUpdateRate}, ${pushRate} pushRate: ${this.devicePushRate}`)
// maxRetries
this.deviceMaxRetries = device.maxRetries ?? this.platform.platformMaxRetries ?? 5
const maxRetries = device.maxRetries ? 'Device' : this.platform.platformMaxRetries ? 'Platform' : 'Default'
this.debugLog(`Using ${maxRetries} Max Retries: ${this.deviceMaxRetries}`)
// delayBetweenRetries
this.deviceDelayBetweenRetries = device.delayBetweenRetries ? (device.delayBetweenRetries * 1000) : this.platform.platformDelayBetweenRetries ? this.platform.platformDelayBetweenRetries : 3000
this.deviceDelayBetweenRetries = device.delayBetweenRetries ? (device.delayBetweenRetries * 1000) : this.platform.platformDelayBetweenRetries ?? 3000
const delayBetweenRetries = device.delayBetweenRetries ? 'Device' : this.platform.platformDelayBetweenRetries ? 'Platform' : 'Default'
this.debugLog(`Using ${delayBetweenRetries} Delay Between Retries: ${this.deviceDelayBetweenRetries}`)
// scanDuration
this.scanDuration = Math.max(device.scanDuration ?? 1, this.deviceUpdateRate > 1 ? this.deviceUpdateRate : 1)
if (this.BLE) {
this.debugLog(`Using ${device.scanDuration ? 'Device Config' : 'Default'} scanDuration: ${this.scanDuration}`)
if (device.scanDuration && this.deviceUpdateRate > device.scanDuration) {
this.warnLog('scanDuration is less than updateRate, overriding scanDuration with updateRate')
}
}
}

async retryBLE({ max, fn }: { max: number, fn: { (): any, (): Promise<any> } }): Promise<null> {
Expand All @@ -132,34 +135,6 @@ export abstract class deviceBase {
return this.device.maxRetry !== undefined ? this.device.maxRetry : 5
}

async getDeviceScanDuration(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
this.scanDuration = device.scanDuration
? (this.deviceUpdateRate > device.scanDuration) ? this.deviceUpdateRate : device.scanDuration ? (this.deviceUpdateRate > 1) ? this.deviceUpdateRate : 1 : this.deviceUpdateRate
: 1
if (device.scanDuration) {
if (this.deviceUpdateRate > device.scanDuration) {
this.scanDuration = this.deviceUpdateRate
if (this.BLE) {
this.warnLog('scanDuration is less than updateRate, overriding scanDuration with updateRate')
}
} else {
this.scanDuration = accessory.context.scanDuration = device.scanDuration
}
if (this.BLE) {
this.debugLog(`Using Device Config scanDuration: ${this.scanDuration}`)
}
} else {
if (this.deviceUpdateRate > 1) {
this.scanDuration = this.deviceUpdateRate
} else {
this.scanDuration = accessory.context.scanDuration = 1
}
if (this.BLE) {
this.debugLog(`Using Default scanDuration: ${this.scanDuration}`)
}
}
}

async getDeviceConfigSettings(device: device & devicesConfig): Promise<void> {
const deviceConfig = Object.assign(
{},
Expand Down
30 changes: 16 additions & 14 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2656,24 +2656,26 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
}

async getPlatformRateSettings() {
this.platformRefreshRate = this.config.options?.refreshRate ?? 120
if (this.platformRefreshRate < 5) {
this.platformRefreshRate = 5
}
const refreshRate = this.config.options?.refreshRate ? 'Using Platform Config refreshRate' : 'refreshRate Disabled by Default'
// RefreshRate
this.platformRefreshRate = this.config.options?.refreshRate ? this.config.options.refreshRate : undefined
const refreshRate = this.config.options?.refreshRate ? 'Using Platform Config refreshRate' : 'Platform Config refreshRate Not Set'
await this.debugLog(`${refreshRate}: ${this.platformRefreshRate}`)
this.platformUpdateRate = this.config.options?.updateRate ? this.config.options.updateRate : 1
const updateRate = this.config.options?.updateRate ? 'Using Platform Config updateRate' : 'Using Default updateRate'
// UpdateRate
this.platformUpdateRate = this.config.options?.updateRate ? this.config.options.updateRate : undefined
const updateRate = this.config.options?.updateRate ? 'Using Platform Config updateRate' : 'Platform Config updateRate Not Set'
await this.debugLog(`${updateRate}: ${this.platformUpdateRate}`)
this.platformPushRate = this.config.options?.pushRate ? this.config.options.pushRate : 0.1
const pushRate = this.config.options?.pushRate ? 'Using Platform Config pushRate' : 'Using Default pushRate'
// PushRate
this.platformPushRate = this.config.options?.pushRate ? this.config.options.pushRate : undefined
const pushRate = this.config.options?.pushRate ? 'Using Platform Config pushRate' : 'Platform Config pushRate Not Set'
await this.debugLog(`${pushRate}: ${this.platformPushRate}`)
this.platformMaxRetries = this.config.options?.maxRetries ? this.config.options.maxRetries : 3
const maxRetries = this.config.options?.maxRetries ? 'Using Platform Config maxRetries' : 'Using Default maxRetries'
// MaxRetries
this.platformMaxRetries = this.config.options?.maxRetries ? this.config.options.maxRetries : undefined
const maxRetries = this.config.options?.maxRetries ? 'Using Platform Config maxRetries' : 'Platform Config maxRetries Not Set'
await this.debugLog(`${maxRetries}: ${this.platformMaxRetries}`)
this.platformDelayBetweenRetries = this.config.options?.delayBetweenRetries ? this.config.options.delayBetweenRetries * 1000 : 3000
const delayBetweenRetries = this.config.options?.delayBetweenRetries ? 'Using Platform Config delayBetweenRetries' : 'Using Default delayBetweenRetries'
await this.debugLog(`${delayBetweenRetries}: ${this.platformDelayBetweenRetries / 1000}`)
// DelayBetweenRetries
this.platformDelayBetweenRetries = this.config.options?.delayBetweenRetries ? this.config.options.delayBetweenRetries : undefined
const delayBetweenRetries = this.config.options?.delayBetweenRetries ? 'Using Platform Config delayBetweenRetries' : 'Platform Config delayBetweenRetries Not Set'
await this.debugLog(`${delayBetweenRetries}: ${this.platformDelayBetweenRetries}`)
}

async getPlatformLogSettings() {
Expand Down

0 comments on commit da56779

Please sign in to comment.