@switchbot/homebridge-switchbot 3.8.3-beta.3 → 3.8.3-beta.31
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/workflows/beta-release.yml +7 -4
- package/.github/workflows/release.yml +7 -6
- package/CHANGELOG.md +2 -1
- package/config.schema.json +24 -0
- package/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +33 -34
- 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 +30 -31
- 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 +50 -54
- 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 +62 -66
- 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 +18 -18
- 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 +31 -32
- 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 +33 -17
- 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 +47 -49
- 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 +18 -18
- 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 +43 -46
- 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 +18 -18
- 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 +51 -54
- 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 +31 -32
- 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 +18 -18
- 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 +18 -18
- 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 +18 -18
- 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 +29 -30
- 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 +36 -38
- 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 +18 -18
- 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 +11 -12
- 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 +15 -16
- 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 +7 -13
- 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 +9 -10
- 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 +9 -10
- 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 +6 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +127 -188
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- 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 +14 -15
- package/src/device/blindtilt.ts +35 -39
- package/src/device/bot.ts +31 -35
- package/src/device/ceilinglight.ts +51 -58
- package/src/device/colorbulb.ts +63 -70
- package/src/device/contact.ts +19 -22
- package/src/device/curtain.ts +33 -37
- package/src/device/device.ts +32 -21
- package/src/device/fan.ts +48 -53
- package/src/device/hub.ts +19 -22
- package/src/device/humidifier.ts +44 -50
- package/src/device/iosensor.ts +19 -22
- package/src/device/lightstrip.ts +52 -58
- package/src/device/lock.ts +32 -36
- package/src/device/meter.ts +19 -22
- package/src/device/meterplus.ts +19 -22
- package/src/device/motion.ts +19 -22
- package/src/device/plug.ts +30 -34
- package/src/device/robotvacuumcleaner.ts +37 -46
- package/src/device/waterdetector.ts +19 -22
- package/src/irdevice/airconditioner.ts +12 -14
- package/src/irdevice/airpurifier.ts +12 -13
- package/src/irdevice/camera.ts +10 -11
- package/src/irdevice/fan.ts +16 -17
- package/src/irdevice/irdevice.ts +9 -17
- package/src/irdevice/light.ts +10 -11
- package/src/irdevice/other.ts +10 -11
- 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 +131 -188
- package/src/settings.ts +8 -4
- package/src/utils.ts +2 -1
- 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/lock.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* lock.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, lockProServiceData, lockProStatus, lockProWebhookContext, lockServiceData, lockStatus, lockWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { lockProServiceData, lockServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { lockProStatus, lockStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { lockProWebhookContext, lockWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -158,7 +155,7 @@ export class Lock extends deviceBase {
|
|
|
158
155
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
159
156
|
this.refreshStatus()
|
|
160
157
|
} catch (e: any) {
|
|
161
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
158
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
162
159
|
}
|
|
163
160
|
|
|
164
161
|
// regisiter webhook event handler if enabled
|
|
@@ -166,7 +163,7 @@ export class Lock extends deviceBase {
|
|
|
166
163
|
this.debugLog('Registering Webhook Event Handler')
|
|
167
164
|
this.registerWebhook()
|
|
168
165
|
} catch (e: any) {
|
|
169
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
166
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
// regisiter platform BLE event handler if enabled
|
|
@@ -174,7 +171,7 @@ export class Lock extends deviceBase {
|
|
|
174
171
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
175
172
|
this.registerPlatformBLE()
|
|
176
173
|
} catch (e: any) {
|
|
177
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
174
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
178
175
|
}
|
|
179
176
|
|
|
180
177
|
// Start an update interval
|
|
@@ -222,7 +219,7 @@ export class Lock extends deviceBase {
|
|
|
222
219
|
|
|
223
220
|
// Contact Sensor
|
|
224
221
|
if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
|
|
225
|
-
this.ContactSensor.ContactSensorState = this.serviceData.door_open
|
|
222
|
+
this.ContactSensor.ContactSensorState = this.serviceData.door_open
|
|
226
223
|
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
|
227
224
|
: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
|
|
228
225
|
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
|
|
@@ -324,14 +321,14 @@ export class Lock extends deviceBase {
|
|
|
324
321
|
|
|
325
322
|
async BLERefreshStatus(): Promise<void> {
|
|
326
323
|
await this.debugLog('BLERefreshStatus')
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
329
|
-
await this.BLERefreshConnection(
|
|
324
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
325
|
+
if (switchBotBLE === undefined) {
|
|
326
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
330
327
|
} else {
|
|
331
328
|
// Start to monitor advertisement packets
|
|
332
329
|
(async () => {
|
|
333
330
|
// Start to monitor advertisement packets
|
|
334
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
331
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as lockServiceData | lockProServiceData
|
|
335
332
|
// Update HomeKit
|
|
336
333
|
if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
|
|
337
334
|
&& (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
|
|
@@ -339,8 +336,8 @@ export class Lock extends deviceBase {
|
|
|
339
336
|
await this.BLEparseStatus()
|
|
340
337
|
await this.updateHomeKitCharacteristics()
|
|
341
338
|
} else {
|
|
342
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
343
|
-
await this.BLERefreshConnection(
|
|
339
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
340
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
344
341
|
}
|
|
345
342
|
})()
|
|
346
343
|
}
|
|
@@ -361,7 +358,7 @@ export class Lock extends deviceBase {
|
|
|
361
358
|
await this.BLEparseStatus()
|
|
362
359
|
await this.updateHomeKitCharacteristics()
|
|
363
360
|
} catch (e: any) {
|
|
364
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
361
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
365
362
|
}
|
|
366
363
|
}
|
|
367
364
|
} catch (error) {
|
|
@@ -375,17 +372,17 @@ export class Lock extends deviceBase {
|
|
|
375
372
|
async openAPIRefreshStatus(): Promise<void> {
|
|
376
373
|
await this.debugLog('openAPIRefreshStatus')
|
|
377
374
|
try {
|
|
378
|
-
const { body
|
|
379
|
-
const deviceStatus: any = await body
|
|
380
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
381
|
-
if (await this.successfulStatusCodes(
|
|
382
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
375
|
+
const { body } = await this.deviceRefreshStatus()
|
|
376
|
+
const deviceStatus: any = await body
|
|
377
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
379
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
383
380
|
this.deviceStatus = deviceStatus.body
|
|
384
381
|
await this.openAPIparseStatus()
|
|
385
382
|
await this.updateHomeKitCharacteristics()
|
|
386
383
|
} else {
|
|
387
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
388
|
-
await this.debugWarnLog(
|
|
384
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
385
|
+
await this.debugWarnLog(deviceStatus)
|
|
389
386
|
}
|
|
390
387
|
} catch (e: any) {
|
|
391
388
|
await this.apiError(e)
|
|
@@ -403,7 +400,7 @@ export class Lock extends deviceBase {
|
|
|
403
400
|
await this.parseStatusWebhook()
|
|
404
401
|
await this.updateHomeKitCharacteristics()
|
|
405
402
|
} catch (e: any) {
|
|
406
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
403
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
407
404
|
}
|
|
408
405
|
}
|
|
409
406
|
} else {
|
|
@@ -440,13 +437,13 @@ export class Lock extends deviceBase {
|
|
|
440
437
|
async BLEpushChanges(): Promise<void> {
|
|
441
438
|
await this.debugLog('BLEpushChanges')
|
|
442
439
|
if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
|
|
443
|
-
const
|
|
440
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
444
441
|
try {
|
|
445
442
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
446
443
|
this.device.bleMac = formattedDeviceId
|
|
447
444
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
448
|
-
if (
|
|
449
|
-
|
|
445
|
+
if (switchBotBLE !== false) {
|
|
446
|
+
switchBotBLE
|
|
450
447
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
451
448
|
.then(async (device_list: any) => {
|
|
452
449
|
return await this.retryBLE({
|
|
@@ -470,7 +467,7 @@ export class Lock extends deviceBase {
|
|
|
470
467
|
await this.BLEPushConnection()
|
|
471
468
|
})
|
|
472
469
|
} else {
|
|
473
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
470
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
474
471
|
await this.BLEPushConnection()
|
|
475
472
|
}
|
|
476
473
|
} catch (error) {
|
|
@@ -486,21 +483,20 @@ export class Lock extends deviceBase {
|
|
|
486
483
|
if ((this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) || LatchUnlock) {
|
|
487
484
|
// Determine the command based on the LockTargetState or the forceUnlock parameter
|
|
488
485
|
const command = LatchUnlock ? 'unlock' : this.LockMechanism.LockTargetState ? 'lock' : 'unlock'
|
|
489
|
-
const bodyChange =
|
|
486
|
+
const bodyChange: bodyChange = {
|
|
490
487
|
command: `${command}`,
|
|
491
488
|
parameter: 'default',
|
|
492
489
|
commandType: 'command',
|
|
493
|
-
}
|
|
490
|
+
}
|
|
494
491
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
495
492
|
try {
|
|
496
|
-
const { body
|
|
497
|
-
const deviceStatus: any = await body
|
|
498
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
499
|
-
if (await this.successfulStatusCodes(
|
|
500
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
493
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
494
|
+
const deviceStatus: any = await body
|
|
495
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
496
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
497
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
501
498
|
await this.updateHomeKitCharacteristics()
|
|
502
499
|
} else {
|
|
503
|
-
await this.statusCode(statusCode)
|
|
504
500
|
await this.statusCode(deviceStatus.statusCode)
|
|
505
501
|
}
|
|
506
502
|
} catch (e: any) {
|
|
@@ -549,7 +545,7 @@ export class Lock extends deviceBase {
|
|
|
549
545
|
}
|
|
550
546
|
}).catch(async (e: any) => {
|
|
551
547
|
// Log the error if the operation failed
|
|
552
|
-
await this.debugLog(`Error opening latch: ${e}`)
|
|
548
|
+
await this.debugLog(`Error opening latch: ${e.message ?? e}`)
|
|
553
549
|
// Ensure we turn the switch back off even in case of an error
|
|
554
550
|
if (this.Switch?.Service) {
|
|
555
551
|
this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(false)
|
package/src/device/meter.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* meter.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, meterServiceData, meterStatus, meterWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { meterServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { meterStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { meterWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -144,7 +141,7 @@ export class Meter extends deviceBase {
|
|
|
144
141
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
145
142
|
this.refreshStatus()
|
|
146
143
|
} catch (e: any) {
|
|
147
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
144
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
148
145
|
}
|
|
149
146
|
|
|
150
147
|
// regisiter webhook event handler if enabled
|
|
@@ -152,7 +149,7 @@ export class Meter extends deviceBase {
|
|
|
152
149
|
this.debugLog('Registering Webhook Event Handler')
|
|
153
150
|
this.registerWebhook()
|
|
154
151
|
} catch (e: any) {
|
|
155
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
152
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
156
153
|
}
|
|
157
154
|
|
|
158
155
|
// regisiter platform BLE event handler if enabled
|
|
@@ -160,7 +157,7 @@ export class Meter extends deviceBase {
|
|
|
160
157
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
161
158
|
this.registerPlatformBLE()
|
|
162
159
|
} catch (e: any) {
|
|
163
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
160
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
// Start an update interval
|
|
@@ -280,22 +277,22 @@ export class Meter extends deviceBase {
|
|
|
280
277
|
|
|
281
278
|
async BLERefreshStatus(): Promise<void> {
|
|
282
279
|
await this.debugLog('BLERefreshStatus')
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
await this.BLERefreshConnection(
|
|
280
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
281
|
+
if (switchBotBLE === undefined) {
|
|
282
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
286
283
|
} else {
|
|
287
284
|
// Start to monitor advertisement packets
|
|
288
285
|
(async () => {
|
|
289
286
|
// Start to monitor advertisement packets
|
|
290
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
287
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterServiceData
|
|
291
288
|
// Update HomeKit
|
|
292
289
|
if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
|
|
293
290
|
this.serviceData = serviceData
|
|
294
291
|
await this.BLEparseStatus()
|
|
295
292
|
await this.updateHomeKitCharacteristics()
|
|
296
293
|
} else {
|
|
297
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
298
|
-
await this.BLERefreshConnection(
|
|
294
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
295
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
299
296
|
}
|
|
300
297
|
})()
|
|
301
298
|
}
|
|
@@ -316,7 +313,7 @@ export class Meter extends deviceBase {
|
|
|
316
313
|
await this.BLEparseStatus()
|
|
317
314
|
await this.updateHomeKitCharacteristics()
|
|
318
315
|
} catch (e: any) {
|
|
319
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
316
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
320
317
|
}
|
|
321
318
|
}
|
|
322
319
|
} catch (error) {
|
|
@@ -330,17 +327,17 @@ export class Meter extends deviceBase {
|
|
|
330
327
|
async openAPIRefreshStatus(): Promise<void> {
|
|
331
328
|
await this.debugLog('openAPIRefreshStatus')
|
|
332
329
|
try {
|
|
333
|
-
const { body
|
|
334
|
-
const deviceStatus: any = await body
|
|
335
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
336
|
-
if (await this.successfulStatusCodes(
|
|
337
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
330
|
+
const { body } = await this.deviceRefreshStatus()
|
|
331
|
+
const deviceStatus: any = await body
|
|
332
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
333
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
334
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
335
|
this.deviceStatus = deviceStatus.body
|
|
339
336
|
await this.openAPIparseStatus()
|
|
340
337
|
await this.updateHomeKitCharacteristics()
|
|
341
338
|
} else {
|
|
342
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
|
-
await this.debugWarnLog(
|
|
339
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
|
+
await this.debugWarnLog(deviceStatus)
|
|
344
341
|
}
|
|
345
342
|
} catch (e: any) {
|
|
346
343
|
await this.apiError(e)
|
|
@@ -358,7 +355,7 @@ export class Meter extends deviceBase {
|
|
|
358
355
|
await this.parseStatusWebhook()
|
|
359
356
|
await this.updateHomeKitCharacteristics()
|
|
360
357
|
} catch (e: any) {
|
|
361
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
358
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
362
359
|
}
|
|
363
360
|
}
|
|
364
361
|
} else {
|
package/src/device/meterplus.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* meterplus.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, meterPlusServiceData, meterPlusStatus, meterPlusWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { meterPlusServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { meterPlusStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { meterPlusWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -149,7 +146,7 @@ export class MeterPlus 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 MeterPlus 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 MeterPlus 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
|
|
@@ -282,22 +279,22 @@ export class MeterPlus extends deviceBase {
|
|
|
282
279
|
|
|
283
280
|
async BLERefreshStatus(): Promise<void> {
|
|
284
281
|
await this.debugLog('BLERefreshStatus')
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
await this.BLERefreshConnection(
|
|
282
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
283
|
+
if (switchBotBLE === undefined) {
|
|
284
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
288
285
|
} else {
|
|
289
286
|
// Start to monitor advertisement packets
|
|
290
287
|
(async () => {
|
|
291
288
|
// Start to monitor advertisement packets
|
|
292
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
289
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterPlusServiceData
|
|
293
290
|
// Update HomeKit
|
|
294
291
|
if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
|
|
295
292
|
this.serviceData = serviceData
|
|
296
293
|
await this.BLEparseStatus()
|
|
297
294
|
await this.updateHomeKitCharacteristics()
|
|
298
295
|
} else {
|
|
299
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
300
|
-
await this.BLERefreshConnection(
|
|
296
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
297
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
301
298
|
}
|
|
302
299
|
})()
|
|
303
300
|
}
|
|
@@ -318,7 +315,7 @@ export class MeterPlus extends deviceBase {
|
|
|
318
315
|
await this.BLEparseStatus()
|
|
319
316
|
await this.updateHomeKitCharacteristics()
|
|
320
317
|
} catch (e: any) {
|
|
321
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
318
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
322
319
|
}
|
|
323
320
|
}
|
|
324
321
|
} catch (error) {
|
|
@@ -332,17 +329,17 @@ export class MeterPlus extends deviceBase {
|
|
|
332
329
|
async openAPIRefreshStatus(): Promise<void> {
|
|
333
330
|
await this.debugLog('openAPIRefreshStatus')
|
|
334
331
|
try {
|
|
335
|
-
const { body
|
|
336
|
-
const deviceStatus: any = await body
|
|
337
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
|
-
if (await this.successfulStatusCodes(
|
|
339
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
332
|
+
const { body } = await this.deviceRefreshStatus()
|
|
333
|
+
const deviceStatus: any = await body
|
|
334
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
336
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
337
|
this.deviceStatus = deviceStatus.body
|
|
341
338
|
await this.openAPIparseStatus()
|
|
342
339
|
await this.updateHomeKitCharacteristics()
|
|
343
340
|
} else {
|
|
344
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
345
|
-
await this.debugWarnLog(
|
|
341
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
342
|
+
await this.debugWarnLog(deviceStatus)
|
|
346
343
|
}
|
|
347
344
|
} catch (e: any) {
|
|
348
345
|
await this.apiError(e)
|
|
@@ -360,7 +357,7 @@ export class MeterPlus extends deviceBase {
|
|
|
360
357
|
await this.parseStatusWebhook()
|
|
361
358
|
await this.updateHomeKitCharacteristics()
|
|
362
359
|
} catch (e: any) {
|
|
363
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
360
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
364
361
|
}
|
|
365
362
|
}
|
|
366
363
|
} else {
|
package/src/device/motion.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* motion.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, motionSensorServiceData, motionSensorStatus, motionSensorWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { motionSensorServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { motionSensorStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { motionSensorWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -133,7 +130,7 @@ export class Motion extends deviceBase {
|
|
|
133
130
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
134
131
|
this.refreshStatus()
|
|
135
132
|
} catch (e: any) {
|
|
136
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
133
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
// regisiter webhook event handler if enabled
|
|
@@ -141,7 +138,7 @@ export class Motion extends deviceBase {
|
|
|
141
138
|
this.debugLog('Registering Webhook Event Handler')
|
|
142
139
|
this.registerWebhook()
|
|
143
140
|
} catch (e: any) {
|
|
144
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
141
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
145
142
|
}
|
|
146
143
|
|
|
147
144
|
// regisiter platform BLE event handler if enabled
|
|
@@ -149,7 +146,7 @@ export class Motion extends deviceBase {
|
|
|
149
146
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
150
147
|
this.registerPlatformBLE()
|
|
151
148
|
} catch (e: any) {
|
|
152
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
149
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
// Start an update interval
|
|
@@ -257,22 +254,22 @@ export class Motion extends deviceBase {
|
|
|
257
254
|
|
|
258
255
|
async BLERefreshStatus(): Promise<void> {
|
|
259
256
|
await this.debugLog('BLERefreshStatus')
|
|
260
|
-
const
|
|
261
|
-
if (
|
|
262
|
-
await this.BLERefreshConnection(
|
|
257
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
258
|
+
if (switchBotBLE === undefined) {
|
|
259
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
263
260
|
} else {
|
|
264
261
|
// Start to monitor advertisement packets
|
|
265
262
|
(async () => {
|
|
266
263
|
// Start to monitor advertisement packets
|
|
267
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
264
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as motionSensorServiceData
|
|
268
265
|
// Update HomeKit
|
|
269
266
|
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
270
267
|
this.serviceData = serviceData
|
|
271
268
|
await this.BLEparseStatus()
|
|
272
269
|
await this.updateHomeKitCharacteristics()
|
|
273
270
|
} else {
|
|
274
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
275
|
-
await this.BLERefreshConnection(
|
|
271
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
272
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
276
273
|
}
|
|
277
274
|
})()
|
|
278
275
|
}
|
|
@@ -293,7 +290,7 @@ export class Motion extends deviceBase {
|
|
|
293
290
|
await this.BLEparseStatus()
|
|
294
291
|
await this.updateHomeKitCharacteristics()
|
|
295
292
|
} catch (e: any) {
|
|
296
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
293
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
297
294
|
}
|
|
298
295
|
}
|
|
299
296
|
} catch (error) {
|
|
@@ -307,17 +304,17 @@ export class Motion extends deviceBase {
|
|
|
307
304
|
async openAPIRefreshStatus(): Promise<void> {
|
|
308
305
|
await this.debugLog('openAPIRefreshStatus')
|
|
309
306
|
try {
|
|
310
|
-
const { body
|
|
311
|
-
const deviceStatus: any = await body
|
|
312
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
313
|
-
if (await this.successfulStatusCodes(
|
|
314
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
307
|
+
const { body } = await this.deviceRefreshStatus()
|
|
308
|
+
const deviceStatus: any = await body
|
|
309
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
310
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
311
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
315
312
|
this.deviceStatus = deviceStatus.body
|
|
316
313
|
await this.openAPIparseStatus()
|
|
317
314
|
await this.updateHomeKitCharacteristics()
|
|
318
315
|
} else {
|
|
319
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
320
|
-
await this.debugWarnLog(
|
|
316
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
317
|
+
await this.debugWarnLog(deviceStatus)
|
|
321
318
|
}
|
|
322
319
|
} catch (e: any) {
|
|
323
320
|
await this.apiError(e)
|
|
@@ -335,7 +332,7 @@ export class Motion extends deviceBase {
|
|
|
335
332
|
await this.parseStatusWebhook()
|
|
336
333
|
await this.updateHomeKitCharacteristics()
|
|
337
334
|
} catch (e: any) {
|
|
338
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
335
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
339
336
|
}
|
|
340
337
|
}
|
|
341
338
|
} else {
|