@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/bot.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* bot.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, botServiceData, botStatus, botWebhookContext, device } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { botServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { botStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { botWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -394,7 +391,7 @@ export class Bot extends deviceBase {
|
|
|
394
391
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
395
392
|
this.refreshStatus()
|
|
396
393
|
} catch (e: any) {
|
|
397
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
394
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
398
395
|
}
|
|
399
396
|
|
|
400
397
|
// regisiter webhook event handler if enabled
|
|
@@ -402,7 +399,7 @@ export class Bot extends deviceBase {
|
|
|
402
399
|
this.debugLog('Registering Webhook Event Handler')
|
|
403
400
|
this.registerWebhook()
|
|
404
401
|
} catch (e: any) {
|
|
405
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
402
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
406
403
|
}
|
|
407
404
|
|
|
408
405
|
// regisiter platform BLE event handler if enabled
|
|
@@ -410,7 +407,7 @@ export class Bot extends deviceBase {
|
|
|
410
407
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
411
408
|
this.registerPlatformBLE()
|
|
412
409
|
} catch (e: any) {
|
|
413
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
410
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
414
411
|
}
|
|
415
412
|
|
|
416
413
|
// Start an update interval
|
|
@@ -551,22 +548,22 @@ export class Bot extends deviceBase {
|
|
|
551
548
|
|
|
552
549
|
async BLERefreshStatus(): Promise<void> {
|
|
553
550
|
await this.debugLog('BLERefreshStatus')
|
|
554
|
-
const
|
|
555
|
-
if (
|
|
556
|
-
await this.BLERefreshConnection(
|
|
551
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
552
|
+
if (switchBotBLE === undefined) {
|
|
553
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
557
554
|
} else {
|
|
558
555
|
// Start to monitor advertisement packets
|
|
559
556
|
(async () => {
|
|
560
557
|
// Start to monitor advertisement packets
|
|
561
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
558
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as botServiceData
|
|
562
559
|
// Update HomeKit
|
|
563
560
|
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
564
561
|
this.serviceData = serviceData
|
|
565
562
|
await this.BLEparseStatus()
|
|
566
563
|
await this.updateHomeKitCharacteristics()
|
|
567
564
|
} else {
|
|
568
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
569
|
-
await this.BLERefreshConnection(
|
|
565
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
566
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
570
567
|
}
|
|
571
568
|
})()
|
|
572
569
|
}
|
|
@@ -587,7 +584,7 @@ export class Bot extends deviceBase {
|
|
|
587
584
|
await this.BLEparseStatus()
|
|
588
585
|
await this.updateHomeKitCharacteristics()
|
|
589
586
|
} catch (e: any) {
|
|
590
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
587
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
591
588
|
}
|
|
592
589
|
}
|
|
593
590
|
} catch (error) {
|
|
@@ -601,17 +598,17 @@ export class Bot extends deviceBase {
|
|
|
601
598
|
async openAPIRefreshStatus(): Promise<void> {
|
|
602
599
|
await this.debugLog('openAPIRefreshStatus')
|
|
603
600
|
try {
|
|
604
|
-
const { body
|
|
605
|
-
const deviceStatus: any = await body
|
|
606
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
607
|
-
if (await this.successfulStatusCodes(
|
|
608
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
601
|
+
const { body } = await this.deviceRefreshStatus()
|
|
602
|
+
const deviceStatus: any = await body
|
|
603
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
604
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
605
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
609
606
|
this.deviceStatus = deviceStatus.body
|
|
610
607
|
await this.openAPIparseStatus()
|
|
611
608
|
await this.updateHomeKitCharacteristics()
|
|
612
609
|
} else {
|
|
613
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
614
|
-
await this.debugWarnLog(
|
|
610
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
611
|
+
await this.debugWarnLog(deviceStatus)
|
|
615
612
|
}
|
|
616
613
|
} catch (e: any) {
|
|
617
614
|
await this.apiError(e)
|
|
@@ -629,7 +626,7 @@ export class Bot extends deviceBase {
|
|
|
629
626
|
await this.parseStatusWebhook()
|
|
630
627
|
await this.updateHomeKitCharacteristics()
|
|
631
628
|
} catch (e: any) {
|
|
632
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
629
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
633
630
|
}
|
|
634
631
|
}
|
|
635
632
|
} else {
|
|
@@ -668,15 +665,15 @@ export class Bot extends deviceBase {
|
|
|
668
665
|
await this.debugLog('BLEpushChanges')
|
|
669
666
|
if (this.On !== this.accessory.context.On || this.allowPush) {
|
|
670
667
|
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
671
|
-
const
|
|
668
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
672
669
|
try {
|
|
673
670
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
674
671
|
this.device.bleMac = formattedDeviceId
|
|
675
672
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
676
|
-
// if (
|
|
673
|
+
// if (switchBotBLE !== false) {
|
|
677
674
|
await this.debugLog(`Bot Mode: ${this.botMode}`)
|
|
678
675
|
if (this.botMode === 'press') {
|
|
679
|
-
|
|
676
|
+
switchBotBLE
|
|
680
677
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
681
678
|
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
|
|
682
679
|
await this.infoLog(`On: ${this.On}`)
|
|
@@ -697,7 +694,7 @@ export class Bot extends deviceBase {
|
|
|
697
694
|
await this.BLEPushConnection()
|
|
698
695
|
})
|
|
699
696
|
} else if (this.botMode === 'switch') {
|
|
700
|
-
|
|
697
|
+
switchBotBLE
|
|
701
698
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
702
699
|
.then(async (device_list: any) => {
|
|
703
700
|
this.infoLog(`On: ${this.On}`)
|
|
@@ -749,21 +746,20 @@ export class Bot extends deviceBase {
|
|
|
749
746
|
} else {
|
|
750
747
|
throw new Error('Device Parameters not set for this Bot.')
|
|
751
748
|
}
|
|
752
|
-
const bodyChange =
|
|
749
|
+
const bodyChange: bodyChange = {
|
|
753
750
|
command: `${command}`,
|
|
754
751
|
parameter: 'default',
|
|
755
752
|
commandType: 'command',
|
|
756
|
-
}
|
|
757
|
-
this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
753
|
+
}
|
|
754
|
+
this.debugLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)},`)
|
|
758
755
|
try {
|
|
759
|
-
const { body
|
|
760
|
-
const deviceStatus: any = await body
|
|
761
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
762
|
-
if (await this.successfulStatusCodes(
|
|
763
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
756
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
757
|
+
const deviceStatus: any = await body
|
|
758
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
759
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
760
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
764
761
|
await this.updateHomeKitCharacteristics()
|
|
765
762
|
} else {
|
|
766
|
-
await this.statusCode(statusCode)
|
|
767
763
|
await this.statusCode(deviceStatus.statusCode)
|
|
768
764
|
}
|
|
769
765
|
if (this.device.bot?.mode === 'multipress') {
|
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* ceilinglight.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, ceilingLightProServiceData, ceilingLightProStatus, ceilingLightProWebhookContext, ceilingLightServiceData, ceilingLightStatus, ceilingLightWebhookContext, device } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { ceilingLightProServiceData, ceilingLightServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { ceilingLightProStatus, ceilingLightStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { ceilingLightProWebhookContext, ceilingLightWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -151,7 +148,7 @@ export class CeilingLight extends deviceBase {
|
|
|
151
148
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
152
149
|
this.refreshStatus()
|
|
153
150
|
} catch (e: any) {
|
|
154
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
151
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
// regisiter webhook event handler if enabled
|
|
@@ -159,7 +156,7 @@ export class CeilingLight extends deviceBase {
|
|
|
159
156
|
this.debugLog('Registering Webhook Event Handler')
|
|
160
157
|
this.registerWebhook()
|
|
161
158
|
} catch (e: any) {
|
|
162
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
159
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
163
160
|
}
|
|
164
161
|
|
|
165
162
|
// regisiter platform BLE event handler if enabled
|
|
@@ -167,7 +164,7 @@ export class CeilingLight extends deviceBase {
|
|
|
167
164
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
168
165
|
this.registerPlatformBLE()
|
|
169
166
|
} catch (e: any) {
|
|
170
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
167
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
171
168
|
}
|
|
172
169
|
|
|
173
170
|
// Start an update interval
|
|
@@ -286,21 +283,21 @@ export class CeilingLight extends deviceBase {
|
|
|
286
283
|
|
|
287
284
|
async BLERefreshStatus(): Promise<void> {
|
|
288
285
|
await this.debugLog('BLERefreshStatus')
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
await this.BLERefreshConnection(
|
|
286
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
287
|
+
if (switchBotBLE === undefined) {
|
|
288
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
292
289
|
} else {
|
|
293
290
|
(async () => {
|
|
294
291
|
// Start to monitor advertisement packets
|
|
295
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
292
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as unknown as ceilingLightServiceData
|
|
296
293
|
// Update HomeKit
|
|
297
294
|
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro) && (serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro)) {
|
|
298
295
|
this.serviceData = serviceData
|
|
299
296
|
await this.BLEparseStatus()
|
|
300
297
|
await this.updateHomeKitCharacteristics()
|
|
301
298
|
} else {
|
|
302
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
303
|
-
await this.BLERefreshConnection(
|
|
299
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
300
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
304
301
|
}
|
|
305
302
|
})()
|
|
306
303
|
}
|
|
@@ -321,7 +318,7 @@ export class CeilingLight extends deviceBase {
|
|
|
321
318
|
await this.BLEparseStatus()
|
|
322
319
|
await this.updateHomeKitCharacteristics()
|
|
323
320
|
} catch (e: any) {
|
|
324
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
321
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
325
322
|
}
|
|
326
323
|
}
|
|
327
324
|
} catch (error) {
|
|
@@ -335,17 +332,17 @@ export class CeilingLight extends deviceBase {
|
|
|
335
332
|
async openAPIRefreshStatus(): Promise<void> {
|
|
336
333
|
await this.debugLog('openAPIRefreshStatus')
|
|
337
334
|
try {
|
|
338
|
-
const { body
|
|
339
|
-
const deviceStatus: any = await body
|
|
340
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
341
|
-
if (await this.successfulStatusCodes(
|
|
342
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
|
+
const { body } = await this.deviceRefreshStatus()
|
|
336
|
+
const deviceStatus: any = await body
|
|
337
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
339
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
340
|
this.deviceStatus = deviceStatus.body
|
|
344
341
|
await this.openAPIparseStatus()
|
|
345
342
|
await this.updateHomeKitCharacteristics()
|
|
346
343
|
} else {
|
|
347
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
348
|
-
await this.debugWarnLog(
|
|
344
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
345
|
+
await this.debugWarnLog(deviceStatus)
|
|
349
346
|
}
|
|
350
347
|
} catch (e: any) {
|
|
351
348
|
await this.apiError(e)
|
|
@@ -363,7 +360,7 @@ export class CeilingLight extends deviceBase {
|
|
|
363
360
|
await this.parseStatusWebhook()
|
|
364
361
|
await this.updateHomeKitCharacteristics()
|
|
365
362
|
} catch (e: any) {
|
|
366
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
363
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
367
364
|
}
|
|
368
365
|
}
|
|
369
366
|
} else {
|
|
@@ -420,13 +417,13 @@ export class CeilingLight extends deviceBase {
|
|
|
420
417
|
await this.debugLog('BLEpushChanges')
|
|
421
418
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
422
419
|
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`)
|
|
423
|
-
const
|
|
420
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
424
421
|
try {
|
|
425
422
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
426
423
|
this.device.bleMac = formattedDeviceId
|
|
427
424
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
428
|
-
if (
|
|
429
|
-
|
|
425
|
+
if (switchBotBLE !== false) {
|
|
426
|
+
switchBotBLE
|
|
430
427
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
431
428
|
.then(async (device_list: any) => {
|
|
432
429
|
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
@@ -451,7 +448,7 @@ export class CeilingLight extends deviceBase {
|
|
|
451
448
|
await this.BLEPushConnection()
|
|
452
449
|
})
|
|
453
450
|
} else {
|
|
454
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
451
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
455
452
|
await this.BLEPushConnection()
|
|
456
453
|
}
|
|
457
454
|
} catch (error) {
|
|
@@ -466,21 +463,20 @@ export class CeilingLight extends deviceBase {
|
|
|
466
463
|
await this.debugLog('openAPIpushChanges')
|
|
467
464
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
468
465
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
469
|
-
const bodyChange =
|
|
466
|
+
const bodyChange: bodyChange = {
|
|
470
467
|
command: `${command}`,
|
|
471
468
|
parameter: 'default',
|
|
472
469
|
commandType: 'command',
|
|
473
|
-
}
|
|
470
|
+
}
|
|
474
471
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
475
472
|
try {
|
|
476
|
-
const { body
|
|
477
|
-
const deviceStatus: any = await body
|
|
478
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
479
|
-
if (await this.successfulStatusCodes(
|
|
480
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
473
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
474
|
+
const deviceStatus: any = await body
|
|
475
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
476
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
477
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
481
478
|
await this.updateHomeKitCharacteristics()
|
|
482
479
|
} else {
|
|
483
|
-
await this.statusCode(statusCode)
|
|
484
480
|
await this.statusCode(deviceStatus.statusCode)
|
|
485
481
|
}
|
|
486
482
|
} catch (e: any) {
|
|
@@ -499,21 +495,20 @@ export class CeilingLight extends deviceBase {
|
|
|
499
495
|
await this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
500
496
|
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation))
|
|
501
497
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
502
|
-
const bodyChange =
|
|
498
|
+
const bodyChange: bodyChange = {
|
|
503
499
|
command: 'setColor',
|
|
504
500
|
parameter: `${red}:${green}:${blue}`,
|
|
505
501
|
commandType: 'command',
|
|
506
|
-
}
|
|
502
|
+
}
|
|
507
503
|
await this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
508
504
|
try {
|
|
509
|
-
const { body
|
|
510
|
-
const deviceStatus: any = await body
|
|
511
|
-
await this.debugLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
512
|
-
if (await this.successfulStatusCodes(
|
|
513
|
-
await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
505
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
506
|
+
const deviceStatus: any = await body
|
|
507
|
+
await this.debugLog(`(pushHueSaturationChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
508
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
509
|
+
await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
514
510
|
await this.updateHomeKitCharacteristics()
|
|
515
511
|
} else {
|
|
516
|
-
await this.statusCode(statusCode)
|
|
517
512
|
await this.statusCode(deviceStatus.statusCode)
|
|
518
513
|
}
|
|
519
514
|
} catch (e: any) {
|
|
@@ -530,21 +525,20 @@ export class CeilingLight extends deviceBase {
|
|
|
530
525
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
531
526
|
const kelvin = Math.round(1000000 * Number(this.LightBulb.ColorTemperature))
|
|
532
527
|
this.accessory.context.kelvin = kelvin
|
|
533
|
-
const bodyChange =
|
|
528
|
+
const bodyChange: bodyChange = {
|
|
534
529
|
command: 'setColorTemperature',
|
|
535
530
|
parameter: `${kelvin}`,
|
|
536
531
|
commandType: 'command',
|
|
537
|
-
}
|
|
532
|
+
}
|
|
538
533
|
await this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
539
534
|
try {
|
|
540
|
-
const { body
|
|
541
|
-
const deviceStatus: any = await body
|
|
542
|
-
await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
543
|
-
if (await this.successfulStatusCodes(
|
|
544
|
-
await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
535
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
536
|
+
const deviceStatus: any = await body
|
|
537
|
+
await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
538
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
539
|
+
await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
545
540
|
await this.updateHomeKitCharacteristics()
|
|
546
541
|
} else {
|
|
547
|
-
await this.statusCode(statusCode)
|
|
548
542
|
await this.statusCode(deviceStatus.statusCode)
|
|
549
543
|
}
|
|
550
544
|
} catch (e: any) {
|
|
@@ -559,21 +553,20 @@ export class CeilingLight extends deviceBase {
|
|
|
559
553
|
async pushBrightnessChanges(): Promise<void> {
|
|
560
554
|
await this.debugLog('pushBrightnessChanges')
|
|
561
555
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
562
|
-
const bodyChange =
|
|
556
|
+
const bodyChange: bodyChange = {
|
|
563
557
|
command: 'setBrightness',
|
|
564
558
|
parameter: `${this.LightBulb.Brightness}`,
|
|
565
559
|
commandType: 'command',
|
|
566
|
-
}
|
|
560
|
+
}
|
|
567
561
|
await this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
568
562
|
try {
|
|
569
|
-
const { body
|
|
570
|
-
const deviceStatus: any = await body
|
|
571
|
-
await this.debugLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
572
|
-
if (await this.successfulStatusCodes(
|
|
573
|
-
await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
563
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
564
|
+
const deviceStatus: any = await body
|
|
565
|
+
await this.debugLog(`(pushBrightnessChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
566
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
567
|
+
await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
574
568
|
await this.updateHomeKitCharacteristics()
|
|
575
569
|
} else {
|
|
576
|
-
await this.statusCode(statusCode)
|
|
577
570
|
await this.statusCode(deviceStatus.statusCode)
|
|
578
571
|
}
|
|
579
572
|
} catch (e: any) {
|