@switchbot/homebridge-switchbot 3.8.3 → 4.0.0-beta.1
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/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/beta-release.yml +12 -4
- package/CHANGELOG.md +15 -1
- package/config.schema.json +583 -937
- package/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +68 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +63 -59
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +56 -65
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -4
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +73 -80
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +38 -38
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +60 -60
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -6
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +86 -20
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +1 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +50 -51
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +48 -48
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +53 -55
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +35 -35
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +57 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -4
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +38 -39
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +35 -35
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +35 -35
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +27 -27
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +32 -32
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +39 -40
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +28 -28
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -32
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +11 -12
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -23
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -6
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +28 -14
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +12 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +12 -15
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +27 -28
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -10
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -10
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +9 -22
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +154 -260
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +64 -82
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -20
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -102
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -105
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +42 -0
- package/docs/assets/main.js +1 -1
- package/docs/functions/default.html +1 -1
- package/docs/index.html +61 -50
- package/docs/media/security-privacy-bluetooth.png +0 -0
- package/package.json +5 -7
- package/src/device/blindtilt.ts +74 -74
- package/src/device/bot.ts +68 -67
- package/src/device/ceilinglight.ts +59 -70
- package/src/device/colorbulb.ts +79 -88
- package/src/device/contact.ts +40 -43
- package/src/device/curtain.ts +66 -68
- package/src/device/device.ts +86 -40
- package/src/device/fan.ts +52 -56
- package/src/device/hub.ts +50 -53
- package/src/device/humidifier.ts +56 -61
- package/src/device/iosensor.ts +37 -40
- package/src/device/lightstrip.ts +62 -72
- package/src/device/lock.ts +41 -45
- package/src/device/meter.ts +37 -40
- package/src/device/meterplus.ts +37 -40
- package/src/device/motion.ts +29 -32
- package/src/device/plug.ts +34 -37
- package/src/device/robotvacuumcleaner.ts +41 -49
- package/src/device/waterdetector.ts +30 -33
- package/src/irdevice/airconditioner.ts +33 -35
- package/src/irdevice/airpurifier.ts +12 -13
- package/src/irdevice/camera.ts +10 -11
- package/src/irdevice/fan.ts +24 -25
- package/src/irdevice/irdevice.ts +31 -27
- package/src/irdevice/light.ts +14 -15
- package/src/irdevice/other.ts +14 -17
- package/src/irdevice/tv.ts +28 -29
- package/src/irdevice/vacuumcleaner.ts +10 -11
- package/src/irdevice/waterheater.ts +10 -11
- package/src/platform.ts +178 -287
- package/src/settings.ts +67 -88
- package/src/utils.ts +2 -106
- package/dist/types/bledevicestatus.d.ts +0 -281
- package/dist/types/bledevicestatus.d.ts.map +0 -1
- package/dist/types/bledevicestatus.js +0 -2
- package/dist/types/bledevicestatus.js.map +0 -1
- package/dist/types/devicelist.d.ts +0 -89
- package/dist/types/devicelist.d.ts.map +0 -1
- package/dist/types/devicelist.js +0 -6
- package/dist/types/devicelist.js.map +0 -1
- package/dist/types/deviceresponse.d.ts +0 -13
- package/dist/types/deviceresponse.d.ts.map +0 -1
- package/dist/types/deviceresponse.js +0 -2
- package/dist/types/deviceresponse.js.map +0 -1
- package/dist/types/devicestatus.d.ts +0 -149
- package/dist/types/devicestatus.d.ts.map +0 -1
- package/dist/types/devicestatus.js +0 -3
- package/dist/types/devicestatus.js.map +0 -1
- package/dist/types/devicewebhookstatus.d.ts +0 -156
- package/dist/types/devicewebhookstatus.d.ts.map +0 -1
- package/dist/types/devicewebhookstatus.js +0 -2
- package/dist/types/devicewebhookstatus.js.map +0 -1
- package/dist/types/irdevicelist.d.ts +0 -10
- package/dist/types/irdevicelist.d.ts.map +0 -1
- package/dist/types/irdevicelist.js +0 -2
- package/dist/types/irdevicelist.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/src/types/bledevicestatus.ts +0 -303
- package/src/types/devicelist.ts +0 -124
- package/src/types/deviceresponse.ts +0 -14
- package/src/types/devicestatus.ts +0 -178
- package/src/types/devicewebhookstatus.ts +0 -191
- package/src/types/irdevicelist.ts +0 -15
- package/src/types/pushbody.ts +0 -9
package/src/device/fan.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* plug.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { batteryCirculatorFanServiceData, batteryCirculatorFanStatus, batteryCirculatorFanWebhookContext, bodyChange, device, SwitchbotDevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { batteryCirculatorFanServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { batteryCirculatorFanStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { batteryCirculatorFanWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -149,7 +146,7 @@ export class Fan extends deviceBase {
|
|
|
149
146
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
150
147
|
this.refreshStatus()
|
|
151
148
|
} catch (e: any) {
|
|
152
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
149
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
// regisiter webhook event handler if enabled
|
|
@@ -157,7 +154,7 @@ export class Fan extends deviceBase {
|
|
|
157
154
|
this.debugLog('Registering Webhook Event Handler')
|
|
158
155
|
this.registerWebhook()
|
|
159
156
|
} catch (e: any) {
|
|
160
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
157
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
161
158
|
}
|
|
162
159
|
|
|
163
160
|
// regisiter platform BLE event handler if enabled
|
|
@@ -165,7 +162,7 @@ export class Fan extends deviceBase {
|
|
|
165
162
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
166
163
|
this.registerPlatformBLE()
|
|
167
164
|
} catch (e: any) {
|
|
168
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
165
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
169
166
|
}
|
|
170
167
|
|
|
171
168
|
// Start an update interval
|
|
@@ -204,7 +201,8 @@ export class Fan extends deviceBase {
|
|
|
204
201
|
await this.debugLog(`Active: ${this.Fan.Active}`)
|
|
205
202
|
|
|
206
203
|
// RotationSpeed
|
|
207
|
-
this.Fan.RotationSpeed = this.serviceData.fanSpeed
|
|
204
|
+
this.Fan.RotationSpeed = this.serviceData.fanSpeed // ?? 0
|
|
205
|
+
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`)
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
async openAPIparseStatus() {
|
|
@@ -222,7 +220,7 @@ export class Fan extends deviceBase {
|
|
|
222
220
|
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`)
|
|
223
221
|
|
|
224
222
|
// RotationSpeed
|
|
225
|
-
this.Fan.RotationSpeed = this.deviceStatus.fanSpeed
|
|
223
|
+
this.Fan.RotationSpeed = this.deviceStatus.fanSpeed ?? 0
|
|
226
224
|
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`)
|
|
227
225
|
|
|
228
226
|
// ChargingState
|
|
@@ -271,7 +269,7 @@ export class Fan extends deviceBase {
|
|
|
271
269
|
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`)
|
|
272
270
|
|
|
273
271
|
// RotationSpeed
|
|
274
|
-
this.Fan.RotationSpeed = this.webhookContext.fanSpeed
|
|
272
|
+
this.Fan.RotationSpeed = this.webhookContext.fanSpeed // ?? 0
|
|
275
273
|
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`)
|
|
276
274
|
|
|
277
275
|
// BatteryLevel
|
|
@@ -322,22 +320,22 @@ export class Fan extends deviceBase {
|
|
|
322
320
|
|
|
323
321
|
async BLERefreshStatus(): Promise<void> {
|
|
324
322
|
await this.debugLog('BLERefreshStatus')
|
|
325
|
-
const
|
|
326
|
-
if (
|
|
327
|
-
await this.BLERefreshConnection(
|
|
323
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
324
|
+
if (switchBotBLE === undefined) {
|
|
325
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
328
326
|
} else {
|
|
329
327
|
// Start to monitor advertisement packets
|
|
330
328
|
(async () => {
|
|
331
329
|
// Start to monitor advertisement packets
|
|
332
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
330
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as batteryCirculatorFanServiceData
|
|
333
331
|
// Update HomeKit
|
|
334
332
|
if (serviceData.model === SwitchBotBLEModel.Unknown && SwitchBotBLEModelName.Unknown) {
|
|
335
333
|
this.serviceData = serviceData
|
|
336
334
|
await this.BLEparseStatus()
|
|
337
335
|
await this.updateHomeKitCharacteristics()
|
|
338
336
|
} else {
|
|
339
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
340
|
-
await this.BLERefreshConnection(
|
|
337
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
338
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
341
339
|
}
|
|
342
340
|
})()
|
|
343
341
|
}
|
|
@@ -358,7 +356,7 @@ export class Fan extends deviceBase {
|
|
|
358
356
|
await this.BLEparseStatus()
|
|
359
357
|
await this.updateHomeKitCharacteristics()
|
|
360
358
|
} catch (e: any) {
|
|
361
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
359
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
362
360
|
}
|
|
363
361
|
}
|
|
364
362
|
} catch (error) {
|
|
@@ -372,17 +370,17 @@ export class Fan extends deviceBase {
|
|
|
372
370
|
async openAPIRefreshStatus(): Promise<void> {
|
|
373
371
|
await this.debugLog('openAPIRefreshStatus')
|
|
374
372
|
try {
|
|
375
|
-
const { body
|
|
376
|
-
const deviceStatus: any = await body
|
|
377
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
|
-
if (await this.successfulStatusCodes(
|
|
379
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
373
|
+
const { body } = await this.deviceRefreshStatus()
|
|
374
|
+
const deviceStatus: any = await body
|
|
375
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
376
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
377
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
380
378
|
this.deviceStatus = deviceStatus.body
|
|
381
379
|
await this.openAPIparseStatus()
|
|
382
380
|
await this.updateHomeKitCharacteristics()
|
|
383
381
|
} else {
|
|
384
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
385
|
-
await this.debugWarnLog(
|
|
382
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
383
|
+
await this.debugWarnLog(deviceStatus)
|
|
386
384
|
}
|
|
387
385
|
} catch (e: any) {
|
|
388
386
|
await this.apiError(e)
|
|
@@ -400,7 +398,7 @@ export class Fan extends deviceBase {
|
|
|
400
398
|
await this.parseStatusWebhook()
|
|
401
399
|
await this.updateHomeKitCharacteristics()
|
|
402
400
|
} catch (e: any) {
|
|
403
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
401
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
404
402
|
}
|
|
405
403
|
}
|
|
406
404
|
} else {
|
|
@@ -453,22 +451,23 @@ export class Fan extends deviceBase {
|
|
|
453
451
|
await this.debugLog('BLEpushChanges')
|
|
454
452
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
455
453
|
await this.debugLog(`BLEpushChanges On: ${this.Fan.Active} OnCached: ${this.accessory.context.Active}`)
|
|
456
|
-
const
|
|
454
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
457
455
|
try {
|
|
458
456
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
459
457
|
this.device.bleMac = formattedDeviceId
|
|
460
458
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
461
|
-
if (
|
|
462
|
-
|
|
459
|
+
if (switchBotBLE !== false) {
|
|
460
|
+
switchBotBLE
|
|
463
461
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
464
|
-
.then(async (device_list:
|
|
462
|
+
.then(async (device_list: SwitchbotDevice[]) => {
|
|
463
|
+
const deviceList = device_list as unknown as SwitchbotDevice[]
|
|
465
464
|
return await this.retryBLE({
|
|
466
465
|
max: await this.maxRetryBLE(),
|
|
467
466
|
fn: async () => {
|
|
468
467
|
if (this.Fan.Active) {
|
|
469
|
-
return await
|
|
468
|
+
return await deviceList[0].turnOn()
|
|
470
469
|
} else {
|
|
471
|
-
return await
|
|
470
|
+
return await deviceList[0].turnOff()
|
|
472
471
|
}
|
|
473
472
|
},
|
|
474
473
|
})
|
|
@@ -483,7 +482,7 @@ export class Fan extends deviceBase {
|
|
|
483
482
|
await this.BLEPushConnection()
|
|
484
483
|
})
|
|
485
484
|
} else {
|
|
486
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
485
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
487
486
|
await this.BLEPushConnection()
|
|
488
487
|
}
|
|
489
488
|
} catch (error) {
|
|
@@ -498,21 +497,20 @@ export class Fan extends deviceBase {
|
|
|
498
497
|
await this.debugLog('openAPIpushChanges')
|
|
499
498
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
500
499
|
const command = this.Fan.Active ? 'turnOn' : 'turnOff'
|
|
501
|
-
const bodyChange =
|
|
500
|
+
const bodyChange: bodyChange = {
|
|
502
501
|
command: `${command}`,
|
|
503
502
|
parameter: 'default',
|
|
504
503
|
commandType: 'command',
|
|
505
|
-
}
|
|
504
|
+
}
|
|
506
505
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
507
506
|
try {
|
|
508
|
-
const { body
|
|
509
|
-
const deviceStatus: any = await body
|
|
510
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
511
|
-
if (await this.successfulStatusCodes(
|
|
512
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
507
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
508
|
+
const deviceStatus: any = await body
|
|
509
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
510
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
511
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
512
|
await this.updateHomeKitCharacteristics()
|
|
514
513
|
} else {
|
|
515
|
-
await this.statusCode(statusCode)
|
|
516
514
|
await this.statusCode(deviceStatus.statusCode)
|
|
517
515
|
}
|
|
518
516
|
} catch (e: any) {
|
|
@@ -527,21 +525,20 @@ export class Fan extends deviceBase {
|
|
|
527
525
|
async pushRotationSpeedChanges(): Promise<void> {
|
|
528
526
|
await this.debugLog('pushRotationSpeedChanges')
|
|
529
527
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
530
|
-
const bodyChange =
|
|
528
|
+
const bodyChange: bodyChange = {
|
|
531
529
|
command: 'setWindSpeed',
|
|
532
530
|
parameter: `${this.Fan.RotationSpeed}`,
|
|
533
531
|
commandType: 'command',
|
|
534
|
-
}
|
|
532
|
+
}
|
|
535
533
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
536
534
|
try {
|
|
537
|
-
const { body
|
|
538
|
-
const deviceStatus: any = await body
|
|
539
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
540
|
-
if (await this.successfulStatusCodes(
|
|
541
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
535
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
536
|
+
const deviceStatus: any = await body
|
|
537
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
538
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
539
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
542
540
|
await this.updateHomeKitCharacteristics()
|
|
543
541
|
} else {
|
|
544
|
-
await this.statusCode(statusCode)
|
|
545
542
|
await this.statusCode(deviceStatus.statusCode)
|
|
546
543
|
}
|
|
547
544
|
} catch (e: any) {
|
|
@@ -557,21 +554,20 @@ export class Fan extends deviceBase {
|
|
|
557
554
|
await this.debugLog('pushSwingModeChanges')
|
|
558
555
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
559
556
|
const parameter = this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED ? 'on' : 'off'
|
|
560
|
-
const bodyChange =
|
|
557
|
+
const bodyChange: bodyChange = {
|
|
561
558
|
command: 'setOscillation',
|
|
562
559
|
parameter: `${parameter}`,
|
|
563
560
|
commandType: 'command',
|
|
564
|
-
}
|
|
561
|
+
}
|
|
565
562
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
566
563
|
try {
|
|
567
|
-
const { body
|
|
568
|
-
const deviceStatus: any = await body
|
|
569
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
570
|
-
if (await this.successfulStatusCodes(
|
|
571
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
564
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
565
|
+
const deviceStatus: any = await body
|
|
566
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
567
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
568
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
572
569
|
await this.updateHomeKitCharacteristics()
|
|
573
570
|
} else {
|
|
574
|
-
await this.statusCode(statusCode)
|
|
575
571
|
await this.statusCode(deviceStatus.statusCode)
|
|
576
572
|
}
|
|
577
573
|
} catch (e: any) {
|
package/src/device/hub.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* hub.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, hub2ServiceData, hub2Status, hub2WebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { hub2ServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { hub2Status } from '../types/devicestatus.js'
|
|
12
|
-
import type { hub2WebhookContext } from '../types/devicewebhookstatus.js'
|
|
9
|
+
import type { devicesConfig, hubConfig } from '../settings.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -69,7 +66,7 @@ export class Hub extends deviceBase {
|
|
|
69
66
|
this.hubUpdateInProgress = false
|
|
70
67
|
|
|
71
68
|
// Initialize Temperature Sensor Service
|
|
72
|
-
if (device.
|
|
69
|
+
if ((device as hubConfig).hide_temperature) {
|
|
73
70
|
if (this.TemperatureSensor) {
|
|
74
71
|
this.debugLog('Removing Temperature Sensor Service')
|
|
75
72
|
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service
|
|
@@ -97,7 +94,7 @@ export class Hub extends deviceBase {
|
|
|
97
94
|
}
|
|
98
95
|
|
|
99
96
|
// Initialize Humidity Sensor Service
|
|
100
|
-
if (device.
|
|
97
|
+
if ((device as hubConfig).hide_humidity) {
|
|
101
98
|
if (this.HumiditySensor) {
|
|
102
99
|
this.debugLog('Removing Humidity Sensor Service')
|
|
103
100
|
this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service
|
|
@@ -121,7 +118,7 @@ export class Hub extends deviceBase {
|
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
// Initialize Light Sensor Service
|
|
124
|
-
if (device.
|
|
121
|
+
if ((device as hubConfig).hide_lightsensor) {
|
|
125
122
|
if (this.LightSensor) {
|
|
126
123
|
this.debugLog('Removing Light Sensor Service')
|
|
127
124
|
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service
|
|
@@ -149,7 +146,7 @@ export class Hub extends deviceBase {
|
|
|
149
146
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
150
147
|
this.refreshStatus()
|
|
151
148
|
} catch (e: any) {
|
|
152
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
149
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
// regisiter webhook event handler if enabled
|
|
@@ -157,7 +154,7 @@ export class Hub extends deviceBase {
|
|
|
157
154
|
this.debugLog('Registering Webhook Event Handler')
|
|
158
155
|
this.registerWebhook()
|
|
159
156
|
} catch (e: any) {
|
|
160
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
157
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
161
158
|
}
|
|
162
159
|
|
|
163
160
|
// regisiter platform BLE event handler if enabled
|
|
@@ -165,7 +162,7 @@ export class Hub extends deviceBase {
|
|
|
165
162
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
166
163
|
this.registerPlatformBLE()
|
|
167
164
|
} catch (e: any) {
|
|
168
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
165
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
169
166
|
}
|
|
170
167
|
|
|
171
168
|
// Start an update interval
|
|
@@ -181,21 +178,21 @@ export class Hub extends deviceBase {
|
|
|
181
178
|
await this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.celsius}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
182
179
|
|
|
183
180
|
// CurrentTemperature
|
|
184
|
-
if (!this.device.
|
|
181
|
+
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
185
182
|
this.TemperatureSensor.CurrentTemperature = this.serviceData.celsius
|
|
186
183
|
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
187
184
|
}
|
|
188
185
|
|
|
189
186
|
// CurrentRelativeHumidity
|
|
190
|
-
if (!this.device.
|
|
187
|
+
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
191
188
|
this.HumiditySensor!.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
192
189
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
193
190
|
}
|
|
194
191
|
|
|
195
192
|
// CurrentAmbientLightLevel
|
|
196
|
-
if (!this.device.
|
|
197
|
-
const set_minLux = this.device.
|
|
198
|
-
const set_maxLux = this.device.
|
|
193
|
+
if (!(this.device as hubConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
194
|
+
const set_minLux = (this.device as hubConfig).set_minLux ?? 1
|
|
195
|
+
const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
|
|
199
196
|
const lightLevel = this.serviceData.lightLevel
|
|
200
197
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
201
198
|
await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
@@ -207,21 +204,21 @@ export class Hub extends deviceBase {
|
|
|
207
204
|
await this.debugLog(`(temperature, humidity, lightLevel) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}, ${this.deviceStatus.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
208
205
|
|
|
209
206
|
// CurrentRelativeHumidity
|
|
210
|
-
if (!this.device.
|
|
207
|
+
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
211
208
|
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
212
209
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
213
210
|
}
|
|
214
211
|
|
|
215
212
|
// CurrentTemperature
|
|
216
|
-
if (!this.device.
|
|
213
|
+
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
217
214
|
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
218
215
|
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
// LightSensor
|
|
222
|
-
if (!this.device.
|
|
223
|
-
const set_minLux = this.device.
|
|
224
|
-
const set_maxLux = this.device.
|
|
219
|
+
if (!(this.device as hubConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
220
|
+
const set_minLux = (this.device as hubConfig).set_minLux ?? 1
|
|
221
|
+
const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
|
|
225
222
|
const lightLevel = this.deviceStatus.lightLevel
|
|
226
223
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
227
224
|
await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
|
|
@@ -245,28 +242,28 @@ export class Hub extends deviceBase {
|
|
|
245
242
|
|
|
246
243
|
async parseStatusWebhook(): Promise<void> {
|
|
247
244
|
await this.debugLog('parseStatusWebhook')
|
|
248
|
-
await this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.
|
|
245
|
+
await this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)}, ${this.webhookContext.humidity}, ${this.webhookContext.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
249
246
|
// Check if the scale is not CELSIUS
|
|
250
|
-
if (this.webhookContext.scale !== 'CELSIUS' && this.device.
|
|
247
|
+
if (this.webhookContext.scale !== 'CELSIUS' && (this.device as hubConfig).convertUnitTo === undefined) {
|
|
251
248
|
await this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
|
|
252
249
|
}
|
|
253
250
|
|
|
254
251
|
// CurrentRelativeHumidity
|
|
255
|
-
if (!this.device.
|
|
252
|
+
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
256
253
|
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
|
|
257
254
|
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
|
|
258
255
|
}
|
|
259
256
|
|
|
260
257
|
// CurrentTemperature
|
|
261
|
-
if (!this.device.
|
|
262
|
-
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.
|
|
258
|
+
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
259
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)
|
|
263
260
|
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
264
261
|
}
|
|
265
262
|
|
|
266
263
|
// CurrentAmbientLightLevel
|
|
267
|
-
if (!this.device.
|
|
268
|
-
const set_minLux = this.device.
|
|
269
|
-
const set_maxLux = this.device.
|
|
264
|
+
if (!(this.device as hubConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
265
|
+
const set_minLux = (this.device as hubConfig).set_minLux ?? 1
|
|
266
|
+
const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
|
|
270
267
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(this.webhookContext.lightLevel, set_minLux, set_maxLux, 19)
|
|
271
268
|
await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
272
269
|
}
|
|
@@ -290,22 +287,22 @@ export class Hub extends deviceBase {
|
|
|
290
287
|
|
|
291
288
|
async BLERefreshStatus(): Promise<void> {
|
|
292
289
|
await this.debugLog('BLERefreshStatus')
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
await this.BLERefreshConnection(
|
|
290
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
291
|
+
if (switchBotBLE === undefined) {
|
|
292
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
296
293
|
} else {
|
|
297
294
|
// Start to monitor advertisement packets
|
|
298
295
|
(async () => {
|
|
299
296
|
// Start to monitor advertisement packets
|
|
300
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
297
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as hub2ServiceData
|
|
301
298
|
// Update HomeKit
|
|
302
299
|
if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
|
|
303
300
|
this.serviceData = serviceData
|
|
304
301
|
await this.BLEparseStatus()
|
|
305
302
|
await this.updateHomeKitCharacteristics()
|
|
306
303
|
} else {
|
|
307
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
308
|
-
await this.BLERefreshConnection(
|
|
304
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
305
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
309
306
|
}
|
|
310
307
|
})()
|
|
311
308
|
}
|
|
@@ -326,7 +323,7 @@ export class Hub extends deviceBase {
|
|
|
326
323
|
await this.BLEparseStatus()
|
|
327
324
|
await this.updateHomeKitCharacteristics()
|
|
328
325
|
} catch (e: any) {
|
|
329
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
326
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
330
327
|
}
|
|
331
328
|
}
|
|
332
329
|
} catch (error) {
|
|
@@ -340,17 +337,17 @@ export class Hub extends deviceBase {
|
|
|
340
337
|
async openAPIRefreshStatus(): Promise<void> {
|
|
341
338
|
await this.debugLog('openAPIRefreshStatus')
|
|
342
339
|
try {
|
|
343
|
-
const { body
|
|
344
|
-
const deviceStatus: any = await body
|
|
345
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
346
|
-
if (await this.successfulStatusCodes(
|
|
347
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
|
+
const { body } = await this.deviceRefreshStatus()
|
|
341
|
+
const deviceStatus: any = await body
|
|
342
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
344
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
348
345
|
this.deviceStatus = deviceStatus.body
|
|
349
346
|
await this.openAPIparseStatus()
|
|
350
347
|
await this.updateHomeKitCharacteristics()
|
|
351
348
|
} else {
|
|
352
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
353
|
-
await this.debugWarnLog(
|
|
349
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
350
|
+
await this.debugWarnLog(deviceStatus)
|
|
354
351
|
}
|
|
355
352
|
} catch (e: any) {
|
|
356
353
|
await this.apiError(e)
|
|
@@ -368,7 +365,7 @@ export class Hub extends deviceBase {
|
|
|
368
365
|
await this.parseStatusWebhook()
|
|
369
366
|
await this.updateHomeKitCharacteristics()
|
|
370
367
|
} catch (e: any) {
|
|
371
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
368
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
372
369
|
}
|
|
373
370
|
}
|
|
374
371
|
} else {
|
|
@@ -382,15 +379,15 @@ export class Hub extends deviceBase {
|
|
|
382
379
|
|
|
383
380
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
384
381
|
// CurrentRelativeHumidity
|
|
385
|
-
if (!this.device.
|
|
382
|
+
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
386
383
|
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity, this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity')
|
|
387
384
|
}
|
|
388
385
|
// CurrentTemperature
|
|
389
|
-
if (!this.device.
|
|
386
|
+
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
390
387
|
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature')
|
|
391
388
|
}
|
|
392
389
|
// CurrentAmbientLightLevel
|
|
393
|
-
if (!this.device.
|
|
390
|
+
if (!(this.device as hubConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
394
391
|
await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel')
|
|
395
392
|
}
|
|
396
393
|
}
|
|
@@ -405,26 +402,26 @@ export class Hub extends deviceBase {
|
|
|
405
402
|
|
|
406
403
|
async offlineOff(): Promise<void> {
|
|
407
404
|
if (this.device.offline) {
|
|
408
|
-
if (!this.device.
|
|
405
|
+
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
409
406
|
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature)
|
|
410
407
|
}
|
|
411
|
-
if (!this.device.
|
|
408
|
+
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
412
409
|
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.accessory.context.CurrentRelativeHumidity)
|
|
413
410
|
}
|
|
414
|
-
if (!this.device.
|
|
411
|
+
if (!(this.device as hubConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
415
412
|
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.accessory.context.CurrentAmbientLightLevel)
|
|
416
413
|
}
|
|
417
414
|
}
|
|
418
415
|
}
|
|
419
416
|
|
|
420
417
|
async apiError(e: any): Promise<void> {
|
|
421
|
-
if (!this.device.
|
|
418
|
+
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
422
419
|
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
423
420
|
}
|
|
424
|
-
if (!this.device.
|
|
421
|
+
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
425
422
|
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
426
423
|
}
|
|
427
|
-
if (!this.device.
|
|
424
|
+
if (!(this.device as hubConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
428
425
|
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
|
|
429
426
|
}
|
|
430
427
|
}
|