@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/lightstrip.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { stripLightWebhookContext } 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
|
/**
|
|
@@ -337,17 +337,22 @@ export class StripLight extends deviceBase {
|
|
|
337
337
|
await this.debugLog('registerPlatformBLE')
|
|
338
338
|
if (this.config.options?.BLE) {
|
|
339
339
|
await this.debugLog('is listening to Platform BLE.')
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
340
|
+
try {
|
|
341
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
342
|
+
this.device.bleMac = formattedDeviceId
|
|
343
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
344
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: stripLightServiceData) => {
|
|
345
|
+
try {
|
|
346
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
347
|
+
this.serviceData = context
|
|
348
|
+
await this.BLEparseStatus()
|
|
349
|
+
await this.updateHomeKitCharacteristics()
|
|
350
|
+
} catch (e: any) {
|
|
351
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
352
|
+
}
|
|
350
353
|
}
|
|
354
|
+
} catch (error) {
|
|
355
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
351
356
|
}
|
|
352
357
|
} else {
|
|
353
358
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -455,35 +460,41 @@ export class StripLight extends deviceBase {
|
|
|
455
460
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
456
461
|
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
457
462
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
463
|
+
try {
|
|
464
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
465
|
+
this.device.bleMac = formattedDeviceId
|
|
466
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
467
|
+
if (switchbot !== false) {
|
|
468
|
+
switchbot
|
|
469
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
470
|
+
.then(async (device_list: any) => {
|
|
471
|
+
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
472
|
+
return await this.retryBLE({
|
|
473
|
+
max: await this.maxRetryBLE(),
|
|
474
|
+
fn: async () => {
|
|
475
|
+
if (this.LightBulb.On) {
|
|
476
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
477
|
+
} else {
|
|
478
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
})
|
|
473
482
|
})
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
.then(async () => {
|
|
484
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
485
|
+
await this.updateHomeKitCharacteristics()
|
|
486
|
+
})
|
|
487
|
+
.catch(async (e: any) => {
|
|
488
|
+
await this.apiError(e)
|
|
489
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
490
|
+
await this.BLEPushConnection()
|
|
491
|
+
})
|
|
492
|
+
} else {
|
|
493
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
494
|
+
await this.BLEPushConnection()
|
|
495
|
+
}
|
|
496
|
+
} catch (error) {
|
|
497
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
487
498
|
}
|
|
488
499
|
} else {
|
|
489
500
|
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
@@ -494,26 +505,32 @@ export class StripLight extends deviceBase {
|
|
|
494
505
|
await this.debugLog('BLEpushBrightnessChanges')
|
|
495
506
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
496
507
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
508
|
+
try {
|
|
509
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
510
|
+
this.device.bleMac = formattedDeviceId
|
|
511
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
512
|
+
if (switchbot !== false) {
|
|
513
|
+
switchbot
|
|
514
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
515
|
+
.then(async (device_list: any) => {
|
|
516
|
+
await this.infoLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
517
|
+
return await device_list[0].setBrightness(this.LightBulb.Brightness)
|
|
518
|
+
})
|
|
519
|
+
.then(async () => {
|
|
520
|
+
await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
|
|
521
|
+
await this.updateHomeKitCharacteristics()
|
|
522
|
+
})
|
|
523
|
+
.catch(async (e: any) => {
|
|
524
|
+
await this.apiError(e)
|
|
525
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
526
|
+
await this.BLEPushConnection()
|
|
527
|
+
})
|
|
528
|
+
} else {
|
|
529
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
530
|
+
await this.BLEPushConnection()
|
|
531
|
+
}
|
|
532
|
+
} catch (error) {
|
|
533
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
517
534
|
}
|
|
518
535
|
} else {
|
|
519
536
|
await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
@@ -527,26 +544,32 @@ export class StripLight extends deviceBase {
|
|
|
527
544
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
528
545
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
529
546
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
547
|
+
try {
|
|
548
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
549
|
+
this.device.bleMac = formattedDeviceId
|
|
550
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
551
|
+
if (switchbot !== false) {
|
|
552
|
+
switchbot
|
|
553
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
554
|
+
.then(async (device_list: any) => {
|
|
555
|
+
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
556
|
+
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
|
|
557
|
+
})
|
|
558
|
+
.then(async () => {
|
|
559
|
+
await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
|
|
560
|
+
await this.updateHomeKitCharacteristics()
|
|
561
|
+
})
|
|
562
|
+
.catch(async (e: any) => {
|
|
563
|
+
await this.apiError(e)
|
|
564
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
565
|
+
await this.BLEPushConnection()
|
|
566
|
+
})
|
|
567
|
+
} else {
|
|
568
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
569
|
+
await this.BLEPushConnection()
|
|
570
|
+
}
|
|
571
|
+
} catch (error) {
|
|
572
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
550
573
|
}
|
|
551
574
|
} else {
|
|
552
575
|
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/lock.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { lockProWebhookContext, lockWebhookContext } from '../types/devicew
|
|
|
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
|
export class Lock extends deviceBase {
|
|
@@ -349,17 +350,22 @@ export class Lock extends deviceBase {
|
|
|
349
350
|
await this.debugLog('registerPlatformBLE')
|
|
350
351
|
if (this.config.options?.BLE) {
|
|
351
352
|
await this.debugLog('is listening to Platform BLE.')
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
353
|
+
try {
|
|
354
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
355
|
+
this.device.bleMac = formattedDeviceId
|
|
356
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
357
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: lockServiceData | lockProServiceData) => {
|
|
358
|
+
try {
|
|
359
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
360
|
+
this.serviceData = context
|
|
361
|
+
await this.BLEparseStatus()
|
|
362
|
+
await this.updateHomeKitCharacteristics()
|
|
363
|
+
} catch (e: any) {
|
|
364
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
365
|
+
}
|
|
362
366
|
}
|
|
367
|
+
} catch (error) {
|
|
368
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
363
369
|
}
|
|
364
370
|
} else {
|
|
365
371
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -435,34 +441,40 @@ export class Lock extends deviceBase {
|
|
|
435
441
|
await this.debugLog('BLEpushChanges')
|
|
436
442
|
if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
|
|
437
443
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
444
|
+
try {
|
|
445
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
446
|
+
this.device.bleMac = formattedDeviceId
|
|
447
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
448
|
+
if (switchbot !== false) {
|
|
449
|
+
switchbot
|
|
450
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
451
|
+
.then(async (device_list: any) => {
|
|
452
|
+
return await this.retryBLE({
|
|
453
|
+
max: await this.maxRetryBLE(),
|
|
454
|
+
fn: async () => {
|
|
455
|
+
if (this.LockMechanism.LockTargetState === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
456
|
+
return await device_list[0].lock({ id: this.device.bleMac })
|
|
457
|
+
} else {
|
|
458
|
+
return await device_list[0].unlock({ id: this.device.bleMac })
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
})
|
|
452
462
|
})
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
.then(async () => {
|
|
464
|
+
await this.successLog(`LockTargetState: ${this.LockMechanism.LockTargetState} sent over SwitchBot BLE, sent successfully`)
|
|
465
|
+
await this.updateHomeKitCharacteristics()
|
|
466
|
+
})
|
|
467
|
+
.catch(async (e: any) => {
|
|
468
|
+
await this.apiError(e)
|
|
469
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
470
|
+
await this.BLEPushConnection()
|
|
471
|
+
})
|
|
472
|
+
} else {
|
|
473
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
474
|
+
await this.BLEPushConnection()
|
|
475
|
+
}
|
|
476
|
+
} catch (error) {
|
|
477
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
466
478
|
}
|
|
467
479
|
} else {
|
|
468
480
|
await this.debugLog(`No changes (BLEpushChanges), LockTargetState: ${this.LockMechanism.LockTargetState}, LockCurrentState: ${this.LockMechanism.LockCurrentState}`)
|
package/src/device/meter.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { Units } from 'homebridge'
|
|
|
19
19
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
20
20
|
import { interval, skipWhile, Subject } from 'rxjs'
|
|
21
21
|
|
|
22
|
-
import { convertUnits, validHumidity } from '../utils.js'
|
|
22
|
+
import { convertUnits, formatDeviceIdAsMac, validHumidity } from '../utils.js'
|
|
23
23
|
import { deviceBase } from './device.js'
|
|
24
24
|
|
|
25
25
|
export class Meter extends deviceBase {
|
|
@@ -305,17 +305,22 @@ export class Meter extends deviceBase {
|
|
|
305
305
|
await this.debugLog('registerPlatformBLE')
|
|
306
306
|
if (this.config.options?.BLE) {
|
|
307
307
|
await this.debugLog('is listening to Platform BLE.')
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
308
|
+
try {
|
|
309
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
310
|
+
this.device.bleMac = formattedDeviceId
|
|
311
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
312
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterServiceData) => {
|
|
313
|
+
try {
|
|
314
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
315
|
+
this.serviceData = context
|
|
316
|
+
await this.BLEparseStatus()
|
|
317
|
+
await this.updateHomeKitCharacteristics()
|
|
318
|
+
} catch (e: any) {
|
|
319
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
320
|
+
}
|
|
318
321
|
}
|
|
322
|
+
} catch (error) {
|
|
323
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
319
324
|
}
|
|
320
325
|
} else {
|
|
321
326
|
await this.debugLog('is not listening to Platform BLE')
|
package/src/device/meterplus.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { Units } from 'homebridge'
|
|
|
19
19
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
20
20
|
import { interval, skipWhile, Subject } from 'rxjs'
|
|
21
21
|
|
|
22
|
-
import { convertUnits, validHumidity } from '../utils.js'
|
|
22
|
+
import { convertUnits, formatDeviceIdAsMac, validHumidity } from '../utils.js'
|
|
23
23
|
import { deviceBase } from './device.js'
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -307,17 +307,22 @@ export class MeterPlus extends deviceBase {
|
|
|
307
307
|
await this.debugLog('registerPlatformBLE')
|
|
308
308
|
if (this.config.options?.BLE) {
|
|
309
309
|
await this.debugLog('is listening to Platform BLE.')
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
310
|
+
try {
|
|
311
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
312
|
+
this.device.bleMac = formattedDeviceId
|
|
313
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
314
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterPlusServiceData) => {
|
|
315
|
+
try {
|
|
316
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
317
|
+
this.serviceData = context
|
|
318
|
+
await this.BLEparseStatus()
|
|
319
|
+
await this.updateHomeKitCharacteristics()
|
|
320
|
+
} catch (e: any) {
|
|
321
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
322
|
+
}
|
|
320
323
|
}
|
|
324
|
+
} catch (error) {
|
|
325
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
321
326
|
}
|
|
322
327
|
} else {
|
|
323
328
|
await this.debugLog('is not listening to Platform BLE')
|
package/src/device/motion.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { motionSensorWebhookContext } from '../types/devicewebhookstatus.js
|
|
|
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
|
/**
|
|
@@ -281,17 +282,22 @@ export class Motion extends deviceBase {
|
|
|
281
282
|
await this.debugLog('registerPlatformBLE')
|
|
282
283
|
if (this.config.options?.BLE) {
|
|
283
284
|
await this.debugLog('is listening to Platform BLE.')
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
285
|
+
try {
|
|
286
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
287
|
+
this.device.bleMac = formattedDeviceId
|
|
288
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
289
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: motionSensorServiceData) => {
|
|
290
|
+
try {
|
|
291
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
292
|
+
this.serviceData = context
|
|
293
|
+
await this.BLEparseStatus()
|
|
294
|
+
await this.updateHomeKitCharacteristics()
|
|
295
|
+
} catch (e: any) {
|
|
296
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
297
|
+
}
|
|
294
298
|
}
|
|
299
|
+
} catch (error) {
|
|
300
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
295
301
|
}
|
|
296
302
|
} else {
|
|
297
303
|
await this.debugLog('is not listening to Platform BLE')
|
package/src/device/plug.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { plugMiniJPWebhookContext, plugMiniUSWebhookContext, plugWebhookCon
|
|
|
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
|
export class Plug extends deviceBase {
|
|
@@ -205,17 +206,22 @@ export class Plug extends deviceBase {
|
|
|
205
206
|
await this.debugLog('registerPlatformBLE')
|
|
206
207
|
if (this.config.options?.BLE) {
|
|
207
208
|
await this.debugLog('is listening to Platform BLE.')
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
209
|
+
try {
|
|
210
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
211
|
+
this.device.bleMac = formattedDeviceId
|
|
212
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
213
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: plugMiniUSServiceData | plugMiniJPServiceData) => {
|
|
214
|
+
try {
|
|
215
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
216
|
+
this.serviceData = context
|
|
217
|
+
await this.BLEparseStatus()
|
|
218
|
+
await this.updateHomeKitCharacteristics()
|
|
219
|
+
} catch (e: any) {
|
|
220
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
221
|
+
}
|
|
218
222
|
}
|
|
223
|
+
} catch (error) {
|
|
224
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
219
225
|
}
|
|
220
226
|
} else {
|
|
221
227
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -296,35 +302,41 @@ export class Plug extends deviceBase {
|
|
|
296
302
|
if (this.Outlet.On !== this.accessory.context.On) {
|
|
297
303
|
await this.debugLog(`BLEpushChanges On: ${this.Outlet.On}, OnCached: ${this.accessory.context.On}`)
|
|
298
304
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
305
|
+
try {
|
|
306
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
307
|
+
this.device.bleMac = formattedDeviceId
|
|
308
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
309
|
+
if (switchbot !== false) {
|
|
310
|
+
switchbot
|
|
311
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
312
|
+
.then(async (device_list: any) => {
|
|
313
|
+
await this.infoLog(`On: ${this.Outlet.On}`)
|
|
314
|
+
return await this.retryBLE({
|
|
315
|
+
max: await this.maxRetryBLE(),
|
|
316
|
+
fn: async () => {
|
|
317
|
+
if (this.Outlet.On) {
|
|
318
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
319
|
+
} else {
|
|
320
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
})
|
|
314
324
|
})
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
325
|
+
.then(async () => {
|
|
326
|
+
await this.successLog(`On: ${this.Outlet.On} sent over SwitchBot BLE, sent successfully`)
|
|
327
|
+
await this.updateHomeKitCharacteristics()
|
|
328
|
+
})
|
|
329
|
+
.catch(async (e: any) => {
|
|
330
|
+
await this.apiError(e)
|
|
331
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
332
|
+
await this.BLEPushConnection()
|
|
333
|
+
})
|
|
334
|
+
} else {
|
|
335
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
336
|
+
await this.BLEPushConnection()
|
|
337
|
+
}
|
|
338
|
+
} catch (error) {
|
|
339
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
328
340
|
}
|
|
329
341
|
} else {
|
|
330
342
|
await this.debugLog(`No changes (BLEpushChanges), On: ${this.Outlet.On}, OnCached: ${this.accessory.context.On}`)
|