@switchbot/homebridge-switchbot 3.8.3-beta.30 → 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/release.yml +1 -1
- package/CHANGELOG.md +2 -1
- package/config.schema.json +24 -0
- package/dist/device/blindtilt.js +15 -15
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +15 -15
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +15 -15
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +27 -27
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +11 -11
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +15 -15
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.js +7 -7
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +15 -15
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +11 -11
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +15 -15
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +11 -11
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +23 -23
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +16 -16
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +11 -11
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.js +11 -11
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +15 -15
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +15 -15
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +11 -11
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +80 -76
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +15 -15
- package/src/device/bot.ts +15 -15
- package/src/device/ceilinglight.ts +15 -15
- package/src/device/colorbulb.ts +27 -27
- package/src/device/contact.ts +11 -11
- package/src/device/curtain.ts +15 -15
- package/src/device/device.ts +7 -7
- package/src/device/fan.ts +15 -15
- package/src/device/hub.ts +11 -11
- package/src/device/humidifier.ts +15 -15
- package/src/device/iosensor.ts +11 -11
- package/src/device/lightstrip.ts +23 -23
- package/src/device/lock.ts +16 -16
- package/src/device/meter.ts +11 -11
- package/src/device/meterplus.ts +11 -11
- package/src/device/motion.ts +11 -11
- package/src/device/plug.ts +15 -15
- package/src/device/robotvacuumcleaner.ts +15 -15
- package/src/device/waterdetector.ts +11 -11
- package/src/platform.ts +81 -77
- package/src/settings.ts +3 -0
package/src/device/curtain.ts
CHANGED
|
@@ -241,7 +241,7 @@ export class Curtain extends deviceBase {
|
|
|
241
241
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
242
242
|
this.refreshStatus()
|
|
243
243
|
} catch (e: any) {
|
|
244
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
244
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// regisiter webhook event handler if enabled
|
|
@@ -249,7 +249,7 @@ export class Curtain extends deviceBase {
|
|
|
249
249
|
this.debugLog('Registering Webhook Event Handler')
|
|
250
250
|
this.registerWebhook()
|
|
251
251
|
} catch (e: any) {
|
|
252
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
252
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
// regisiter platform BLE event handler if enabled
|
|
@@ -257,7 +257,7 @@ export class Curtain extends deviceBase {
|
|
|
257
257
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
258
258
|
this.registerPlatformBLE()
|
|
259
259
|
} catch (e: any) {
|
|
260
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
260
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
// History
|
|
@@ -477,14 +477,14 @@ export class Curtain extends deviceBase {
|
|
|
477
477
|
|
|
478
478
|
async BLERefreshStatus(): Promise<void> {
|
|
479
479
|
await this.debugLog('BLERefreshStatus')
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
482
|
-
await this.BLERefreshConnection(
|
|
480
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
481
|
+
if (switchBotBLE === undefined) {
|
|
482
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
483
483
|
} else {
|
|
484
484
|
// Start to monitor advertisement packets
|
|
485
485
|
(async () => {
|
|
486
486
|
// Start to monitor advertisement packets
|
|
487
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
487
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as curtainServiceData | curtain3ServiceData
|
|
488
488
|
// Update HomeKit
|
|
489
489
|
if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
|
|
490
490
|
&& (serviceData.modelName === SwitchBotBLEModelName.Curtain || SwitchBotBLEModelName.Curtain3)) {
|
|
@@ -492,8 +492,8 @@ export class Curtain extends deviceBase {
|
|
|
492
492
|
await this.BLEparseStatus()
|
|
493
493
|
await this.updateHomeKitCharacteristics()
|
|
494
494
|
} else {
|
|
495
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
496
|
-
await this.BLERefreshConnection(
|
|
495
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
496
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
497
497
|
}
|
|
498
498
|
})()
|
|
499
499
|
}
|
|
@@ -530,7 +530,7 @@ export class Curtain extends deviceBase {
|
|
|
530
530
|
await this.parseStatusWebhook()
|
|
531
531
|
await this.updateHomeKitCharacteristics()
|
|
532
532
|
} catch (e: any) {
|
|
533
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
533
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
} else {
|
|
@@ -553,7 +553,7 @@ export class Curtain extends deviceBase {
|
|
|
553
553
|
await this.BLEparseStatus()
|
|
554
554
|
await this.updateHomeKitCharacteristics()
|
|
555
555
|
} catch (e: any) {
|
|
556
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
556
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
} catch (error) {
|
|
@@ -590,7 +590,7 @@ export class Curtain extends deviceBase {
|
|
|
590
590
|
async BLEpushChanges(): Promise<void> {
|
|
591
591
|
await this.debugLog('BLEpushChanges')
|
|
592
592
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
593
|
-
const
|
|
593
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
594
594
|
try {
|
|
595
595
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
596
596
|
this.device.bleMac = formattedDeviceId
|
|
@@ -598,8 +598,8 @@ export class Curtain extends deviceBase {
|
|
|
598
598
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
599
599
|
const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF
|
|
600
600
|
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
601
|
-
if (
|
|
602
|
-
|
|
601
|
+
if (switchBotBLE !== false) {
|
|
602
|
+
switchBotBLE
|
|
603
603
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
604
604
|
.then(async (device_list: any) => {
|
|
605
605
|
return await this.retryBLE({
|
|
@@ -619,7 +619,7 @@ export class Curtain extends deviceBase {
|
|
|
619
619
|
await this.BLEPushConnection()
|
|
620
620
|
})
|
|
621
621
|
} else {
|
|
622
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
622
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
623
623
|
await this.BLEPushConnection()
|
|
624
624
|
}
|
|
625
625
|
} catch (error) {
|
package/src/device/device.ts
CHANGED
|
@@ -275,14 +275,14 @@ export abstract class deviceBase {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
async switchbotBLE(): Promise<any> {
|
|
278
|
-
const
|
|
278
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
279
279
|
// Convert to BLE Address
|
|
280
280
|
try {
|
|
281
281
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
282
282
|
this.device.bleMac = formattedDeviceId
|
|
283
283
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
284
|
-
await this.getCustomBLEAddress(
|
|
285
|
-
return
|
|
284
|
+
await this.getCustomBLEAddress(switchBotBLE)
|
|
285
|
+
return switchBotBLE
|
|
286
286
|
} catch (error) {
|
|
287
287
|
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
288
288
|
}
|
|
@@ -293,7 +293,7 @@ export abstract class deviceBase {
|
|
|
293
293
|
try {
|
|
294
294
|
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac })
|
|
295
295
|
} catch (e: any) {
|
|
296
|
-
await this.errorLog(`Failed to start BLE scanning. Error:${e}`)
|
|
296
|
+
await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
|
|
297
297
|
}
|
|
298
298
|
// Set an event handler
|
|
299
299
|
let serviceData = { model: this.device.bleModel, modelName: this.device.bleModelName } as ad['serviceData']
|
|
@@ -314,7 +314,7 @@ export abstract class deviceBase {
|
|
|
314
314
|
try {
|
|
315
315
|
await switchbot.stopScan()
|
|
316
316
|
} catch (e: any) {
|
|
317
|
-
await this.errorLog(`Failed to stop BLE scanning. Error:${e}`)
|
|
317
|
+
await this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
|
|
318
318
|
}
|
|
319
319
|
return serviceData
|
|
320
320
|
}
|
|
@@ -327,7 +327,7 @@ export abstract class deviceBase {
|
|
|
327
327
|
try {
|
|
328
328
|
await switchbot.startScan({ model: this.device.bleModel })
|
|
329
329
|
} catch (e: any) {
|
|
330
|
-
await this.errorLog(`Failed to start BLE scanning. Error:${e}`)
|
|
330
|
+
await this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
|
|
331
331
|
}
|
|
332
332
|
// Set an event handler
|
|
333
333
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
@@ -338,7 +338,7 @@ export abstract class deviceBase {
|
|
|
338
338
|
try {
|
|
339
339
|
switchbot.stopScan()
|
|
340
340
|
} catch (e: any) {
|
|
341
|
-
await this.errorLog(`Failed to stop BLE scanning. Error:${e}`)
|
|
341
|
+
await this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
|
|
342
342
|
}
|
|
343
343
|
})()
|
|
344
344
|
}
|
package/src/device/fan.ts
CHANGED
|
@@ -146,7 +146,7 @@ export class Fan extends deviceBase {
|
|
|
146
146
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
147
147
|
this.refreshStatus()
|
|
148
148
|
} catch (e: any) {
|
|
149
|
-
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}`)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// regisiter webhook event handler if enabled
|
|
@@ -154,7 +154,7 @@ export class Fan extends deviceBase {
|
|
|
154
154
|
this.debugLog('Registering Webhook Event Handler')
|
|
155
155
|
this.registerWebhook()
|
|
156
156
|
} catch (e: any) {
|
|
157
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
157
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
// regisiter platform BLE event handler if enabled
|
|
@@ -162,7 +162,7 @@ export class Fan extends deviceBase {
|
|
|
162
162
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
163
163
|
this.registerPlatformBLE()
|
|
164
164
|
} catch (e: any) {
|
|
165
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
165
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// Start an update interval
|
|
@@ -320,22 +320,22 @@ export class Fan extends deviceBase {
|
|
|
320
320
|
|
|
321
321
|
async BLERefreshStatus(): Promise<void> {
|
|
322
322
|
await this.debugLog('BLERefreshStatus')
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
await this.BLERefreshConnection(
|
|
323
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
324
|
+
if (switchBotBLE === undefined) {
|
|
325
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
326
326
|
} else {
|
|
327
327
|
// Start to monitor advertisement packets
|
|
328
328
|
(async () => {
|
|
329
329
|
// Start to monitor advertisement packets
|
|
330
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
330
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as batteryCirculatorFanServiceData
|
|
331
331
|
// Update HomeKit
|
|
332
332
|
if (serviceData.model === SwitchBotBLEModel.Unknown && SwitchBotBLEModelName.Unknown) {
|
|
333
333
|
this.serviceData = serviceData
|
|
334
334
|
await this.BLEparseStatus()
|
|
335
335
|
await this.updateHomeKitCharacteristics()
|
|
336
336
|
} else {
|
|
337
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
338
|
-
await this.BLERefreshConnection(
|
|
337
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
338
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
339
339
|
}
|
|
340
340
|
})()
|
|
341
341
|
}
|
|
@@ -356,7 +356,7 @@ export class Fan extends deviceBase {
|
|
|
356
356
|
await this.BLEparseStatus()
|
|
357
357
|
await this.updateHomeKitCharacteristics()
|
|
358
358
|
} catch (e: any) {
|
|
359
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
359
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
} catch (error) {
|
|
@@ -398,7 +398,7 @@ export class Fan extends deviceBase {
|
|
|
398
398
|
await this.parseStatusWebhook()
|
|
399
399
|
await this.updateHomeKitCharacteristics()
|
|
400
400
|
} catch (e: any) {
|
|
401
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
401
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
} else {
|
|
@@ -451,13 +451,13 @@ export class Fan extends deviceBase {
|
|
|
451
451
|
await this.debugLog('BLEpushChanges')
|
|
452
452
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
453
453
|
await this.debugLog(`BLEpushChanges On: ${this.Fan.Active} OnCached: ${this.accessory.context.Active}`)
|
|
454
|
-
const
|
|
454
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
455
455
|
try {
|
|
456
456
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
457
457
|
this.device.bleMac = formattedDeviceId
|
|
458
458
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
459
|
-
if (
|
|
460
|
-
|
|
459
|
+
if (switchBotBLE !== false) {
|
|
460
|
+
switchBotBLE
|
|
461
461
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
462
462
|
.then(async (device_list: any) => {
|
|
463
463
|
return await this.retryBLE({
|
|
@@ -481,7 +481,7 @@ export class Fan extends deviceBase {
|
|
|
481
481
|
await this.BLEPushConnection()
|
|
482
482
|
})
|
|
483
483
|
} else {
|
|
484
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
484
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
485
485
|
await this.BLEPushConnection()
|
|
486
486
|
}
|
|
487
487
|
} catch (error) {
|
package/src/device/hub.ts
CHANGED
|
@@ -146,7 +146,7 @@ export class Hub extends deviceBase {
|
|
|
146
146
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
147
147
|
this.refreshStatus()
|
|
148
148
|
} catch (e: any) {
|
|
149
|
-
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}`)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// regisiter webhook event handler if enabled
|
|
@@ -154,7 +154,7 @@ export class Hub extends deviceBase {
|
|
|
154
154
|
this.debugLog('Registering Webhook Event Handler')
|
|
155
155
|
this.registerWebhook()
|
|
156
156
|
} catch (e: any) {
|
|
157
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
157
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
// regisiter platform BLE event handler if enabled
|
|
@@ -162,7 +162,7 @@ export class Hub extends deviceBase {
|
|
|
162
162
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
163
163
|
this.registerPlatformBLE()
|
|
164
164
|
} catch (e: any) {
|
|
165
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
165
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// Start an update interval
|
|
@@ -287,22 +287,22 @@ export class Hub extends deviceBase {
|
|
|
287
287
|
|
|
288
288
|
async BLERefreshStatus(): Promise<void> {
|
|
289
289
|
await this.debugLog('BLERefreshStatus')
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
await this.BLERefreshConnection(
|
|
290
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
291
|
+
if (switchBotBLE === undefined) {
|
|
292
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
293
293
|
} else {
|
|
294
294
|
// Start to monitor advertisement packets
|
|
295
295
|
(async () => {
|
|
296
296
|
// Start to monitor advertisement packets
|
|
297
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
297
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as hub2ServiceData
|
|
298
298
|
// Update HomeKit
|
|
299
299
|
if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
|
|
300
300
|
this.serviceData = serviceData
|
|
301
301
|
await this.BLEparseStatus()
|
|
302
302
|
await this.updateHomeKitCharacteristics()
|
|
303
303
|
} else {
|
|
304
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
305
|
-
await this.BLERefreshConnection(
|
|
304
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
305
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
306
306
|
}
|
|
307
307
|
})()
|
|
308
308
|
}
|
|
@@ -323,7 +323,7 @@ export class Hub extends deviceBase {
|
|
|
323
323
|
await this.BLEparseStatus()
|
|
324
324
|
await this.updateHomeKitCharacteristics()
|
|
325
325
|
} catch (e: any) {
|
|
326
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
326
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
} catch (error) {
|
|
@@ -365,7 +365,7 @@ export class Hub extends deviceBase {
|
|
|
365
365
|
await this.parseStatusWebhook()
|
|
366
366
|
await this.updateHomeKitCharacteristics()
|
|
367
367
|
} catch (e: any) {
|
|
368
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
368
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
} else {
|
package/src/device/humidifier.ts
CHANGED
|
@@ -137,7 +137,7 @@ export class Humidifier extends deviceBase {
|
|
|
137
137
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
138
138
|
this.refreshStatus()
|
|
139
139
|
} catch (e: any) {
|
|
140
|
-
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}`)
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
// regisiter webhook event handler if enabled
|
|
@@ -145,7 +145,7 @@ export class Humidifier extends deviceBase {
|
|
|
145
145
|
this.debugLog('Registering Webhook Event Handler')
|
|
146
146
|
this.registerWebhook()
|
|
147
147
|
} catch (e: any) {
|
|
148
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
148
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// regisiter platform BLE event handler if enabled
|
|
@@ -153,7 +153,7 @@ export class Humidifier extends deviceBase {
|
|
|
153
153
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
154
154
|
this.registerPlatformBLE()
|
|
155
155
|
} catch (e: any) {
|
|
156
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
156
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Start an update interval
|
|
@@ -317,22 +317,22 @@ export class Humidifier extends deviceBase {
|
|
|
317
317
|
|
|
318
318
|
async BLERefreshStatus(): Promise<void> {
|
|
319
319
|
await this.debugLog('BLERefreshStatus')
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
await this.BLERefreshConnection(
|
|
320
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
321
|
+
if (switchBotBLE === undefined) {
|
|
322
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
323
323
|
} else {
|
|
324
324
|
// Start to monitor advertisement packets
|
|
325
325
|
(async () => {
|
|
326
326
|
// Start to monitor advertisement packets
|
|
327
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
327
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as humidifierServiceData
|
|
328
328
|
// Update HomeKit
|
|
329
329
|
if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
|
|
330
330
|
this.serviceData = serviceData
|
|
331
331
|
await this.BLEparseStatus()
|
|
332
332
|
await this.updateHomeKitCharacteristics()
|
|
333
333
|
} else {
|
|
334
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
335
|
-
await this.BLERefreshConnection(
|
|
334
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
335
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
336
336
|
}
|
|
337
337
|
})()
|
|
338
338
|
}
|
|
@@ -353,7 +353,7 @@ export class Humidifier extends deviceBase {
|
|
|
353
353
|
await this.BLEparseStatus()
|
|
354
354
|
await this.updateHomeKitCharacteristics()
|
|
355
355
|
} catch (e: any) {
|
|
356
|
-
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}`)
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
} catch (error) {
|
|
@@ -395,7 +395,7 @@ export class Humidifier extends deviceBase {
|
|
|
395
395
|
await this.parseStatusWebhook()
|
|
396
396
|
await this.updateHomeKitCharacteristics()
|
|
397
397
|
} catch (e: any) {
|
|
398
|
-
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}`)
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
}
|
|
@@ -429,13 +429,13 @@ export class Humidifier extends deviceBase {
|
|
|
429
429
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
430
430
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
431
431
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
432
|
-
const
|
|
432
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
433
433
|
try {
|
|
434
434
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
435
435
|
this.device.bleMac = formattedDeviceId
|
|
436
436
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
437
|
-
if (
|
|
438
|
-
|
|
437
|
+
if (switchBotBLE !== false) {
|
|
438
|
+
switchBotBLE
|
|
439
439
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
440
440
|
.then(async (device_list: any) => {
|
|
441
441
|
return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
|
|
@@ -450,7 +450,7 @@ export class Humidifier extends deviceBase {
|
|
|
450
450
|
await this.BLEPushConnection()
|
|
451
451
|
})
|
|
452
452
|
} else {
|
|
453
|
-
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)}`)
|
|
454
454
|
await this.BLEPushConnection()
|
|
455
455
|
}
|
|
456
456
|
} catch (error) {
|
package/src/device/iosensor.ts
CHANGED
|
@@ -148,7 +148,7 @@ export class IOSensor extends deviceBase {
|
|
|
148
148
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
149
149
|
this.refreshStatus()
|
|
150
150
|
} catch (e: any) {
|
|
151
|
-
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}`)
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
// regisiter webhook event handler if enabled
|
|
@@ -156,7 +156,7 @@ export class IOSensor extends deviceBase {
|
|
|
156
156
|
this.debugLog('Registering Webhook Event Handler')
|
|
157
157
|
this.registerWebhook()
|
|
158
158
|
} catch (e: any) {
|
|
159
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
159
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// regisiter platform BLE event handler if enabled
|
|
@@ -164,7 +164,7 @@ export class IOSensor extends deviceBase {
|
|
|
164
164
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
165
165
|
this.registerPlatformBLE()
|
|
166
166
|
} catch (e: any) {
|
|
167
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
167
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// Start an update interval
|
|
@@ -282,22 +282,22 @@ export class IOSensor extends deviceBase {
|
|
|
282
282
|
|
|
283
283
|
async BLERefreshStatus(): Promise<void> {
|
|
284
284
|
await this.debugLog('BLERefreshStatus')
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
await this.BLERefreshConnection(
|
|
285
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
286
|
+
if (switchBotBLE === undefined) {
|
|
287
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
288
288
|
} else {
|
|
289
289
|
// Start to monitor advertisement packets
|
|
290
290
|
(async () => {
|
|
291
291
|
// Start to monitor advertisement packets
|
|
292
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
292
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as outdoorMeterServiceData
|
|
293
293
|
// Update HomeKit
|
|
294
294
|
if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
|
|
295
295
|
this.serviceData = serviceData
|
|
296
296
|
await this.BLEparseStatus()
|
|
297
297
|
await this.updateHomeKitCharacteristics()
|
|
298
298
|
} else {
|
|
299
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
300
|
-
await this.BLERefreshConnection(
|
|
299
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
300
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
301
301
|
}
|
|
302
302
|
})()
|
|
303
303
|
}
|
|
@@ -318,7 +318,7 @@ export class IOSensor extends deviceBase {
|
|
|
318
318
|
await this.BLEparseStatus()
|
|
319
319
|
await this.updateHomeKitCharacteristics()
|
|
320
320
|
} catch (e: any) {
|
|
321
|
-
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}`)
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
} catch (error) {
|
|
@@ -360,7 +360,7 @@ export class IOSensor extends deviceBase {
|
|
|
360
360
|
await this.parseStatusWebhook()
|
|
361
361
|
await this.updateHomeKitCharacteristics()
|
|
362
362
|
} catch (e: any) {
|
|
363
|
-
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}`)
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
} else {
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -148,7 +148,7 @@ export class StripLight extends deviceBase {
|
|
|
148
148
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
149
149
|
this.refreshStatus()
|
|
150
150
|
} catch (e: any) {
|
|
151
|
-
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}`)
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
// regisiter webhook event handler if enabled
|
|
@@ -156,7 +156,7 @@ export class StripLight extends deviceBase {
|
|
|
156
156
|
this.debugLog('Registering Webhook Event Handler')
|
|
157
157
|
this.registerWebhook()
|
|
158
158
|
} catch (e: any) {
|
|
159
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
159
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// regisiter platform BLE event handler if enabled
|
|
@@ -164,7 +164,7 @@ export class StripLight extends deviceBase {
|
|
|
164
164
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
165
165
|
this.registerPlatformBLE()
|
|
166
166
|
} catch (e: any) {
|
|
167
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
167
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// Start an update interval
|
|
@@ -309,22 +309,22 @@ export class StripLight extends deviceBase {
|
|
|
309
309
|
|
|
310
310
|
async BLERefreshStatus(): Promise<void> {
|
|
311
311
|
await this.debugLog('BLERefreshStatus')
|
|
312
|
-
const
|
|
313
|
-
if (
|
|
314
|
-
await this.BLERefreshConnection(
|
|
312
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
313
|
+
if (switchBotBLE === undefined) {
|
|
314
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
315
315
|
} else {
|
|
316
316
|
// Start to monitor advertisement packets
|
|
317
317
|
(async () => {
|
|
318
318
|
// Start to monitor advertisement packets
|
|
319
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
319
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as stripLightServiceData
|
|
320
320
|
// Update HomeKit
|
|
321
321
|
if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
|
|
322
322
|
this.serviceData = serviceData
|
|
323
323
|
await this.BLEparseStatus()
|
|
324
324
|
await this.updateHomeKitCharacteristics()
|
|
325
325
|
} else {
|
|
326
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
327
|
-
await this.BLERefreshConnection(
|
|
326
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
327
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
328
328
|
}
|
|
329
329
|
})()
|
|
330
330
|
}
|
|
@@ -345,7 +345,7 @@ export class StripLight extends deviceBase {
|
|
|
345
345
|
await this.BLEparseStatus()
|
|
346
346
|
await this.updateHomeKitCharacteristics()
|
|
347
347
|
} catch (e: any) {
|
|
348
|
-
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}`)
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
} catch (error) {
|
|
@@ -387,7 +387,7 @@ export class StripLight extends deviceBase {
|
|
|
387
387
|
await this.parseStatusWebhook()
|
|
388
388
|
await this.updateHomeKitCharacteristics()
|
|
389
389
|
} catch (e: any) {
|
|
390
|
-
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}`)
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
} else {
|
|
@@ -456,13 +456,13 @@ export class StripLight extends deviceBase {
|
|
|
456
456
|
await this.debugLog('BLEpushChanges')
|
|
457
457
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
458
458
|
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
459
|
-
const
|
|
459
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
460
460
|
try {
|
|
461
461
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
462
462
|
this.device.bleMac = formattedDeviceId
|
|
463
463
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
464
|
-
if (
|
|
465
|
-
|
|
464
|
+
if (switchBotBLE !== false) {
|
|
465
|
+
switchBotBLE
|
|
466
466
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
467
467
|
.then(async (device_list: any) => {
|
|
468
468
|
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
@@ -487,7 +487,7 @@ export class StripLight extends deviceBase {
|
|
|
487
487
|
await this.BLEPushConnection()
|
|
488
488
|
})
|
|
489
489
|
} else {
|
|
490
|
-
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)}`)
|
|
491
491
|
await this.BLEPushConnection()
|
|
492
492
|
}
|
|
493
493
|
} catch (error) {
|
|
@@ -501,13 +501,13 @@ export class StripLight extends deviceBase {
|
|
|
501
501
|
async BLEpushBrightnessChanges(): Promise<void> {
|
|
502
502
|
await this.debugLog('BLEpushBrightnessChanges')
|
|
503
503
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
504
|
-
const
|
|
504
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
505
505
|
try {
|
|
506
506
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
507
507
|
this.device.bleMac = formattedDeviceId
|
|
508
508
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
509
|
-
if (
|
|
510
|
-
|
|
509
|
+
if (switchBotBLE !== false) {
|
|
510
|
+
switchBotBLE
|
|
511
511
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
512
512
|
.then(async (device_list: any) => {
|
|
513
513
|
await this.infoLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
@@ -523,7 +523,7 @@ export class StripLight extends deviceBase {
|
|
|
523
523
|
await this.BLEPushConnection()
|
|
524
524
|
})
|
|
525
525
|
} else {
|
|
526
|
-
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)}`)
|
|
527
527
|
await this.BLEPushConnection()
|
|
528
528
|
}
|
|
529
529
|
} catch (error) {
|
|
@@ -540,13 +540,13 @@ export class StripLight extends deviceBase {
|
|
|
540
540
|
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
541
541
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
542
542
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
543
|
-
const
|
|
543
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
544
544
|
try {
|
|
545
545
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
546
546
|
this.device.bleMac = formattedDeviceId
|
|
547
547
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
548
|
-
if (
|
|
549
|
-
|
|
548
|
+
if (switchBotBLE !== false) {
|
|
549
|
+
switchBotBLE
|
|
550
550
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
551
551
|
.then(async (device_list: any) => {
|
|
552
552
|
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
@@ -562,7 +562,7 @@ export class StripLight extends deviceBase {
|
|
|
562
562
|
await this.BLEPushConnection()
|
|
563
563
|
})
|
|
564
564
|
} else {
|
|
565
|
-
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)}`)
|
|
566
566
|
await this.BLEPushConnection()
|
|
567
567
|
}
|
|
568
568
|
} catch (error) {
|