@switchbot/homebridge-switchbot 4.1.1 → 4.1.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@switchbot/homebridge-switchbot",
3
3
  "displayName": "SwitchBot",
4
4
  "type": "module",
5
- "version": "4.1.1",
5
+ "version": "4.1.3-beta.0",
6
6
  "description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
7
7
  "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
8
8
  "contributors": [
@@ -60,7 +60,6 @@
60
60
  },
61
61
  "scripts": {
62
62
  "check": "npm install && npm outdated",
63
- "update": "ncu -u && npm update && npm install",
64
63
  "lint": "eslint src/**/*.ts",
65
64
  "lint:fix": "eslint src/**/*.ts --fix",
66
65
  "watch": "npm run build && npm run plugin-ui && npm link && nodemon",
@@ -90,7 +89,7 @@
90
89
  "@types/debug": "^4.1.12",
91
90
  "@types/fs-extra": "^11.0.4",
92
91
  "@types/mdast": "^4.0.4",
93
- "@types/node": "^22.8.6",
92
+ "@types/node": "^22.9.0",
94
93
  "@types/semver": "^7.5.8",
95
94
  "@types/source-map-support": "^0.5.10",
96
95
  "@vitest/coverage-v8": "^2.1.4",
@@ -99,7 +98,6 @@
99
98
  "homebridge": "^1.8.5",
100
99
  "homebridge-config-ui-x": "4.62.0",
101
100
  "nodemon": "^3.1.7",
102
- "npm-check-updates": "^17.1.9",
103
101
  "shx": "^0.3.4",
104
102
  "ts-node": "^10.9.2",
105
103
  "typedoc": "^0.26.11",
@@ -66,11 +66,10 @@ export abstract class deviceBase {
66
66
  this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI'
67
67
  this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI'
68
68
 
69
- this.getDeviceLogSettings(accessory, device)
70
- this.getDeviceRateSettings(accessory, device)
69
+ this.getDeviceLogSettings(device)
70
+ this.getDeviceRateSettings(device)
71
71
  this.getDeviceConfigSettings(device)
72
72
  this.getDeviceContext(accessory, device)
73
- this.getDeviceScanDuration(accessory, device)
74
73
  this.getMqttSettings(device)
75
74
 
76
75
  // Set accessory information
@@ -85,25 +84,21 @@ export abstract class deviceBase {
85
84
  .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
86
85
  }
87
86
 
88
- async getDeviceLogSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
87
+ async getDeviceLogSettings(device: device & devicesConfig): Promise<void> {
89
88
  this.deviceLogging = this.platform.debugMode ? 'debugMode' : device.logging ?? this.platform.platformLogging ?? 'standard'
90
89
  const logging = this.platform.debugMode ? 'Debug Mode' : device.logging ? 'Device Config' : this.platform.platformLogging ? 'Platform Config' : 'Default'
91
- accessory.context.deviceLogging = this.deviceLogging
92
90
  this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`)
93
91
  }
94
92
 
95
- async getDeviceRateSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
93
+ async getDeviceRateSettings(device: device & devicesConfig): Promise<void> {
96
94
  // refreshRate
97
- this.deviceRefreshRate = device.refreshRate ?? this.platform.platformRefreshRate ?? 5
98
- accessory.context.deviceRefreshRate = this.deviceRefreshRate
95
+ this.deviceRefreshRate = device.refreshRate ?? this.platform.platformRefreshRate ?? 360
99
96
  const refreshRate = device.refreshRate ? 'Device Config' : this.platform.platformRefreshRate ? 'Platform Config' : 'Default'
100
97
  // updateRate
101
98
  this.deviceUpdateRate = device.updateRate ?? this.platform.platformUpdateRate ?? 5
102
- accessory.context.deviceUpdateRate = this.deviceUpdateRate
103
99
  const updateRate = device.updateRate ? 'Device Config' : this.platform.platformUpdateRate ? 'Platform Config' : 'Default'
104
100
  // pushRate
105
- this.devicePushRate = device.pushRate ?? this.platform.platformPushRate ?? 1
106
- accessory.context.devicePushRate = this.devicePushRate
101
+ this.devicePushRate = device.pushRate ?? this.platform.platformPushRate ?? 0.1
107
102
  const pushRate = device.pushRate ? 'Device Config' : this.platform.platformPushRate ? 'Platform Config' : 'Default'
108
103
  this.debugLog(`Using ${refreshRate} refreshRate: ${this.deviceRefreshRate}, ${updateRate} updateRate: ${this.deviceUpdateRate}, ${pushRate} pushRate: ${this.devicePushRate}`)
109
104
  // maxRetries
@@ -111,9 +106,17 @@ export abstract class deviceBase {
111
106
  const maxRetries = device.maxRetries ? 'Device' : this.platform.platformMaxRetries ? 'Platform' : 'Default'
112
107
  this.debugLog(`Using ${maxRetries} Max Retries: ${this.deviceMaxRetries}`)
113
108
  // delayBetweenRetries
114
- this.deviceDelayBetweenRetries = device.delayBetweenRetries ? (device.delayBetweenRetries * 1000) : this.platform.platformDelayBetweenRetries ? this.platform.platformDelayBetweenRetries : 3000
109
+ this.deviceDelayBetweenRetries = device.delayBetweenRetries ? (device.delayBetweenRetries * 1000) : this.platform.platformDelayBetweenRetries ?? 3000
115
110
  const delayBetweenRetries = device.delayBetweenRetries ? 'Device' : this.platform.platformDelayBetweenRetries ? 'Platform' : 'Default'
116
111
  this.debugLog(`Using ${delayBetweenRetries} Delay Between Retries: ${this.deviceDelayBetweenRetries}`)
112
+ // scanDuration
113
+ this.scanDuration = Math.max(device.scanDuration ?? 1, this.deviceUpdateRate > 1 ? this.deviceUpdateRate : 1)
114
+ if (this.BLE) {
115
+ this.debugLog(`Using ${device.scanDuration ? 'Device Config' : 'Default'} scanDuration: ${this.scanDuration}`)
116
+ if (device.scanDuration && this.deviceUpdateRate > device.scanDuration) {
117
+ this.warnLog('scanDuration is less than updateRate, overriding scanDuration with updateRate')
118
+ }
119
+ }
117
120
  }
118
121
 
119
122
  async retryBLE({ max, fn }: { max: number, fn: { (): any, (): Promise<any> } }): Promise<null> {
@@ -132,34 +135,6 @@ export abstract class deviceBase {
132
135
  return this.device.maxRetry !== undefined ? this.device.maxRetry : 5
133
136
  }
134
137
 
135
- async getDeviceScanDuration(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
136
- this.scanDuration = device.scanDuration
137
- ? (this.deviceUpdateRate > device.scanDuration) ? this.deviceUpdateRate : device.scanDuration ? (this.deviceUpdateRate > 1) ? this.deviceUpdateRate : 1 : this.deviceUpdateRate
138
- : 1
139
- if (device.scanDuration) {
140
- if (this.deviceUpdateRate > device.scanDuration) {
141
- this.scanDuration = this.deviceUpdateRate
142
- if (this.BLE) {
143
- this.warnLog('scanDuration is less than updateRate, overriding scanDuration with updateRate')
144
- }
145
- } else {
146
- this.scanDuration = accessory.context.scanDuration = device.scanDuration
147
- }
148
- if (this.BLE) {
149
- this.debugLog(`Using Device Config scanDuration: ${this.scanDuration}`)
150
- }
151
- } else {
152
- if (this.deviceUpdateRate > 1) {
153
- this.scanDuration = this.deviceUpdateRate
154
- } else {
155
- this.scanDuration = accessory.context.scanDuration = 1
156
- }
157
- if (this.BLE) {
158
- this.debugLog(`Using Default scanDuration: ${this.scanDuration}`)
159
- }
160
- }
161
- }
162
-
163
138
  async getDeviceConfigSettings(device: device & devicesConfig): Promise<void> {
164
139
  const deviceConfig = Object.assign(
165
140
  {},
@@ -106,9 +106,7 @@ export class WaterDetector extends deviceBase {
106
106
  accessory.context.LeakSensor = this.LeakSensor as object
107
107
 
108
108
  // Initialize LeakSensor Characteristic
109
- this.LeakSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, this.LeakSensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true).getCharacteristic(this.hap.Characteristic.LeakDetected).onGet(() => {
110
- return this.LeakSensor!.LeakDetected
111
- })
109
+ this.LeakSensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.LeakSensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true)
112
110
  }
113
111
 
114
112
  // Retrieve initial values and updateHomekit
@@ -157,7 +155,7 @@ export class WaterDetector extends deviceBase {
157
155
  // LeakDetected
158
156
  this.LeakSensor.LeakDetected = (this.device as waterDetectorConfig).dry
159
157
  ? this.serviceData.tampered ? 1 : 0
160
- : this.serviceData.tampered
158
+ : this.serviceData.tampered ? 0 : 1
161
159
  this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
162
160
  }
163
161
  // BatteryLevel
@@ -183,13 +181,10 @@ export class WaterDetector extends deviceBase {
183
181
  this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
184
182
 
185
183
  // LeakDetected
186
- if ((this.device as waterDetectorConfig).dry) {
187
- this.LeakSensor.LeakDetected = this.deviceStatus.status === 0 ? 1 : 0
188
- this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
189
- } else {
190
- this.LeakSensor.LeakDetected = this.deviceStatus.status
191
- this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
192
- }
184
+ this.LeakSensor.LeakDetected = (this.device as waterDetectorConfig).dry
185
+ ? this.deviceStatus.status === 0 ? 1 : 0
186
+ : this.deviceStatus.status === 0 ? 0 : 1
187
+ this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
193
188
  }
194
189
 
195
190
  // BatteryLevel
@@ -229,13 +224,10 @@ export class WaterDetector extends deviceBase {
229
224
  this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
230
225
 
231
226
  // LeakDetected
232
- if ((this.device as waterDetectorConfig).dry) {
233
- this.LeakSensor.LeakDetected = this.webhookContext.detectionState === 0 ? 1 : 0
234
- this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
235
- } else {
236
- this.LeakSensor.LeakDetected = this.webhookContext.detectionState
237
- this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
238
- }
227
+ this.LeakSensor.LeakDetected = (this.device as waterDetectorConfig).dry
228
+ ? this.webhookContext.detectionState === 0 ? 1 : 0
229
+ : this.webhookContext.detectionState === 0 ? 0 : 1
230
+ this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
239
231
  }
240
232
 
241
233
  // BatteryLevel
package/src/platform.ts CHANGED
@@ -2656,24 +2656,26 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2656
2656
  }
2657
2657
 
2658
2658
  async getPlatformRateSettings() {
2659
- this.platformRefreshRate = this.config.options?.refreshRate ?? 120
2660
- if (this.platformRefreshRate < 5) {
2661
- this.platformRefreshRate = 5
2662
- }
2663
- const refreshRate = this.config.options?.refreshRate ? 'Using Platform Config refreshRate' : 'refreshRate Disabled by Default'
2659
+ // RefreshRate
2660
+ this.platformRefreshRate = this.config.options?.refreshRate ? this.config.options.refreshRate : undefined
2661
+ const refreshRate = this.config.options?.refreshRate ? 'Using Platform Config refreshRate' : 'Platform Config refreshRate Not Set'
2664
2662
  await this.debugLog(`${refreshRate}: ${this.platformRefreshRate}`)
2665
- this.platformUpdateRate = this.config.options?.updateRate ? this.config.options.updateRate : 1
2666
- const updateRate = this.config.options?.updateRate ? 'Using Platform Config updateRate' : 'Using Default updateRate'
2663
+ // UpdateRate
2664
+ this.platformUpdateRate = this.config.options?.updateRate ? this.config.options.updateRate : undefined
2665
+ const updateRate = this.config.options?.updateRate ? 'Using Platform Config updateRate' : 'Platform Config updateRate Not Set'
2667
2666
  await this.debugLog(`${updateRate}: ${this.platformUpdateRate}`)
2668
- this.platformPushRate = this.config.options?.pushRate ? this.config.options.pushRate : 0.1
2669
- const pushRate = this.config.options?.pushRate ? 'Using Platform Config pushRate' : 'Using Default pushRate'
2667
+ // PushRate
2668
+ this.platformPushRate = this.config.options?.pushRate ? this.config.options.pushRate : undefined
2669
+ const pushRate = this.config.options?.pushRate ? 'Using Platform Config pushRate' : 'Platform Config pushRate Not Set'
2670
2670
  await this.debugLog(`${pushRate}: ${this.platformPushRate}`)
2671
- this.platformMaxRetries = this.config.options?.maxRetries ? this.config.options.maxRetries : 3
2672
- const maxRetries = this.config.options?.maxRetries ? 'Using Platform Config maxRetries' : 'Using Default maxRetries'
2671
+ // MaxRetries
2672
+ this.platformMaxRetries = this.config.options?.maxRetries ? this.config.options.maxRetries : undefined
2673
+ const maxRetries = this.config.options?.maxRetries ? 'Using Platform Config maxRetries' : 'Platform Config maxRetries Not Set'
2673
2674
  await this.debugLog(`${maxRetries}: ${this.platformMaxRetries}`)
2674
- this.platformDelayBetweenRetries = this.config.options?.delayBetweenRetries ? this.config.options.delayBetweenRetries * 1000 : 3000
2675
- const delayBetweenRetries = this.config.options?.delayBetweenRetries ? 'Using Platform Config delayBetweenRetries' : 'Using Default delayBetweenRetries'
2676
- await this.debugLog(`${delayBetweenRetries}: ${this.platformDelayBetweenRetries / 1000}`)
2675
+ // DelayBetweenRetries
2676
+ this.platformDelayBetweenRetries = this.config.options?.delayBetweenRetries ? this.config.options.delayBetweenRetries : undefined
2677
+ const delayBetweenRetries = this.config.options?.delayBetweenRetries ? 'Using Platform Config delayBetweenRetries' : 'Platform Config delayBetweenRetries Not Set'
2678
+ await this.debugLog(`${delayBetweenRetries}: ${this.platformDelayBetweenRetries}`)
2677
2679
  }
2678
2680
 
2679
2681
  async getPlatformLogSettings() {