@switchbot/homebridge-switchbot 3.3.0-beta.2 → 3.3.0-beta.4

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 (67) 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/package.json +2 -2
  52. package/src/device/blindtilt.ts +32 -3
  53. package/src/device/bot.ts +30 -3
  54. package/src/device/ceilinglight.ts +35 -5
  55. package/src/device/colorbulb.ts +46 -10
  56. package/src/device/contact.ts +29 -3
  57. package/src/device/curtain.ts +34 -3
  58. package/src/device/hub.ts +6 -2
  59. package/src/device/humidifier.ts +30 -3
  60. package/src/device/iosensor.ts +31 -3
  61. package/src/device/lightstrip.ts +29 -5
  62. package/src/device/lock.ts +31 -3
  63. package/src/device/meter.ts +31 -3
  64. package/src/device/meterplus.ts +31 -3
  65. package/src/device/motion.ts +30 -3
  66. package/src/device/plug.ts +28 -4
  67. package/src/device/robotvacuumcleaner.ts +29 -13
@@ -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> {
@@ -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
@@ -296,7 +296,34 @@ export class Motion {
296
296
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
297
297
  this.getCustomBLEAddress(switchbot);
298
298
  // Start to monitor advertisement packets
299
- if (switchbot !== false) {
299
+ (async () => {
300
+ // Start to monitor advertisement packets
301
+ await switchbot.startScan({
302
+ model: 's',
303
+ id: this.device.bleMac,
304
+ });
305
+ // Set an event handler
306
+ switchbot.onadvertisement = (ad: any) => {
307
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
308
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
309
+ if (this.device.bleMac === ad.address && ad.serviceData.model === 's') {
310
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
311
+ this.BLE_MotionDetected = ad.serviceData.movement;
312
+ this.BLE_BatteryLevel = ad.serviceData.battery;
313
+ this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
314
+ } else {
315
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
316
+ }
317
+ };
318
+ // Wait 1 seconds
319
+ await switchbot.wait(this.scanDuration * 1000);
320
+ // Stop to monitor
321
+ await switchbot.stopScan();
322
+ // Update HomeKit
323
+ await this.BLEparseStatus();
324
+ await this.updateHomeKitCharacteristics();
325
+ })();
326
+ /*if (switchbot !== false) {
300
327
  await switchbot
301
328
  .startScan({
302
329
  model: 's',
@@ -359,7 +386,7 @@ export class Motion {
359
386
  } else {
360
387
  this.debugErrorLog('4');
361
388
  await this.BLERefreshConnection(switchbot);
362
- }
389
+ }*/
363
390
  }
364
391
 
365
392
  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, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
+ import { device, devicesConfig, deviceStatus, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
8
8
 
9
9
  export class Plug {
10
10
  public readonly api: API;
@@ -220,7 +220,31 @@ export class Plug {
220
220
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
221
221
  this.getCustomBLEAddress(switchbot);
222
222
  // Start to monitor advertisement packets
223
- if (switchbot !== false) {
223
+ (async () => {
224
+ await switchbot.startScan({
225
+ model: this.BLEmodel(),
226
+ id: this.device.bleMac,
227
+ });
228
+ // Set an event handler
229
+ switchbot.onadvertisement = (ad: any) => {
230
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
231
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
232
+ if (this.device.bleMac === ad.address && ad.serviceData.model === this.BLEmodel()) {
233
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
234
+ this.BLE_On = ad.serviceData.state;
235
+ } else {
236
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
237
+ }
238
+ };
239
+ // Wait 1 seconds
240
+ await switchbot.wait(this.scanDuration * 1000);
241
+ // Stop to monitor
242
+ await switchbot.stopScan();
243
+ // Update HomeKit
244
+ await this.BLEparseStatus();
245
+ await this.updateHomeKitCharacteristics();
246
+ })();
247
+ /*if (switchbot !== false) {
224
248
  switchbot
225
249
  .startScan({
226
250
  model: this.BLEmodel(),
@@ -267,7 +291,7 @@ export class Plug {
267
291
  });
268
292
  } else {
269
293
  await this.BLERefreshConnection(switchbot);
270
- }
294
+ }*/
271
295
  }
272
296
 
273
297
  async openAPIRefreshStatus() {
@@ -464,7 +488,7 @@ export class Plug {
464
488
  }
465
489
 
466
490
  BLEmodel(): 'g' | 'j' {
467
- if (this.device.deviceType === 'Plug Mini (US)') {
491
+ if (this.device.deviceType === 'Plug Mini (US)' || this.device.configDeviceType === 'Plug Mini (US)') {
468
492
  return 'g';
469
493
  } else {
470
494
  return 'j';
@@ -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, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
7
+ import { device, devicesConfig, deviceStatus, serviceData, Devices, SwitchBotPlatformConfig } from '../settings.js';
8
8
 
9
9
  export class RobotVacuumCleaner {
10
10
  public readonly api: API;
@@ -267,7 +267,31 @@ export class RobotVacuumCleaner {
267
267
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
268
268
  this.getCustomBLEAddress(switchbot);
269
269
  // Start to monitor advertisement packets
270
- if (switchbot !== false) {
270
+ (async () => {
271
+ await switchbot.startScan({
272
+ model: '?',
273
+ id: this.device.bleMac,
274
+ });
275
+ // Set an event handler
276
+ switchbot.onadvertisement = (ad: any) => {
277
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
278
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
279
+ if (this.device.bleMac === ad.address && ad.serviceData.model === '?') {
280
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
281
+ this.BLE_On = ad.serviceData.state;
282
+ } else {
283
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
284
+ }
285
+ };
286
+ // Wait 1 seconds
287
+ await switchbot.wait(this.scanDuration * 1000);
288
+ // Stop to monitor
289
+ await switchbot.stopScan();
290
+ // Update HomeKit
291
+ await this.BLEparseStatus();
292
+ await this.updateHomeKitCharacteristics();
293
+ })();
294
+ /*if (switchbot !== false) {
271
295
  switchbot
272
296
  .startScan({
273
297
  model: this.BLEmodel(),
@@ -314,7 +338,7 @@ export class RobotVacuumCleaner {
314
338
  });
315
339
  } else {
316
340
  await this.BLERefreshConnection(switchbot);
317
- }
341
+ }*/
318
342
  }
319
343
 
320
344
  async openAPIRefreshStatus() {
@@ -392,7 +416,7 @@ export class RobotVacuumCleaner {
392
416
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
393
417
  switchbot
394
418
  .discover({
395
- model: this.BLEmodel(),
419
+ model: '?',
396
420
  id: this.device.bleMac,
397
421
  })
398
422
  .then(async (device_list: any) => {
@@ -625,20 +649,12 @@ export class RobotVacuumCleaner {
625
649
  }
626
650
  }
627
651
 
628
- BLEmodel(): 'g' | 'j' {
629
- if (this.device.deviceType === 'Plug Mini (US)') {
630
- return 'g';
631
- } else {
632
- return 'j';
633
- }
634
- }
635
-
636
652
  async getCustomBLEAddress(switchbot: any) {
637
653
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
638
654
  (async () => {
639
655
  // Start to monitor advertisement packets
640
656
  await switchbot.startScan({
641
- model: this.BLEmodel(),
657
+ model: '?',
642
658
  });
643
659
  // Set an event handler
644
660
  switchbot.onadvertisement = (ad: any) => {