@switchbot/homebridge-switchbot 2.0.0-beta.22 → 2.0.0-beta.24

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 (66) hide show
  1. package/config.schema.json +25 -1
  2. package/dist/device/bot.d.ts +2 -1
  3. package/dist/device/bot.d.ts.map +1 -1
  4. package/dist/device/bot.js +11 -5
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts +2 -1
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +13 -10
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts +1 -1
  11. package/dist/device/contact.d.ts.map +1 -1
  12. package/dist/device/contact.js +5 -5
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.d.ts +2 -1
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +13 -13
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/humidifier.d.ts +2 -1
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +12 -9
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +2 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +14 -4
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +1 -1
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +5 -5
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +1 -1
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +5 -5
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +1 -1
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +5 -5
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +2 -1
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +12 -9
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +2 -1
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +12 -9
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/platform.d.ts +6 -2
  47. package/dist/platform.d.ts.map +1 -1
  48. package/dist/platform.js +136 -111
  49. package/dist/platform.js.map +1 -1
  50. package/dist/settings.d.ts +2 -0
  51. package/dist/settings.d.ts.map +1 -1
  52. package/dist/settings.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/device/bot.ts +12 -5
  55. package/src/device/colorbulb.ts +14 -10
  56. package/src/device/contact.ts +5 -5
  57. package/src/device/curtain.ts +14 -13
  58. package/src/device/humidifier.ts +13 -9
  59. package/src/device/lock.ts +16 -4
  60. package/src/device/meter.ts +5 -5
  61. package/src/device/meterplus.ts +5 -5
  62. package/src/device/motion.ts +5 -5
  63. package/src/device/plug.ts +13 -9
  64. package/src/device/striplight.ts +13 -9
  65. package/src/platform.ts +143 -117
  66. package/src/settings.ts +2 -0
@@ -329,17 +329,17 @@ export class Contact {
329
329
  this.BLEparseStatus();
330
330
  this.updateHomeKitCharacteristics();
331
331
  } else {
332
- await this.BLEconnection(switchbot);
332
+ await this.BLERefreshConnection(switchbot);
333
333
  }
334
334
  })
335
335
  .catch(async (e: any) => {
336
336
  this.apiError(e);
337
337
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
338
338
  + ` Connection, Error Message: ${superStringify(e.message)}`);
339
- await this.BLEconnection(switchbot);
339
+ await this.BLERefreshConnection(switchbot);
340
340
  });
341
341
  } else {
342
- await this.BLEconnection(switchbot);
342
+ await this.BLERefreshConnection(switchbot);
343
343
  }
344
344
  }
345
345
 
@@ -464,10 +464,10 @@ export class Contact {
464
464
  }
465
465
  }
466
466
 
467
- async BLEconnection(switchbot: any): Promise<void> {
467
+ async BLERefreshConnection(switchbot: any): Promise<void> {
468
468
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
469
469
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
470
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
470
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
471
471
  await this.openAPIRefreshStatus();
472
472
  }
473
473
  }
@@ -452,17 +452,17 @@ export class Curtain {
452
452
  this.BLEparseStatus();
453
453
  this.updateHomeKitCharacteristics();
454
454
  } else {
455
- await this.BLEconnection(switchbot);
455
+ await this.BLERefreshConnection(switchbot);
456
456
  }
457
457
  })
458
458
  .catch(async (e: any) => {
459
459
  this.apiError(e);
460
460
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
461
461
  + ` Connection, Error Message: ${superStringify(e.message)}`);
462
- await this.BLEconnection(switchbot);
462
+ await this.BLERefreshConnection(switchbot);
463
463
  });
464
464
  } else {
465
- await this.BLEconnection(switchbot);
465
+ await this.BLERefreshConnection(switchbot);
466
466
  }
467
467
  }
468
468
 
@@ -566,17 +566,11 @@ export class Curtain {
566
566
  this.apiError(e);
567
567
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
568
568
  + ` Connection, Error Message: ${superStringify(e.message)}`);
569
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
570
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
571
- await this.openAPIpushChanges();
572
- }
569
+ await this.BLEPushConnection();
573
570
  });
574
571
  } else {
575
572
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
576
- if (this.platform.config.credentials?.token) {
577
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
578
- await this.openAPIpushChanges();
579
- }
573
+ await this.BLEPushConnection();
580
574
  }
581
575
  } else {
582
576
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
@@ -808,10 +802,17 @@ export class Curtain {
808
802
  }
809
803
  }
810
804
 
811
- async BLEconnection(switchbot: any): Promise<void> {
805
+ async BLEPushConnection() {
806
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
807
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
808
+ await this.openAPIpushChanges();
809
+ }
810
+ }
811
+
812
+ async BLERefreshConnection(switchbot: any): Promise<void> {
812
813
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
813
814
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
814
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
815
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
815
816
  await this.openAPIRefreshStatus();
816
817
  }
817
818
  }
@@ -344,17 +344,17 @@ export class Humidifier {
344
344
  this.BLEparseStatus();
345
345
  this.updateHomeKitCharacteristics();
346
346
  } else {
347
- await this.BLEconnection(switchbot);
347
+ await this.BLERefreshConnection(switchbot);
348
348
  }
349
349
  })
350
350
  .catch(async (e: any) => {
351
351
  this.apiError(e);
352
352
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
353
353
  + ` Connection, Error Message: ${superStringify(e.message)}`);
354
- await this.BLEconnection(switchbot);
354
+ await this.BLERefreshConnection(switchbot);
355
355
  });
356
356
  } else {
357
- await this.BLEconnection(switchbot);
357
+ await this.BLERefreshConnection(switchbot);
358
358
  }
359
359
  }
360
360
 
@@ -460,10 +460,7 @@ export class Humidifier {
460
460
  this.apiError(e);
461
461
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
462
462
  + ` Connection, Error Message: ${superStringify(e.message)}`);
463
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
464
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
465
- await this.openAPIpushChanges();
466
- }
463
+ await this.BLEPushConnection();
467
464
  });
468
465
  }
469
466
 
@@ -775,10 +772,17 @@ export class Humidifier {
775
772
  }
776
773
  }
777
774
 
778
- async BLEconnection(switchbot: any): Promise<void> {
775
+ async BLEPushConnection() {
776
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
777
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
778
+ await this.openAPIpushChanges();
779
+ }
780
+ }
781
+
782
+ async BLERefreshConnection(switchbot: any): Promise<void> {
779
783
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
780
784
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
781
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
785
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
782
786
  await this.openAPIRefreshStatus();
783
787
  }
784
788
  }
@@ -300,10 +300,7 @@ export class Lock {
300
300
  this.apiError(e);
301
301
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
302
302
  + ` Connection, Error Message: ${superStringify(e.message)}`);
303
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
304
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
305
- await this.openAPIpushChanges();
306
- }
303
+ await this.BLEPushConnection();
307
304
  });
308
305
  } else {
309
306
  this.debugLog(
@@ -415,6 +412,21 @@ export class Lock {
415
412
  }
416
413
  }
417
414
 
415
+ async BLEPushConnection() {
416
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
417
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
418
+ await this.openAPIpushChanges();
419
+ }
420
+ }
421
+
422
+ async BLERefreshConnection(switchbot: any): Promise<void> {
423
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
424
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
425
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
426
+ await this.openAPIRefreshStatus();
427
+ }
428
+ }
429
+
418
430
  async scan(device: device & devicesConfig): Promise<void> {
419
431
  if (device.scanDuration) {
420
432
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
@@ -300,17 +300,17 @@ export class Meter {
300
300
  this.BLEparseStatus();
301
301
  this.updateHomeKitCharacteristics();
302
302
  } else {
303
- await this.BLEconnection(switchbot);
303
+ await this.BLERefreshConnection(switchbot);
304
304
  }
305
305
  })
306
306
  .catch(async (e: any) => {
307
307
  this.apiError(e);
308
308
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
309
309
  + ` Connection, Error Message: ${superStringify(e.message)}`);
310
- await this.BLEconnection(switchbot);
310
+ await this.BLERefreshConnection(switchbot);
311
311
  });
312
312
  } else {
313
- await this.BLEconnection(switchbot);
313
+ await this.BLERefreshConnection(switchbot);
314
314
  }
315
315
  }
316
316
 
@@ -489,10 +489,10 @@ export class Meter {
489
489
  }
490
490
  }
491
491
 
492
- async BLEconnection(switchbot: any): Promise<void> {
492
+ async BLERefreshConnection(switchbot: any): Promise<void> {
493
493
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
494
494
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
495
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
495
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
496
496
  await this.openAPIRefreshStatus();
497
497
  }
498
498
  }
@@ -300,17 +300,17 @@ export class MeterPlus {
300
300
  this.parseStatus();
301
301
  this.updateHomeKitCharacteristics();
302
302
  } else {
303
- await this.BLEconnection(switchbot);
303
+ await this.BLERefreshConnection(switchbot);
304
304
  }
305
305
  })
306
306
  .catch(async (e: any) => {
307
307
  this.apiError(e);
308
308
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
309
309
  + ` Connection, Error Message: ${superStringify(e.message)}`);
310
- await this.BLEconnection(switchbot);
310
+ await this.BLERefreshConnection(switchbot);
311
311
  });
312
312
  } else {
313
- await this.BLEconnection(switchbot);
313
+ await this.BLERefreshConnection(switchbot);
314
314
  }
315
315
  }
316
316
 
@@ -488,10 +488,10 @@ export class MeterPlus {
488
488
  }
489
489
  }
490
490
 
491
- async BLEconnection(switchbot: any): Promise<void> {
491
+ async BLERefreshConnection(switchbot: any): Promise<void> {
492
492
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
493
493
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
494
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
494
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
495
495
  await this.openAPIRefreshStatus();
496
496
  }
497
497
  }
@@ -280,17 +280,17 @@ export class Motion {
280
280
  this.BLEparseStatus();
281
281
  this.updateHomeKitCharacteristics();
282
282
  } else {
283
- await this.BLEconnection(switchbot);
283
+ await this.BLERefreshConnection(switchbot);
284
284
  }
285
285
  })
286
286
  .catch(async (e: any) => {
287
287
  this.apiError(e);
288
288
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
289
289
  + ` Connection, Error Message: ${superStringify(e.message)}`);
290
- await this.BLEconnection(switchbot);
290
+ await this.BLERefreshConnection(switchbot);
291
291
  });
292
292
  } else {
293
- await this.BLEconnection(switchbot);
293
+ await this.BLERefreshConnection(switchbot);
294
294
  }
295
295
  }
296
296
 
@@ -405,10 +405,10 @@ export class Motion {
405
405
  }
406
406
  }
407
407
 
408
- async BLEconnection(switchbot: any): Promise<void> {
408
+ async BLERefreshConnection(switchbot: any): Promise<void> {
409
409
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
410
410
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
411
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
411
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
412
412
  await this.openAPIRefreshStatus();
413
413
  }
414
414
  }
@@ -234,17 +234,17 @@ export class Plug {
234
234
  this.BLEparseStatus();
235
235
  this.updateHomeKitCharacteristics();
236
236
  } else {
237
- await this.BLEconnection(switchbot);
237
+ await this.BLERefreshConnection(switchbot);
238
238
  }
239
239
  })
240
240
  .catch(async (e: any) => {
241
241
  this.apiError(e);
242
242
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
243
243
  + ` Connection, Error Message: ${superStringify(e.message)}`);
244
- await this.BLEconnection(switchbot);
244
+ await this.BLERefreshConnection(switchbot);
245
245
  });
246
246
  } else {
247
- await this.BLEconnection(switchbot);
247
+ await this.BLERefreshConnection(switchbot);
248
248
  }
249
249
  }
250
250
 
@@ -355,10 +355,7 @@ export class Plug {
355
355
  this.apiError(e);
356
356
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
357
357
  + ` Connection, Error Message: ${superStringify(e.message)}`);
358
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
359
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
360
- await this.openAPIpushChanges();
361
- }
358
+ await this.BLEPushConnection();
362
359
  });
363
360
  } else {
364
361
  this.debugLog(
@@ -481,10 +478,17 @@ export class Plug {
481
478
  }
482
479
  }
483
480
 
484
- async BLEconnection(switchbot: any): Promise<void> {
481
+ async BLEPushConnection() {
482
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
483
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
484
+ await this.openAPIpushChanges();
485
+ }
486
+ }
487
+
488
+ async BLERefreshConnection(switchbot: any): Promise<void> {
485
489
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
486
490
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
487
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
491
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
488
492
  await this.openAPIRefreshStatus();
489
493
  }
490
494
  }
@@ -354,17 +354,17 @@ export class StripLight {
354
354
  this.BLEparseStatus();
355
355
  this.updateHomeKitCharacteristics();
356
356
  } else {
357
- await this.BLEconnection(switchbot);
357
+ await this.BLERefreshConnection(switchbot);
358
358
  }
359
359
  })
360
360
  .catch(async (e: any) => {
361
361
  this.apiError(e);
362
362
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
363
363
  + ` Connection, Error Message: ${superStringify(e.message)}`);
364
- await this.BLEconnection(switchbot);
364
+ await this.BLERefreshConnection(switchbot);
365
365
  });
366
366
  } else {
367
- await this.BLEconnection(switchbot);
367
+ await this.BLERefreshConnection(switchbot);
368
368
  }
369
369
  }
370
370
 
@@ -477,10 +477,7 @@ export class StripLight {
477
477
  this.apiError(e);
478
478
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
479
479
  + ` Connection, Error Message: ${superStringify(e.message)}`);
480
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
481
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
482
- await this.openAPIpushChanges();
483
- }
480
+ await this.BLEPushConnection();
484
481
  });
485
482
  } else {
486
483
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
@@ -808,10 +805,17 @@ export class StripLight {
808
805
  }
809
806
  }
810
807
 
811
- async BLEconnection(switchbot: any): Promise<void> {
808
+ async BLEPushConnection() {
809
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
810
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
811
+ await this.openAPIpushChanges();
812
+ }
813
+ }
814
+
815
+ async BLERefreshConnection(switchbot: any): Promise<void> {
812
816
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
813
817
  if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
814
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
818
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
815
819
  await this.openAPIRefreshStatus();
816
820
  }
817
821
  }