@switchbot/homebridge-switchbot 3.3.0-beta.1 → 3.3.0-beta.3

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.
Files changed (71) hide show
  1. package/dist/device/blindtilt.d.ts.map +1 -1
  2. package/dist/device/blindtilt.js +72 -37
  3. package/dist/device/blindtilt.js.map +1 -1
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +68 -35
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts.map +1 -1
  8. package/dist/device/ceilinglight.js +73 -39
  9. package/dist/device/ceilinglight.js.map +1 -1
  10. package/dist/device/colorbulb.d.ts +5 -3
  11. package/dist/device/colorbulb.d.ts.map +1 -1
  12. package/dist/device/colorbulb.js +84 -44
  13. package/dist/device/colorbulb.js.map +1 -1
  14. package/dist/device/contact.d.ts.map +1 -1
  15. package/dist/device/contact.js +71 -39
  16. package/dist/device/contact.js.map +1 -1
  17. package/dist/device/curtain.d.ts.map +1 -1
  18. package/dist/device/curtain.js +71 -36
  19. package/dist/device/curtain.js.map +1 -1
  20. package/dist/device/hub.d.ts.map +1 -1
  21. package/dist/device/hub.js +8 -2
  22. package/dist/device/hub.js.map +1 -1
  23. package/dist/device/humidifier.d.ts.map +1 -1
  24. package/dist/device/humidifier.js +69 -36
  25. package/dist/device/humidifier.js.map +1 -1
  26. package/dist/device/iosensor.d.ts.map +1 -1
  27. package/dist/device/iosensor.js +74 -40
  28. package/dist/device/iosensor.js.map +1 -1
  29. package/dist/device/lightstrip.d.ts.map +1 -1
  30. package/dist/device/lightstrip.js +67 -39
  31. package/dist/device/lightstrip.js.map +1 -1
  32. package/dist/device/lock.d.ts.map +1 -1
  33. package/dist/device/lock.js +70 -36
  34. package/dist/device/lock.js.map +1 -1
  35. package/dist/device/meter.d.ts.map +1 -1
  36. package/dist/device/meter.js +74 -40
  37. package/dist/device/meter.js.map +1 -1
  38. package/dist/device/meterplus.d.ts.map +1 -1
  39. package/dist/device/meterplus.js +74 -40
  40. package/dist/device/meterplus.js.map +1 -1
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +86 -53
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts.map +1 -1
  45. package/dist/device/plug.js +67 -37
  46. package/dist/device/plug.js.map +1 -1
  47. package/dist/device/robotvacuumcleaner.d.ts +0 -1
  48. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  49. package/dist/device/robotvacuumcleaner.js +69 -47
  50. package/dist/device/robotvacuumcleaner.js.map +1 -1
  51. package/dist/platform.d.ts.map +1 -1
  52. package/dist/platform.js +2 -6
  53. package/dist/platform.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/device/blindtilt.ts +32 -3
  56. package/src/device/bot.ts +30 -3
  57. package/src/device/ceilinglight.ts +35 -5
  58. package/src/device/colorbulb.ts +46 -10
  59. package/src/device/contact.ts +29 -3
  60. package/src/device/curtain.ts +34 -3
  61. package/src/device/hub.ts +6 -2
  62. package/src/device/humidifier.ts +30 -3
  63. package/src/device/iosensor.ts +31 -3
  64. package/src/device/lightstrip.ts +29 -5
  65. package/src/device/lock.ts +31 -3
  66. package/src/device/meter.ts +31 -3
  67. package/src/device/meterplus.ts +31 -3
  68. package/src/device/motion.ts +30 -3
  69. package/src/device/plug.ts +28 -4
  70. package/src/device/robotvacuumcleaner.ts +29 -13
  71. package/src/platform.ts +2 -6
@@ -3,7 +3,7 @@ import { sleep } from '../utils.js';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform.js';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices, SwitchBotPlatformConfig } from '../settings.js';
6
+ import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
7
  import {
8
8
  Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, API, Logging, HAP,
9
9
  } from 'homebridge';
@@ -371,7 +371,37 @@ export class CeilingLight {
371
371
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
372
372
  this.getCustomBLEAddress(switchbot);
373
373
  // Start to monitor advertisement packets
374
- if (switchbot !== false) {
374
+ (async () => {
375
+ // Start to monitor advertisement packets
376
+ await switchbot.startScan({
377
+ id: this.device.bleMac,
378
+ });
379
+ // Set an event handler
380
+ switchbot.onadvertisement = (ad: any) => {
381
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
382
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
383
+ if (this.device.bleMac === ad.address && ad.model === 's') {
384
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
385
+ this.BLE_On = ad.serviceData.state;
386
+ //this.delay = ad.serviceData.delay;
387
+ //this.timer = ad.serviceData.timer;
388
+ //this.syncUtcTime = ad.serviceData.syncUtcTime;
389
+ //this.wifiRssi = ad.serviceData.wifiRssi;
390
+ //this.overload = ad.serviceData.overload;
391
+ //this.currentPower = ad.serviceData.currentPower;
392
+ } else {
393
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
394
+ }
395
+ };
396
+ // Wait 1 seconds
397
+ await switchbot.wait(this.scanDuration * 1000);
398
+ // Stop to monitor
399
+ await switchbot.stopScan();
400
+ // Update HomeKit
401
+ await this.BLEparseStatus();
402
+ await this.updateHomeKitCharacteristics();
403
+ })();
404
+ /*if (switchbot !== false) {
375
405
  switchbot
376
406
  .startScan({
377
407
  model: '',
@@ -393,11 +423,11 @@ export class CeilingLight {
393
423
  //this.overload = ad.serviceData.overload;
394
424
  //this.currentPower = ad.serviceData.currentPower;
395
425
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
396
- /*this.debugLog(
426
+ this.debugLog(
397
427
  `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
398
428
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
399
429
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
400
- );*/
430
+ );
401
431
 
402
432
  if (ad.serviceData) {
403
433
  this.BLE_IsConnected = true;
@@ -425,7 +455,7 @@ export class CeilingLight {
425
455
  });
426
456
  } else {
427
457
  await this.BLERefreshConnection(switchbot);
428
- }
458
+ }*/
429
459
  }
430
460
 
431
461
  async openAPIRefreshStatus() {
@@ -3,7 +3,7 @@ import { sleep } from '../utils.js';
3
3
  import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform.js';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
- import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices, SwitchBotPlatformConfig } from '../settings.js';
6
+ import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
7
  import {
8
8
  Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, API, Logging, HAP,
9
9
  } from 'homebridge';
@@ -37,15 +37,17 @@ export class ColorBulb {
37
37
  OpenAPI_ColorTemperature?: deviceStatus['colorTemperature'];
38
38
 
39
39
  // BLE Status
40
+ BLE_ColorTemperature: serviceData['color_temperature'];
41
+ BLE_Power: serviceData['power'];
40
42
  BLE_Red: serviceData['red'];
41
- BLE_On: serviceData['state'];
42
43
  BLE_Blue: serviceData['blue'];
43
- BLE_Power: serviceData['power'];
44
44
  BLE_Green: serviceData['green'];
45
+ BLE_On: serviceData['state'];
45
46
  BLE_Delay: serviceData['delay'];
46
47
  BLE_WifiRssi: serviceData['wifiRssi'];
47
48
  BLE_Brightness: serviceData['brightness'];
48
- BLE_ColorTemperature: serviceData['color_temperature'];
49
+ BLE_Saturation;
50
+ BLE_Hue;
49
51
 
50
52
  // BLE Others
51
53
  BLE_IsConnected?: boolean;
@@ -316,13 +318,15 @@ export class ColorBulb {
316
318
  `${this.device.deviceType}: ${this.accessory.displayName}` +
317
319
  ` hs: ${JSON.stringify(rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue)))}`,
318
320
  );
321
+ this.BLE_Hue = hue;
322
+ this.BLE_Saturation = saturation;
319
323
 
320
324
  // Hue
321
- this.Hue = hue;
325
+ this.Hue = this.BLE_Hue;
322
326
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
323
327
 
324
328
  // Saturation
325
- this.Saturation = saturation;
329
+ this.Saturation = this.BLE_Saturation;
326
330
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
327
331
 
328
332
  // ColorTemperature
@@ -418,7 +422,39 @@ export class ColorBulb {
418
422
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
419
423
  this.getCustomBLEAddress(switchbot);
420
424
  // Start to monitor advertisement packets
421
- if (switchbot !== false) {
425
+ (async () => {
426
+ // Start to monitor advertisement packets
427
+ await switchbot.startScan({
428
+ model: 'u',
429
+ id: this.device.bleMac,
430
+ });
431
+ // Set an event handler
432
+ switchbot.onadvertisement = (ad: any) => {
433
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
434
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
435
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'u') {
436
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
437
+ this.BLE_ColorTemperature = ad.serviceData.color_temperature;
438
+ this.BLE_Power = ad.serviceData.power;
439
+ this.BLE_On = ad.serviceData.state;
440
+ this.BLE_Red = ad.serviceData.red;
441
+ this.BLE_Green = ad.serviceData.green;
442
+ this.BLE_Blue = ad.serviceData.blue;
443
+ this.BLE_Brightness = ad.serviceData.brightness;
444
+ this.BLE_Delay = ad.serviceData.delay;
445
+ } else {
446
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
447
+ }
448
+ };
449
+ // Wait 1 seconds
450
+ await switchbot.wait(this.scanDuration * 1000);
451
+ // Stop to monitor
452
+ await switchbot.stopScan();
453
+ // Update HomeKit
454
+ await this.BLEparseStatus();
455
+ await this.updateHomeKitCharacteristics();
456
+ })();
457
+ /*if (switchbot !== false) {
422
458
  switchbot
423
459
  .startScan({
424
460
  model: 'u',
@@ -441,11 +477,11 @@ export class ColorBulb {
441
477
  this.BLE_Brightness = ad.serviceData.brightness;
442
478
  this.BLE_Delay = ad.serviceData.delay;
443
479
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
444
- /*this.debugLog(
480
+ this.debugLog(
445
481
  `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
446
482
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
447
483
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
448
- );*/
484
+ );
449
485
 
450
486
  if (ad.serviceData) {
451
487
  this.BLE_IsConnected = true;
@@ -473,7 +509,7 @@ export class ColorBulb {
473
509
  });
474
510
  } else {
475
511
  await this.BLERefreshConnection(switchbot);
476
- }
512
+ }*/
477
513
  }
478
514
 
479
515
  async openAPIRefreshStatus() {
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
4
4
  import { skipWhile } from 'rxjs/operators';
5
5
  import { SwitchBotPlatform } from '../platform.js';
6
6
  import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
7
- import { device, devicesConfig, serviceData, deviceStatus, ad, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
+ import { device, devicesConfig, serviceData, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
8
8
 
9
9
  /**
10
10
  * Platform Accessory
@@ -353,7 +353,33 @@ export class Contact {
353
353
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
354
354
  this.getCustomBLEAddress(switchbot);
355
355
  // Start to monitor advertisement packets
356
- if (switchbot !== false) {
356
+ (async () => {
357
+ await switchbot.startScan({
358
+ model: 'd',
359
+ id: this.device.bleMac,
360
+ });
361
+ // Set an event handler
362
+ switchbot.onadvertisement = (ad: any) => {
363
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
364
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
365
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'd') {
366
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
367
+ this.BLE_MotionDetected = ad.serviceData.movement;
368
+ this.BLE_BatteryLevel = ad.serviceData.battery;
369
+ this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
370
+ } else {
371
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
372
+ }
373
+ };
374
+ // Wait 1 seconds
375
+ await switchbot.wait(this.scanDuration * 1000);
376
+ // Stop to monitor
377
+ await switchbot.stopScan();
378
+ // Update HomeKit
379
+ await this.BLEparseStatus();
380
+ await this.updateHomeKitCharacteristics();
381
+ })();
382
+ /*if (switchbot !== false) {
357
383
  await switchbot
358
384
  .startScan({
359
385
  model: 'd',
@@ -405,7 +431,7 @@ export class Contact {
405
431
  });
406
432
  } else {
407
433
  await this.BLERefreshConnection(switchbot);
408
- }
434
+ }*/
409
435
  }
410
436
 
411
437
  async openAPIRefreshStatus(): Promise<void> {
@@ -6,7 +6,7 @@ import asyncmqtt from 'async-mqtt';
6
6
  import { SwitchBotPlatform } from '../platform.js';
7
7
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
8
  import { Service, PlatformAccessory, CharacteristicValue, CharacteristicChange, API, Logging, HAP } from 'homebridge';
9
- import { device, devicesConfig, serviceData, deviceStatus, ad, Devices, SwitchBotPlatformConfig } from '../settings.js';
9
+ import { device, devicesConfig, serviceData, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
10
10
  import { hostname } from 'os';
11
11
 
12
12
  export class Curtain {
@@ -546,7 +546,38 @@ export class Curtain {
546
546
  default:
547
547
  model = 'c';
548
548
  }
549
- if (switchbot !== false) {
549
+ (async () => {
550
+ // Start to monitor advertisement packets
551
+ await switchbot.startScan({
552
+ model: model,
553
+ id: this.device.bleMac,
554
+ });
555
+ // Set an event handler
556
+ switchbot.onadvertisement = (ad: any) => {
557
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
558
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
559
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'c') {
560
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
561
+ this.BLE_Calibration = ad.serviceData.calibration;
562
+ this.BLE_BatteryLevel = ad.serviceData.battery;
563
+ this.BLE_InMotion = ad.serviceData.inMotion;
564
+ this.BLE_CurrentPosition = ad.serviceData.position;
565
+ this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
566
+ } else {
567
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
568
+ }
569
+ };
570
+ // Wait 1 seconds
571
+ await switchbot.wait(this.scanDuration * 1000);
572
+ // Stop to monitor
573
+ await switchbot.stopScan();
574
+ // Update HomeKit
575
+ await this.BLEparseStatus();
576
+ await this.updateHomeKitCharacteristics();
577
+ })();
578
+
579
+
580
+ /*if (switchbot !== false) {
550
581
  switchbot
551
582
  .startScan({
552
583
  model: model,
@@ -597,7 +628,7 @@ export class Curtain {
597
628
  });
598
629
  } else {
599
630
  await this.BLERefreshConnection(switchbot);
600
- }
631
+ }*/
601
632
  }
602
633
 
603
634
  async openAPIRefreshStatus(): Promise<void> {
package/src/device/hub.ts CHANGED
@@ -286,7 +286,9 @@ export class Hub {
286
286
  * Parse the device status from the SwitchBot api
287
287
  */
288
288
  async parseStatus(): Promise<void> {
289
- if (this.OpenAPI && this.platform.config.credentials?.token) {
289
+ if (this.BLE) {
290
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE not supported`);
291
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
290
292
  await this.openAPIparseStatus();
291
293
  } else {
292
294
  await this.offlineOff();
@@ -417,7 +419,9 @@ export class Hub {
417
419
  }
418
420
 
419
421
  async refreshStatus(): Promise<void> {
420
- if (this.OpenAPI && this.platform.config.credentials?.token) {
422
+ if (this.BLE) {
423
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE not supported`);
424
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
421
425
  await this.openAPIRefreshStatus();
422
426
  } else {
423
427
  await this.offlineOff();
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform.js';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
6
  import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
7
- import { device, devicesConfig, serviceData, ad, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
+ import { device, devicesConfig, serviceData, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
8
8
 
9
9
  /**
10
10
  * Platform Accessory
@@ -348,7 +348,34 @@ export class Humidifier {
348
348
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
349
349
  this.getCustomBLEAddress(switchbot);
350
350
  // Start to monitor advertisement packets
351
- if (switchbot !== false) {
351
+ (async () => {
352
+ // Start to monitor advertisement packets
353
+ await switchbot.startScan({
354
+ model: 'e',
355
+ id: this.device.bleMac,
356
+ });
357
+ // Set an event handler
358
+ switchbot.onadvertisement = (ad: any) => {
359
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
360
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
361
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'e') {
362
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
363
+ this.autoMode = ad.serviceData.autoMode;
364
+ this.onState = ad.serviceData.onState;
365
+ this.percentage = ad.serviceData.percentage > 100 ? 100 : ad.serviceData.percentage;
366
+ } else {
367
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
368
+ }
369
+ };
370
+ // Wait 1 seconds
371
+ await switchbot.wait(this.scanDuration * 1000);
372
+ // Stop to monitor
373
+ await switchbot.stopScan();
374
+ // Update HomeKit
375
+ await this.BLEparseStatus();
376
+ await this.updateHomeKitCharacteristics();
377
+ })();
378
+ /*if (switchbot !== false) {
352
379
  switchbot
353
380
  .startScan({
354
381
  model: 'e',
@@ -396,7 +423,7 @@ export class Humidifier {
396
423
  });
397
424
  } else {
398
425
  await this.BLERefreshConnection(switchbot);
399
- }
426
+ }*/
400
427
  }
401
428
 
402
429
  async openAPIRefreshStatus(): Promise<void> {
@@ -7,7 +7,7 @@ import { interval, Subject } from 'rxjs';
7
7
  import { skipWhile } from 'rxjs/operators';
8
8
  import { SwitchBotPlatform } from '../platform.js';
9
9
  import { Service, PlatformAccessory, Units, CharacteristicValue, API, Logging, HAP } from 'homebridge';
10
- import { device, devicesConfig, serviceData, ad, temperature, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
10
+ import { device, devicesConfig, serviceData, temperature, deviceStatus, Devices, SwitchBotPlatformConfig } from '../settings.js';
11
11
 
12
12
  /**
13
13
  * Platform Accessory
@@ -321,7 +321,35 @@ export class IOSensor {
321
321
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
322
322
  this.getCustomBLEAddress(switchbot);
323
323
  // Start to monitor advertisement packets
324
- if (switchbot !== false) {
324
+ (async () => {
325
+ // Start to monitor advertisement packets
326
+ await switchbot.startScan({
327
+ model: 'w',
328
+ id: this.device.bleMac,
329
+ });
330
+ // Set an event handler
331
+ switchbot.onadvertisement = (ad: any) => {
332
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
333
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
334
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'w') {
335
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
336
+ this.BLE_CurrentTemperature = ad.serviceData.temperature;
337
+ this.BLE_Celsius = ad.serviceData.temperature!.c;
338
+ this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
339
+ this.BLE_BatteryLevel = ad.serviceData.battery;
340
+ } else {
341
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
342
+ }
343
+ };
344
+ // Wait 1 seconds
345
+ await switchbot.wait(this.scanDuration * 1000);
346
+ // Stop to monitor
347
+ await switchbot.stopScan();
348
+ // Update HomeKit
349
+ await this.BLEparseStatus();
350
+ await this.updateHomeKitCharacteristics();
351
+ })();
352
+ /*if (switchbot !== false) {
325
353
  switchbot
326
354
  .startScan({
327
355
  model: 'w',
@@ -375,7 +403,7 @@ export class IOSensor {
375
403
  });
376
404
  } else {
377
405
  await this.BLERefreshConnection(switchbot);
378
- }
406
+ }*/
379
407
  }
380
408
 
381
409
  async openAPIRefreshStatus(): Promise<void> {
@@ -6,7 +6,7 @@ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
6
  import {
7
7
  Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, API, Logging, HAP,
8
8
  } from 'homebridge';
9
- import { device, devicesConfig, hs2rgb, rgb2hs, deviceStatus, ad, serviceData, m2hs, Devices, SwitchBotPlatformConfig } from '../settings.js';
9
+ import { device, devicesConfig, hs2rgb, rgb2hs, deviceStatus, serviceData, m2hs, Devices, SwitchBotPlatformConfig } from '../settings.js';
10
10
 
11
11
  /**
12
12
  * Platform Accessory
@@ -364,7 +364,31 @@ export class StripLight {
364
364
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
365
365
  this.getCustomBLEAddress(switchbot);
366
366
  // Start to monitor advertisement packets
367
- if (switchbot !== false) {
367
+ (async () => {
368
+ // Start to monitor advertisement packets
369
+ await switchbot.startScan({
370
+ model: 'r',
371
+ id: this.device.bleMac,
372
+ });
373
+ // Set an event handler
374
+ switchbot.onadvertisement = (ad: any) => {
375
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
376
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
377
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'r') {
378
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
379
+ } else {
380
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
381
+ }
382
+ };
383
+ // Wait 1 seconds
384
+ await switchbot.wait(this.scanDuration * 1000);
385
+ // Stop to monitor
386
+ await switchbot.stopScan();
387
+ // Update HomeKit
388
+ await this.BLEparseStatus();
389
+ await this.updateHomeKitCharacteristics();
390
+ })();
391
+ /*if (switchbot !== false) {
368
392
  switchbot
369
393
  .startScan({
370
394
  model: 'r',
@@ -379,11 +403,11 @@ export class StripLight {
379
403
  );
380
404
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
381
405
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
382
- /*this.debugLog(
406
+ this.debugLog(
383
407
  `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
384
408
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
385
409
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
386
- );*/
410
+ );
387
411
 
388
412
  if (ad.serviceData) {
389
413
  this.BLE_IsConnected = true;
@@ -411,7 +435,7 @@ export class StripLight {
411
435
  });
412
436
  } else {
413
437
  await this.BLERefreshConnection(switchbot);
414
- }
438
+ }*/
415
439
  }
416
440
 
417
441
  async openAPIRefreshStatus(): Promise<void> {
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform.js';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
6
  import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
7
- import { device, devicesConfig, deviceStatus, ad, Devices, serviceData, SwitchBotPlatformConfig } from '../settings.js';
7
+ import { device, devicesConfig, deviceStatus, Devices, serviceData, SwitchBotPlatformConfig } from '../settings.js';
8
8
 
9
9
  export class Lock {
10
10
  public readonly api: API;
@@ -384,7 +384,35 @@ export class Lock {
384
384
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
385
385
  this.getCustomBLEAddress(switchbot);
386
386
  // Start to monitor advertisement packets
387
- if (switchbot !== false) {
387
+ (async () => {
388
+ // Start to monitor advertisement packets
389
+ await switchbot.startScan({
390
+ model: 'o',
391
+ id: this.device.bleMac,
392
+ });
393
+ // Set an event handler
394
+ switchbot.onadvertisement = (ad: any) => {
395
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
396
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
397
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'o') {
398
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
399
+ this.BLE_BatteryLevel = ad.serviceData.battery;
400
+ this.BLE_Calibration = ad.serviceData.calibration;
401
+ this.BLE_LockCurrentState = ad.serviceData.status;
402
+ this.BLE_ContactSensorState = ad.serviceData.door_open;
403
+ } else {
404
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
405
+ }
406
+ };
407
+ // Wait 1 seconds
408
+ await switchbot.wait(this.scanDuration * 1000);
409
+ // Stop to monitor
410
+ await switchbot.stopScan();
411
+ // Update HomeKit
412
+ await this.BLEparseStatus();
413
+ await this.updateHomeKitCharacteristics();
414
+ })();
415
+ /*if (switchbot !== false) {
388
416
  switchbot
389
417
  .startScan({
390
418
  model: 'o',
@@ -434,7 +462,7 @@ export class Lock {
434
462
  });
435
463
  } else {
436
464
  await this.BLERefreshConnection(switchbot);
437
- }
465
+ }*/
438
466
  }
439
467
 
440
468
  async openAPIRefreshStatus(): Promise<void> {
@@ -5,7 +5,7 @@ import { hostname } from 'os';
5
5
  import { interval } from 'rxjs';
6
6
  import { request } from 'undici';
7
7
  import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings.js';
8
+ import { Devices, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings.js';
9
9
  import { sleep } from '../utils.js';
10
10
 
11
11
  export class Meter {
@@ -310,7 +310,35 @@ export class Meter {
310
310
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
311
311
  this.getCustomBLEAddress(switchbot);
312
312
  // Start to monitor advertisement packets
313
- if (switchbot !== false) {
313
+ (async () => {
314
+ await switchbot.startScan({
315
+ model: 'T',
316
+ id: this.device.bleMac,
317
+ });
318
+ // Set an event handler
319
+ switchbot.onadvertisement = (ad: any) => {
320
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
321
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
322
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'T') {
323
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
324
+ this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity < 0 ? 0 : ad.serviceData.humidity > 100 ? 100 : ad.serviceData.humidity;
325
+ this.BLE_CurrentTemperature = ad.serviceData.temperature;
326
+ this.BLE_Celsius = ad.serviceData.temperature!.c;
327
+ this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
328
+ this.BLE_BatteryLevel = ad.serviceData.battery;
329
+ } else {
330
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
331
+ }
332
+ };
333
+ // Wait 1 seconds
334
+ await switchbot.wait(this.scanDuration * 1000);
335
+ // Stop to monitor
336
+ await switchbot.stopScan();
337
+ // Update HomeKit
338
+ await this.BLEparseStatus();
339
+ await this.updateHomeKitCharacteristics();
340
+ })();
341
+ /*if (switchbot !== false) {
314
342
  switchbot
315
343
  .startScan({
316
344
  model: 'T',
@@ -364,7 +392,7 @@ export class Meter {
364
392
  });
365
393
  } else {
366
394
  await this.BLERefreshConnection(switchbot);
367
- }
395
+ }*/
368
396
  }
369
397
 
370
398
  async openAPIRefreshStatus(): Promise<void> {
@@ -5,7 +5,7 @@ import { hostname } from 'os';
5
5
  import { interval } from 'rxjs';
6
6
  import { request } from 'undici';
7
7
  import { SwitchBotPlatform } from '../platform.js';
8
- import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings.js';
8
+ import { Devices, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings.js';
9
9
  import { sleep } from '../utils.js';
10
10
 
11
11
  /**
@@ -312,7 +312,35 @@ export class MeterPlus {
312
312
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
313
313
  this.getCustomBLEAddress(switchbot);
314
314
  // Start to monitor advertisement packets
315
- if (switchbot !== false) {
315
+ (async () => {
316
+ await switchbot.startScan({
317
+ model: 'i',
318
+ id: this.device.bleMac,
319
+ });
320
+ // Set an event handler
321
+ switchbot.onadvertisement = (ad: any) => {
322
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
323
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
324
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 'i') {
325
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
326
+ this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity < 0 ? 0 : ad.serviceData.humidity > 100 ? 100 : ad.serviceData.humidity;
327
+ this.BLE_CurrentTemperature = ad.serviceData.temperature;
328
+ this.BLE_Celsius = ad.serviceData.temperature!.c;
329
+ this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
330
+ this.BLE_BatteryLevel = ad.serviceData.battery;
331
+ } else {
332
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
333
+ }
334
+ };
335
+ // Wait 1 seconds
336
+ await switchbot.wait(this.scanDuration * 1000);
337
+ // Stop to monitor
338
+ await switchbot.stopScan();
339
+ // Update HomeKit
340
+ await this.BLEparseStatus();
341
+ await this.updateHomeKitCharacteristics();
342
+ })();
343
+ /*if (switchbot !== false) {
316
344
  switchbot
317
345
  .startScan({
318
346
  model: 'i',
@@ -366,7 +394,7 @@ export class MeterPlus {
366
394
  });
367
395
  } else {
368
396
  await this.BLERefreshConnection(switchbot);
369
- }
397
+ }*/
370
398
  }
371
399
 
372
400
  async openAPIRefreshStatus(): Promise<void> {