diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc9d41a..0bc65385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 73839a00..ec454ffd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "4.1.1", + "version": "4.1.2", "funding": [ { "type": "Paypal", @@ -32,7 +32,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", @@ -41,7 +41,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", @@ -2683,9 +2682,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.8.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.6.tgz", - "integrity": "sha512-tosuJYKrIqjQIlVCM4PEGxOmyg3FCPa/fViuJChnGeEIhjA46oy8FMVoF9su1/v8PNs2a8Q0iFNyOx0uOF91nw==", + "version": "22.9.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", + "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", "dev": true, "license": "MIT", "dependencies": { @@ -9559,21 +9558,6 @@ "node": ">=0.10.0" } }, - "node_modules/npm-check-updates": { - "version": "17.1.9", - "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-17.1.9.tgz", - "integrity": "sha512-Gfv5S8NNJKTilM1gesFNYka6bUaBs5LnVyPjApXPQphHijrlLFDMw1uSmwYMZbvJSkLZSOx03e8CHcG0Td5SMA==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "ncu": "build/cli.js", - "npm-check-updates": "build/cli.js" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0", - "npm": ">=8.12.1" - } - }, "node_modules/nth-check": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", diff --git a/package.json b/package.json index 8373c136..d66588e2 100644 --- a/package.json +++ b/package.json @@ -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 (https://github.com/SwitchBot)", "contributors": [ @@ -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", @@ -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", @@ -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", diff --git a/src/device/device.ts b/src/device/device.ts index 99131cea..10374c78 100644 --- a/src/device/device.ts +++ b/src/device/device.ts @@ -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 @@ -85,25 +84,21 @@ export abstract class deviceBase { .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId) } - async getDeviceLogSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise { + async getDeviceLogSettings(device: device & devicesConfig): Promise { 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 { + async getDeviceRateSettings(device: device & devicesConfig): Promise { // 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 @@ -111,9 +106,17 @@ export abstract class deviceBase { 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 } }): Promise { @@ -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 { - 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 { const deviceConfig = Object.assign( {}, diff --git a/src/platform.ts b/src/platform.ts index b0e8aa1f..72aa3994 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -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() {