@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/humidifier.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* humidifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, humidifierServiceData, humidifierStatus, humidifierWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { humidifierServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { humidifierStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { humidifierWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -140,7 +137,7 @@ export class Humidifier extends deviceBase {
|
|
|
140
137
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
141
138
|
this.refreshStatus()
|
|
142
139
|
} catch (e: any) {
|
|
143
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
140
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
// regisiter webhook event handler if enabled
|
|
@@ -148,7 +145,7 @@ export class Humidifier extends deviceBase {
|
|
|
148
145
|
this.debugLog('Registering Webhook Event Handler')
|
|
149
146
|
this.registerWebhook()
|
|
150
147
|
} catch (e: any) {
|
|
151
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
148
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
152
149
|
}
|
|
153
150
|
|
|
154
151
|
// regisiter platform BLE event handler if enabled
|
|
@@ -156,7 +153,7 @@ export class Humidifier extends deviceBase {
|
|
|
156
153
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
157
154
|
this.registerPlatformBLE()
|
|
158
155
|
} catch (e: any) {
|
|
159
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
156
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
160
157
|
}
|
|
161
158
|
|
|
162
159
|
// Start an update interval
|
|
@@ -320,22 +317,22 @@ export class Humidifier extends deviceBase {
|
|
|
320
317
|
|
|
321
318
|
async BLERefreshStatus(): Promise<void> {
|
|
322
319
|
await this.debugLog('BLERefreshStatus')
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
await this.BLERefreshConnection(
|
|
320
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
321
|
+
if (switchBotBLE === undefined) {
|
|
322
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
326
323
|
} else {
|
|
327
324
|
// Start to monitor advertisement packets
|
|
328
325
|
(async () => {
|
|
329
326
|
// Start to monitor advertisement packets
|
|
330
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
327
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as humidifierServiceData
|
|
331
328
|
// Update HomeKit
|
|
332
329
|
if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
|
|
333
330
|
this.serviceData = serviceData
|
|
334
331
|
await this.BLEparseStatus()
|
|
335
332
|
await this.updateHomeKitCharacteristics()
|
|
336
333
|
} else {
|
|
337
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
338
|
-
await this.BLERefreshConnection(
|
|
334
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
335
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
339
336
|
}
|
|
340
337
|
})()
|
|
341
338
|
}
|
|
@@ -356,7 +353,7 @@ export class Humidifier extends deviceBase {
|
|
|
356
353
|
await this.BLEparseStatus()
|
|
357
354
|
await this.updateHomeKitCharacteristics()
|
|
358
355
|
} catch (e: any) {
|
|
359
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
356
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
360
357
|
}
|
|
361
358
|
}
|
|
362
359
|
} catch (error) {
|
|
@@ -370,17 +367,17 @@ export class Humidifier extends deviceBase {
|
|
|
370
367
|
async openAPIRefreshStatus(): Promise<void> {
|
|
371
368
|
await this.debugLog('openAPIRefreshStatus')
|
|
372
369
|
try {
|
|
373
|
-
const { body
|
|
374
|
-
const deviceStatus: any = await body
|
|
375
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
376
|
-
if (await this.successfulStatusCodes(
|
|
377
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
370
|
+
const { body } = await this.deviceRefreshStatus()
|
|
371
|
+
const deviceStatus: any = await body
|
|
372
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
373
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
374
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
375
|
this.deviceStatus = deviceStatus.body
|
|
379
376
|
await this.openAPIparseStatus()
|
|
380
377
|
await this.updateHomeKitCharacteristics()
|
|
381
378
|
} else {
|
|
382
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
383
|
-
await this.debugWarnLog(
|
|
379
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
380
|
+
await this.debugWarnLog(deviceStatus)
|
|
384
381
|
}
|
|
385
382
|
} catch (e: any) {
|
|
386
383
|
await this.apiError(e)
|
|
@@ -398,7 +395,7 @@ export class Humidifier extends deviceBase {
|
|
|
398
395
|
await this.parseStatusWebhook()
|
|
399
396
|
await this.updateHomeKitCharacteristics()
|
|
400
397
|
} catch (e: any) {
|
|
401
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
398
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
402
399
|
}
|
|
403
400
|
}
|
|
404
401
|
}
|
|
@@ -432,13 +429,13 @@ export class Humidifier extends deviceBase {
|
|
|
432
429
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
433
430
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
434
431
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
435
|
-
const
|
|
432
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
436
433
|
try {
|
|
437
434
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
438
435
|
this.device.bleMac = formattedDeviceId
|
|
439
436
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
440
|
-
if (
|
|
441
|
-
|
|
437
|
+
if (switchBotBLE !== false) {
|
|
438
|
+
switchBotBLE
|
|
442
439
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
443
440
|
.then(async (device_list: any) => {
|
|
444
441
|
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
|
|
@@ -453,7 +450,7 @@ export class Humidifier extends deviceBase {
|
|
|
453
450
|
await this.BLEPushConnection()
|
|
454
451
|
})
|
|
455
452
|
} else {
|
|
456
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
453
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
457
454
|
await this.BLEPushConnection()
|
|
458
455
|
}
|
|
459
456
|
} catch (error) {
|
|
@@ -470,21 +467,20 @@ export class Humidifier extends deviceBase {
|
|
|
470
467
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
471
468
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
472
469
|
await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`)
|
|
473
|
-
const bodyChange =
|
|
470
|
+
const bodyChange: bodyChange = {
|
|
474
471
|
command: 'setMode',
|
|
475
472
|
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
476
473
|
commandType: 'command',
|
|
477
|
-
}
|
|
474
|
+
}
|
|
478
475
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
479
476
|
try {
|
|
480
|
-
const { body
|
|
481
|
-
const deviceStatus: any = await body
|
|
482
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
483
|
-
if (await this.successfulStatusCodes(
|
|
484
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
477
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
478
|
+
const deviceStatus: any = await body
|
|
479
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
480
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
481
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
485
482
|
await this.updateHomeKitCharacteristics()
|
|
486
483
|
} else {
|
|
487
|
-
await this.statusCode(statusCode)
|
|
488
484
|
await this.statusCode(deviceStatus.statusCode)
|
|
489
485
|
}
|
|
490
486
|
} catch (e: any) {
|
|
@@ -507,21 +503,20 @@ export class Humidifier extends deviceBase {
|
|
|
507
503
|
=== this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
508
504
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
509
505
|
await this.debugLog('Pushing Auto')
|
|
510
|
-
const bodyChange =
|
|
506
|
+
const bodyChange: bodyChange = {
|
|
511
507
|
command: 'setMode',
|
|
512
508
|
parameter: 'auto',
|
|
513
509
|
commandType: 'command',
|
|
514
|
-
}
|
|
510
|
+
}
|
|
515
511
|
await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
516
512
|
try {
|
|
517
|
-
const { body
|
|
518
|
-
const deviceStatus: any = await body
|
|
519
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
520
|
-
if (await this.successfulStatusCodes(
|
|
521
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
514
|
+
const deviceStatus: any = await body
|
|
515
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
516
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
517
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
522
518
|
await this.updateHomeKitCharacteristics()
|
|
523
519
|
} else {
|
|
524
|
-
await this.statusCode(statusCode)
|
|
525
520
|
await this.statusCode(deviceStatus.statusCode)
|
|
526
521
|
}
|
|
527
522
|
} catch (e: any) {
|
|
@@ -540,21 +535,20 @@ export class Humidifier extends deviceBase {
|
|
|
540
535
|
await this.debugLog('pushActiveChanges')
|
|
541
536
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
542
537
|
await this.debugLog('Pushing Off')
|
|
543
|
-
const bodyChange =
|
|
538
|
+
const bodyChange: bodyChange = {
|
|
544
539
|
command: 'turnOff',
|
|
545
540
|
parameter: 'default',
|
|
546
541
|
commandType: 'command',
|
|
547
|
-
}
|
|
542
|
+
}
|
|
548
543
|
await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
549
544
|
try {
|
|
550
|
-
const { body
|
|
551
|
-
const deviceStatus: any = await body
|
|
552
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
553
|
-
if (await this.successfulStatusCodes(
|
|
554
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
545
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
546
|
+
const deviceStatus: any = await body
|
|
547
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
548
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
549
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
555
550
|
await this.updateHomeKitCharacteristics()
|
|
556
551
|
} else {
|
|
557
|
-
await this.statusCode(statusCode)
|
|
558
552
|
await this.statusCode(deviceStatus.statusCode)
|
|
559
553
|
}
|
|
560
554
|
} catch (e: any) {
|
package/src/device/iosensor.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* iosensor.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, outdoorMeterServiceData, outdoorMeterStatus, outdoorMeterWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { outdoorMeterServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { outdoorMeterStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { outdoorMeterWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -151,7 +148,7 @@ export class IOSensor 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 IOSensor 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 IOSensor 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
|
|
@@ -285,22 +282,22 @@ export class IOSensor extends deviceBase {
|
|
|
285
282
|
|
|
286
283
|
async BLERefreshStatus(): Promise<void> {
|
|
287
284
|
await this.debugLog('BLERefreshStatus')
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
await this.BLERefreshConnection(
|
|
285
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
286
|
+
if (switchBotBLE === undefined) {
|
|
287
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
291
288
|
} else {
|
|
292
289
|
// Start to monitor advertisement packets
|
|
293
290
|
(async () => {
|
|
294
291
|
// Start to monitor advertisement packets
|
|
295
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
292
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as outdoorMeterServiceData
|
|
296
293
|
// Update HomeKit
|
|
297
294
|
if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
|
|
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 IOSensor 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 IOSensor 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 IOSensor 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 {
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* lightstrip.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, stripLightServiceData, stripLightStatus, stripLightWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { stripLightServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { stripLightStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { stripLightWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -151,7 +148,7 @@ export class StripLight 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 StripLight 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 StripLight 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
|
|
@@ -312,22 +309,22 @@ export class StripLight extends deviceBase {
|
|
|
312
309
|
|
|
313
310
|
async BLERefreshStatus(): Promise<void> {
|
|
314
311
|
await this.debugLog('BLERefreshStatus')
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
await this.BLERefreshConnection(
|
|
312
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
313
|
+
if (switchBotBLE === undefined) {
|
|
314
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
318
315
|
} else {
|
|
319
316
|
// Start to monitor advertisement packets
|
|
320
317
|
(async () => {
|
|
321
318
|
// Start to monitor advertisement packets
|
|
322
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
319
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as stripLightServiceData
|
|
323
320
|
// Update HomeKit
|
|
324
321
|
if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
|
|
325
322
|
this.serviceData = serviceData
|
|
326
323
|
await this.BLEparseStatus()
|
|
327
324
|
await this.updateHomeKitCharacteristics()
|
|
328
325
|
} else {
|
|
329
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
330
|
-
await this.BLERefreshConnection(
|
|
326
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
327
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
331
328
|
}
|
|
332
329
|
})()
|
|
333
330
|
}
|
|
@@ -348,7 +345,7 @@ export class StripLight extends deviceBase {
|
|
|
348
345
|
await this.BLEparseStatus()
|
|
349
346
|
await this.updateHomeKitCharacteristics()
|
|
350
347
|
} catch (e: any) {
|
|
351
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
348
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
352
349
|
}
|
|
353
350
|
}
|
|
354
351
|
} catch (error) {
|
|
@@ -362,17 +359,17 @@ export class StripLight extends deviceBase {
|
|
|
362
359
|
async openAPIRefreshStatus(): Promise<void> {
|
|
363
360
|
await this.debugLog('openAPIRefreshStatus')
|
|
364
361
|
try {
|
|
365
|
-
const { body
|
|
366
|
-
const deviceStatus: any = await body
|
|
367
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
368
|
-
if (await this.successfulStatusCodes(
|
|
369
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
362
|
+
const { body } = await this.deviceRefreshStatus()
|
|
363
|
+
const deviceStatus: any = await body
|
|
364
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
365
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
366
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
370
367
|
this.deviceStatus = deviceStatus.body
|
|
371
368
|
await this.openAPIparseStatus()
|
|
372
369
|
await this.updateHomeKitCharacteristics()
|
|
373
370
|
} else {
|
|
374
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
375
|
-
await this.debugWarnLog(
|
|
371
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
372
|
+
await this.debugWarnLog(deviceStatus)
|
|
376
373
|
}
|
|
377
374
|
} catch (e: any) {
|
|
378
375
|
await this.apiError(e)
|
|
@@ -390,7 +387,7 @@ export class StripLight extends deviceBase {
|
|
|
390
387
|
await this.parseStatusWebhook()
|
|
391
388
|
await this.updateHomeKitCharacteristics()
|
|
392
389
|
} catch (e: any) {
|
|
393
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
390
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
394
391
|
}
|
|
395
392
|
}
|
|
396
393
|
} else {
|
|
@@ -459,13 +456,13 @@ export class StripLight extends deviceBase {
|
|
|
459
456
|
await this.debugLog('BLEpushChanges')
|
|
460
457
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
461
458
|
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
462
|
-
const
|
|
459
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
463
460
|
try {
|
|
464
461
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
465
462
|
this.device.bleMac = formattedDeviceId
|
|
466
463
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
467
|
-
if (
|
|
468
|
-
|
|
464
|
+
if (switchBotBLE !== false) {
|
|
465
|
+
switchBotBLE
|
|
469
466
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
470
467
|
.then(async (device_list: any) => {
|
|
471
468
|
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
@@ -490,7 +487,7 @@ export class StripLight extends deviceBase {
|
|
|
490
487
|
await this.BLEPushConnection()
|
|
491
488
|
})
|
|
492
489
|
} else {
|
|
493
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
490
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
494
491
|
await this.BLEPushConnection()
|
|
495
492
|
}
|
|
496
493
|
} catch (error) {
|
|
@@ -504,13 +501,13 @@ export class StripLight extends deviceBase {
|
|
|
504
501
|
async BLEpushBrightnessChanges(): Promise<void> {
|
|
505
502
|
await this.debugLog('BLEpushBrightnessChanges')
|
|
506
503
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
507
|
-
const
|
|
504
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
508
505
|
try {
|
|
509
506
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
510
507
|
this.device.bleMac = formattedDeviceId
|
|
511
508
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
512
|
-
if (
|
|
513
|
-
|
|
509
|
+
if (switchBotBLE !== false) {
|
|
510
|
+
switchBotBLE
|
|
514
511
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
515
512
|
.then(async (device_list: any) => {
|
|
516
513
|
await this.infoLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
@@ -526,7 +523,7 @@ export class StripLight extends deviceBase {
|
|
|
526
523
|
await this.BLEPushConnection()
|
|
527
524
|
})
|
|
528
525
|
} else {
|
|
529
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
526
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
530
527
|
await this.BLEPushConnection()
|
|
531
528
|
}
|
|
532
529
|
} catch (error) {
|
|
@@ -543,13 +540,13 @@ export class StripLight extends deviceBase {
|
|
|
543
540
|
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
544
541
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
545
542
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
546
|
-
const
|
|
543
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
547
544
|
try {
|
|
548
545
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
549
546
|
this.device.bleMac = formattedDeviceId
|
|
550
547
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
551
|
-
if (
|
|
552
|
-
|
|
548
|
+
if (switchBotBLE !== false) {
|
|
549
|
+
switchBotBLE
|
|
553
550
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
554
551
|
.then(async (device_list: any) => {
|
|
555
552
|
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
@@ -565,7 +562,7 @@ export class StripLight extends deviceBase {
|
|
|
565
562
|
await this.BLEPushConnection()
|
|
566
563
|
})
|
|
567
564
|
} else {
|
|
568
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
565
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
569
566
|
await this.BLEPushConnection()
|
|
570
567
|
}
|
|
571
568
|
} catch (error) {
|
|
@@ -580,21 +577,20 @@ export class StripLight extends deviceBase {
|
|
|
580
577
|
await this.debugLog('openAPIpushChanges')
|
|
581
578
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
582
579
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
583
|
-
const bodyChange =
|
|
580
|
+
const bodyChange: bodyChange = {
|
|
584
581
|
command: `${command}`,
|
|
585
582
|
parameter: 'default',
|
|
586
583
|
commandType: 'command',
|
|
587
|
-
}
|
|
584
|
+
}
|
|
588
585
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
589
586
|
try {
|
|
590
|
-
const { body
|
|
591
|
-
const deviceStatus: any = await body
|
|
592
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
593
|
-
if (await this.successfulStatusCodes(
|
|
594
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
587
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
588
|
+
const deviceStatus: any = await body
|
|
589
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
590
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
591
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
595
592
|
await this.updateHomeKitCharacteristics()
|
|
596
593
|
} else {
|
|
597
|
-
await this.statusCode(statusCode)
|
|
598
594
|
await this.statusCode(deviceStatus.statusCode)
|
|
599
595
|
}
|
|
600
596
|
} catch (e: any) {
|
|
@@ -612,21 +608,20 @@ export class StripLight extends deviceBase {
|
|
|
612
608
|
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
613
609
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
614
610
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
615
|
-
const bodyChange =
|
|
611
|
+
const bodyChange: bodyChange = {
|
|
616
612
|
command: 'setColor',
|
|
617
613
|
parameter: `${red}:${green}:${blue}`,
|
|
618
614
|
commandType: 'command',
|
|
619
|
-
}
|
|
615
|
+
}
|
|
620
616
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
621
617
|
try {
|
|
622
|
-
const { body
|
|
623
|
-
const deviceStatus: any = await body
|
|
624
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
625
|
-
if (await this.successfulStatusCodes(
|
|
626
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
618
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
619
|
+
const deviceStatus: any = await body
|
|
620
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
621
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
622
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
627
623
|
await this.updateHomeKitCharacteristics()
|
|
628
624
|
} else {
|
|
629
|
-
await this.statusCode(statusCode)
|
|
630
625
|
await this.statusCode(deviceStatus.statusCode)
|
|
631
626
|
}
|
|
632
627
|
} catch (e: any) {
|
|
@@ -641,21 +636,20 @@ export class StripLight extends deviceBase {
|
|
|
641
636
|
async pushBrightnessChanges(): Promise<void> {
|
|
642
637
|
await this.debugLog('pushBrightnessChanges')
|
|
643
638
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
644
|
-
const bodyChange =
|
|
639
|
+
const bodyChange: bodyChange = {
|
|
645
640
|
command: 'setBrightness',
|
|
646
641
|
parameter: `${this.LightBulb.Brightness}`,
|
|
647
642
|
commandType: 'command',
|
|
648
|
-
}
|
|
643
|
+
}
|
|
649
644
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
650
645
|
try {
|
|
651
|
-
const { body
|
|
652
|
-
const deviceStatus: any = await body
|
|
653
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
654
|
-
if (await this.successfulStatusCodes(
|
|
655
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
646
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
647
|
+
const deviceStatus: any = await body
|
|
648
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
649
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
650
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
656
651
|
await this.updateHomeKitCharacteristics()
|
|
657
652
|
} else {
|
|
658
|
-
await this.statusCode(statusCode)
|
|
659
653
|
await this.statusCode(deviceStatus.statusCode)
|
|
660
654
|
}
|
|
661
655
|
} catch (e: any) {
|