@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
@@ -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.model}`);
309
+ if (this.device.bleMac === ad.address && ad.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) => {
package/src/platform.ts CHANGED
@@ -2556,14 +2556,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2556
2556
 
2557
2557
  // BLE Connection
2558
2558
  async connectBLE() {
2559
- let noble: any;
2560
- let SwitchBot: any;
2561
2559
  let switchbot: any;
2562
2560
  try {
2563
- noble = (await import('@abandonware/noble')).default;
2564
- SwitchBot = (await import('node-switchbot')).default;
2565
- //SwitchBot = (await import('/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/switchbot.js')).default;
2566
- queueScheduler.schedule(() => (switchbot = new SwitchBot({ 'noble': noble })));
2561
+ const SwitchBot = (await import('node-switchbot')).SwitchBot;
2562
+ queueScheduler.schedule(() => (switchbot = new SwitchBot()));
2567
2563
  } catch (e: any) {
2568
2564
  switchbot = false;
2569
2565
  this.errorLog(`Was 'node-switchbot' found: ${switchbot}, Error: ${e}`);