@switchbot/homebridge-switchbot 3.8.1 → 3.8.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/npm-version-script.cjs +81 -0
- package/CHANGELOG.md +8 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +51 -38
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +78 -64
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +55 -42
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +133 -99
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -13
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +88 -70
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +0 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +26 -22
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +54 -40
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +20 -14
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +45 -32
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +20 -14
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +107 -80
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +54 -40
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +20 -14
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +20 -14
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +55 -41
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +55 -41
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +20 -13
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +23 -0
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/device/blindtilt.ts +47 -36
- package/src/device/bot.ts +71 -59
- package/src/device/ceilinglight.ts +50 -39
- package/src/device/colorbulb.ts +128 -99
- package/src/device/contact.ts +16 -10
- package/src/device/curtain.ts +84 -69
- package/src/device/device.ts +24 -23
- package/src/device/fan.ts +49 -37
- package/src/device/hub.ts +16 -11
- package/src/device/humidifier.ts +41 -30
- package/src/device/iosensor.ts +16 -11
- package/src/device/lightstrip.ts +102 -79
- package/src/device/lock.ts +49 -37
- package/src/device/meter.ts +16 -11
- package/src/device/meterplus.ts +16 -11
- package/src/device/motion.ts +16 -10
- package/src/device/plug.ts +50 -38
- package/src/device/robotvacuumcleaner.ts +50 -38
- package/src/device/waterdetector.ts +16 -10
- package/src/utils.ts +29 -0
package/src/device/bot.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { botWebhookContext } from '../types/devicewebhookstatus.js'
|
|
|
18
18
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
19
|
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
20
20
|
|
|
21
|
+
import { formatDeviceIdAsMac } from '../utils.js'
|
|
21
22
|
import { deviceBase } from './device.js'
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -575,17 +576,22 @@ export class Bot extends deviceBase {
|
|
|
575
576
|
await this.debugLog('registerPlatformBLE')
|
|
576
577
|
if (this.config.options?.BLE) {
|
|
577
578
|
await this.debugLog('is listening to Platform BLE.')
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
579
|
+
try {
|
|
580
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
581
|
+
this.device.bleMac = formattedDeviceId
|
|
582
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
583
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
|
|
584
|
+
try {
|
|
585
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
586
|
+
this.serviceData = context
|
|
587
|
+
await this.BLEparseStatus()
|
|
588
|
+
await this.updateHomeKitCharacteristics()
|
|
589
|
+
} catch (e: any) {
|
|
590
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
591
|
+
}
|
|
588
592
|
}
|
|
593
|
+
} catch (error) {
|
|
594
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
589
595
|
}
|
|
590
596
|
} else {
|
|
591
597
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -663,57 +669,63 @@ export class Bot extends deviceBase {
|
|
|
663
669
|
if (this.On !== this.accessory.context.On || this.allowPush) {
|
|
664
670
|
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
665
671
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
switchbot
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
this.On
|
|
672
|
+
try {
|
|
673
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
674
|
+
this.device.bleMac = formattedDeviceId
|
|
675
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
676
|
+
// if (switchbot !== false) {
|
|
677
|
+
await this.debugLog(`Bot Mode: ${this.botMode}`)
|
|
678
|
+
if (this.botMode === 'press') {
|
|
679
|
+
switchbot
|
|
680
|
+
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
681
|
+
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
|
|
682
|
+
await this.infoLog(`On: ${this.On}`)
|
|
683
|
+
return await device_list[0].press({ id: this.device.bleMac })
|
|
684
|
+
})
|
|
685
|
+
.then(async () => {
|
|
686
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
681
687
|
await this.updateHomeKitCharacteristics()
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
688
|
-
await this.BLEPushConnection()
|
|
689
|
-
})
|
|
690
|
-
} else if (this.botMode === 'switch') {
|
|
691
|
-
switchbot
|
|
692
|
-
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
693
|
-
.then(async (device_list: any) => {
|
|
694
|
-
this.infoLog(`On: ${this.On}`)
|
|
695
|
-
return await this.retryBLE({
|
|
696
|
-
max: await this.maxRetryBLE(),
|
|
697
|
-
fn: async () => {
|
|
698
|
-
if (this.On) {
|
|
699
|
-
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
700
|
-
} else {
|
|
701
|
-
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
702
|
-
}
|
|
703
|
-
},
|
|
688
|
+
setTimeout(async () => {
|
|
689
|
+
this.On = false
|
|
690
|
+
await this.updateHomeKitCharacteristics()
|
|
691
|
+
this.debugLog(`On: ${this.On}, Switch Timeout`)
|
|
692
|
+
}, 500)
|
|
704
693
|
})
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
694
|
+
.catch(async (e: any) => {
|
|
695
|
+
await this.apiError(e)
|
|
696
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
697
|
+
await this.BLEPushConnection()
|
|
698
|
+
})
|
|
699
|
+
} else if (this.botMode === 'switch') {
|
|
700
|
+
switchbot
|
|
701
|
+
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
702
|
+
.then(async (device_list: any) => {
|
|
703
|
+
this.infoLog(`On: ${this.On}`)
|
|
704
|
+
return await this.retryBLE({
|
|
705
|
+
max: await this.maxRetryBLE(),
|
|
706
|
+
fn: async () => {
|
|
707
|
+
if (this.On) {
|
|
708
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
709
|
+
} else {
|
|
710
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
})
|
|
714
|
+
})
|
|
715
|
+
.then(async () => {
|
|
716
|
+
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
717
|
+
await this.updateHomeKitCharacteristics()
|
|
718
|
+
})
|
|
719
|
+
.catch(async (e: any) => {
|
|
720
|
+
await this.apiError(e)
|
|
721
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
722
|
+
await this.BLEPushConnection()
|
|
723
|
+
})
|
|
724
|
+
} else {
|
|
725
|
+
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
|
|
726
|
+
}
|
|
727
|
+
} catch (error) {
|
|
728
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
717
729
|
}
|
|
718
730
|
} else {
|
|
719
731
|
await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
@@ -18,7 +18,7 @@ import type { ceilingLightProWebhookContext, ceilingLightWebhookContext } from '
|
|
|
18
18
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
19
|
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
20
20
|
|
|
21
|
-
import { hs2rgb, m2hs } from '../utils.js'
|
|
21
|
+
import { formatDeviceIdAsMac, hs2rgb, m2hs } from '../utils.js'
|
|
22
22
|
import { deviceBase } from './device.js'
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -310,17 +310,22 @@ export class CeilingLight extends deviceBase {
|
|
|
310
310
|
await this.debugLog('registerPlatformBLE')
|
|
311
311
|
if (this.config.options?.BLE) {
|
|
312
312
|
await this.debugLog('is listening to Platform BLE.')
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
313
|
+
try {
|
|
314
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
315
|
+
this.device.bleMac = formattedDeviceId
|
|
316
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
317
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData | ceilingLightProServiceData) => {
|
|
318
|
+
try {
|
|
319
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
320
|
+
this.serviceData = context
|
|
321
|
+
await this.BLEparseStatus()
|
|
322
|
+
await this.updateHomeKitCharacteristics()
|
|
323
|
+
} catch (e: any) {
|
|
324
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
325
|
+
}
|
|
323
326
|
}
|
|
327
|
+
} catch (error) {
|
|
328
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
324
329
|
}
|
|
325
330
|
} else {
|
|
326
331
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -416,35 +421,41 @@ export class CeilingLight extends deviceBase {
|
|
|
416
421
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
417
422
|
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`)
|
|
418
423
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
424
|
+
try {
|
|
425
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
426
|
+
this.device.bleMac = formattedDeviceId
|
|
427
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
428
|
+
if (switchbot !== false) {
|
|
429
|
+
switchbot
|
|
430
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
431
|
+
.then(async (device_list: any) => {
|
|
432
|
+
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
433
|
+
return await this.retryBLE({
|
|
434
|
+
max: await this.maxRetryBLE(),
|
|
435
|
+
fn: async () => {
|
|
436
|
+
if (this.LightBulb.On) {
|
|
437
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
438
|
+
} else {
|
|
439
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
})
|
|
434
443
|
})
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
444
|
+
.then(async () => {
|
|
445
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
446
|
+
this.LightBulb.On = false
|
|
447
|
+
})
|
|
448
|
+
.catch(async (e: any) => {
|
|
449
|
+
await this.apiError(e)
|
|
450
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
451
|
+
await this.BLEPushConnection()
|
|
452
|
+
})
|
|
453
|
+
} else {
|
|
454
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
455
|
+
await this.BLEPushConnection()
|
|
456
|
+
}
|
|
457
|
+
} catch (error) {
|
|
458
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
448
459
|
}
|
|
449
460
|
} else {
|
|
450
461
|
await this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { colorBulbWebhookContext } from '../types/devicewebhookstatus.js'
|
|
|
18
18
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
19
|
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
20
20
|
|
|
21
|
-
import { hs2rgb, m2hs, rgb2hs } from '../utils.js'
|
|
21
|
+
import { formatDeviceIdAsMac, hs2rgb, m2hs, rgb2hs } from '../utils.js'
|
|
22
22
|
import { deviceBase } from './device.js'
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -333,17 +333,22 @@ export class ColorBulb extends deviceBase {
|
|
|
333
333
|
await this.debugLog('registerPlatformBLE')
|
|
334
334
|
if (this.config.options?.BLE) {
|
|
335
335
|
await this.debugLog('is listening to Platform BLE.')
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
336
|
+
try {
|
|
337
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
338
|
+
this.device.bleMac = formattedDeviceId
|
|
339
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
340
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: colorBulbServiceData) => {
|
|
341
|
+
try {
|
|
342
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
343
|
+
this.serviceData = context
|
|
344
|
+
await this.BLEparseStatus()
|
|
345
|
+
await this.updateHomeKitCharacteristics()
|
|
346
|
+
} catch (e: any) {
|
|
347
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
348
|
+
}
|
|
346
349
|
}
|
|
350
|
+
} catch (error) {
|
|
351
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
347
352
|
}
|
|
348
353
|
} else {
|
|
349
354
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -451,35 +456,41 @@ export class ColorBulb extends deviceBase {
|
|
|
451
456
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
452
457
|
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
453
458
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
459
|
+
try {
|
|
460
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
461
|
+
this.device.bleMac = formattedDeviceId
|
|
462
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
463
|
+
if (switchbot !== false) {
|
|
464
|
+
switchbot
|
|
465
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
466
|
+
.then(async (device_list: any) => {
|
|
467
|
+
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
468
|
+
return await this.retryBLE({
|
|
469
|
+
max: await this.maxRetryBLE(),
|
|
470
|
+
fn: async () => {
|
|
471
|
+
if (this.LightBulb.On) {
|
|
472
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
473
|
+
} else {
|
|
474
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
})
|
|
469
478
|
})
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
479
|
+
.then(async () => {
|
|
480
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
481
|
+
await this.updateHomeKitCharacteristics()
|
|
482
|
+
})
|
|
483
|
+
.catch(async (e: any) => {
|
|
484
|
+
await this.apiError(e)
|
|
485
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
486
|
+
await this.BLEPushConnection()
|
|
487
|
+
})
|
|
488
|
+
} else {
|
|
489
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
490
|
+
await this.BLEPushConnection()
|
|
491
|
+
}
|
|
492
|
+
} catch (error) {
|
|
493
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
483
494
|
}
|
|
484
495
|
} else {
|
|
485
496
|
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
@@ -490,26 +501,32 @@ export class ColorBulb extends deviceBase {
|
|
|
490
501
|
await this.debugLog('BLEpushBrightnessChanges')
|
|
491
502
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
492
503
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
504
|
+
try {
|
|
505
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
506
|
+
this.device.bleMac = formattedDeviceId
|
|
507
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
508
|
+
if (switchbot !== false) {
|
|
509
|
+
switchbot
|
|
510
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
511
|
+
.then(async (device_list: any) => {
|
|
512
|
+
await this.infoLog(`Target Brightness: ${this.LightBulb.Brightness}`)
|
|
513
|
+
return await device_list[0].setBrightness(this.LightBulb.Brightness)
|
|
514
|
+
})
|
|
515
|
+
.then(async () => {
|
|
516
|
+
await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
|
|
517
|
+
await this.updateHomeKitCharacteristics()
|
|
518
|
+
})
|
|
519
|
+
.catch(async (e: any) => {
|
|
520
|
+
await this.apiError(e)
|
|
521
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
522
|
+
await this.BLEPushConnection()
|
|
523
|
+
})
|
|
524
|
+
} else {
|
|
525
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
526
|
+
await this.BLEPushConnection()
|
|
527
|
+
}
|
|
528
|
+
} catch (error) {
|
|
529
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
513
530
|
}
|
|
514
531
|
} else {
|
|
515
532
|
await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
@@ -522,26 +539,32 @@ export class ColorBulb extends deviceBase {
|
|
|
522
539
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
|
|
523
540
|
this.accessory.context.kelvin = kelvin
|
|
524
541
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
542
|
+
try {
|
|
543
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
544
|
+
this.device.bleMac = formattedDeviceId
|
|
545
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
546
|
+
if (switchbot !== false) {
|
|
547
|
+
switchbot
|
|
548
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
549
|
+
.then(async (device_list: any) => {
|
|
550
|
+
await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`)
|
|
551
|
+
return await device_list[0].setColorTemperature(kelvin)
|
|
552
|
+
})
|
|
553
|
+
.then(async () => {
|
|
554
|
+
await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`)
|
|
555
|
+
await this.updateHomeKitCharacteristics()
|
|
556
|
+
})
|
|
557
|
+
.catch(async (e: any) => {
|
|
558
|
+
await this.apiError(e)
|
|
559
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
560
|
+
await this.BLEPushConnection()
|
|
561
|
+
})
|
|
562
|
+
} else {
|
|
563
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
564
|
+
await this.BLEPushConnection()
|
|
565
|
+
}
|
|
566
|
+
} catch (error) {
|
|
567
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
545
568
|
}
|
|
546
569
|
} else {
|
|
547
570
|
await this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`)
|
|
@@ -555,26 +578,32 @@ export class ColorBulb extends deviceBase {
|
|
|
555
578
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
556
579
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
557
580
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
581
|
+
try {
|
|
582
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
583
|
+
this.device.bleMac = formattedDeviceId
|
|
584
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
585
|
+
if (switchbot !== false) {
|
|
586
|
+
switchbot
|
|
587
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
588
|
+
.then(async (device_list: any) => {
|
|
589
|
+
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
590
|
+
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
|
|
591
|
+
})
|
|
592
|
+
.then(async () => {
|
|
593
|
+
await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
|
|
594
|
+
await this.updateHomeKitCharacteristics()
|
|
595
|
+
})
|
|
596
|
+
.catch(async (e: any) => {
|
|
597
|
+
await this.apiError(e)
|
|
598
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
599
|
+
await this.BLEPushConnection()
|
|
600
|
+
})
|
|
601
|
+
} else {
|
|
602
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
603
|
+
await this.BLEPushConnection()
|
|
604
|
+
}
|
|
605
|
+
} catch (error) {
|
|
606
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
578
607
|
}
|
|
579
608
|
} else {
|
|
580
609
|
await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
|
package/src/device/contact.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { contactSensorWebhookContext } from '../types/devicewebhookstatus.j
|
|
|
18
18
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
19
|
import { interval, skipWhile, Subject } from 'rxjs'
|
|
20
20
|
|
|
21
|
+
import { formatDeviceIdAsMac } from '../utils.js'
|
|
21
22
|
import { deviceBase } from './device.js'
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -326,17 +327,22 @@ export class Contact extends deviceBase {
|
|
|
326
327
|
await this.debugLog('registerPlatformBLE')
|
|
327
328
|
if (this.config.options?.BLE) {
|
|
328
329
|
await this.debugLog('is listening to Platform BLE.')
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
330
|
+
try {
|
|
331
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
332
|
+
this.device.bleMac = formattedDeviceId
|
|
333
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
334
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: contactSensorServiceData) => {
|
|
335
|
+
try {
|
|
336
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
337
|
+
this.serviceData = context
|
|
338
|
+
await this.BLEparseStatus()
|
|
339
|
+
await this.updateHomeKitCharacteristics()
|
|
340
|
+
} catch (e: any) {
|
|
341
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
342
|
+
}
|
|
339
343
|
}
|
|
344
|
+
} catch (error) {
|
|
345
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
340
346
|
}
|
|
341
347
|
} else {
|
|
342
348
|
await this.debugLog('is not listening to Platform BLE')
|