@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10

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 (139) hide show
  1. package/.prettierrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +10 -0
  4. package/config.schema.json +8 -0
  5. package/dist/device/blindtilt.d.ts +1 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +58 -65
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +1 -0
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +52 -55
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +1 -0
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +68 -68
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +1 -0
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +76 -75
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +2 -0
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +67 -59
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +2 -0
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +81 -94
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/hub.d.ts +9 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +197 -30
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +58 -62
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts +1 -0
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +28 -26
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/lightstrip.d.ts +1 -0
  41. package/dist/device/lightstrip.d.ts.map +1 -1
  42. package/dist/device/lightstrip.js +68 -67
  43. package/dist/device/lightstrip.js.map +1 -1
  44. package/dist/device/lock.d.ts +2 -0
  45. package/dist/device/lock.d.ts.map +1 -1
  46. package/dist/device/lock.js +51 -47
  47. package/dist/device/lock.js.map +1 -1
  48. package/dist/device/meter.d.ts +5 -3
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +75 -74
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts +4 -3
  53. package/dist/device/meterplus.d.ts.map +1 -1
  54. package/dist/device/meterplus.js +74 -74
  55. package/dist/device/meterplus.js.map +1 -1
  56. package/dist/device/motion.d.ts +2 -0
  57. package/dist/device/motion.d.ts.map +1 -1
  58. package/dist/device/motion.js +66 -54
  59. package/dist/device/motion.js.map +1 -1
  60. package/dist/device/plug.d.ts +1 -0
  61. package/dist/device/plug.d.ts.map +1 -1
  62. package/dist/device/plug.js +39 -39
  63. package/dist/device/plug.js.map +1 -1
  64. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  65. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  66. package/dist/device/robotvacuumcleaner.js +74 -53
  67. package/dist/device/robotvacuumcleaner.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  69. package/dist/irdevice/airconditioner.js +64 -66
  70. package/dist/irdevice/airconditioner.js.map +1 -1
  71. package/dist/irdevice/airpurifier.d.ts +1 -1
  72. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  73. package/dist/irdevice/airpurifier.js +32 -34
  74. package/dist/irdevice/airpurifier.js.map +1 -1
  75. package/dist/irdevice/camera.d.ts +1 -1
  76. package/dist/irdevice/camera.d.ts.map +1 -1
  77. package/dist/irdevice/camera.js +20 -23
  78. package/dist/irdevice/camera.js.map +1 -1
  79. package/dist/irdevice/fan.d.ts +2 -2
  80. package/dist/irdevice/fan.d.ts.map +1 -1
  81. package/dist/irdevice/fan.js +30 -32
  82. package/dist/irdevice/fan.js.map +1 -1
  83. package/dist/irdevice/light.d.ts +1 -1
  84. package/dist/irdevice/light.d.ts.map +1 -1
  85. package/dist/irdevice/light.js +26 -29
  86. package/dist/irdevice/light.js.map +1 -1
  87. package/dist/irdevice/other.d.ts +1 -1
  88. package/dist/irdevice/other.d.ts.map +1 -1
  89. package/dist/irdevice/other.js +22 -23
  90. package/dist/irdevice/other.js.map +1 -1
  91. package/dist/irdevice/tv.d.ts +2 -2
  92. package/dist/irdevice/tv.d.ts.map +1 -1
  93. package/dist/irdevice/tv.js +47 -50
  94. package/dist/irdevice/tv.js.map +1 -1
  95. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  96. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  97. package/dist/irdevice/vacuumcleaner.js +20 -23
  98. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  99. package/dist/irdevice/waterheater.d.ts +1 -1
  100. package/dist/irdevice/waterheater.d.ts.map +1 -1
  101. package/dist/irdevice/waterheater.js +22 -23
  102. package/dist/irdevice/waterheater.js.map +1 -1
  103. package/dist/platform.d.ts.map +1 -1
  104. package/dist/platform.js +46 -44
  105. package/dist/platform.js.map +1 -1
  106. package/dist/settings.d.ts +1 -0
  107. package/dist/settings.d.ts.map +1 -1
  108. package/dist/settings.js.map +1 -1
  109. package/dist/utils.js +1 -1
  110. package/dist/utils.js.map +1 -1
  111. package/package.json +3 -3
  112. package/src/device/blindtilt.ts +114 -78
  113. package/src/device/bot.ts +102 -63
  114. package/src/device/ceilinglight.ts +113 -73
  115. package/src/device/colorbulb.ts +144 -87
  116. package/src/device/contact.ts +98 -63
  117. package/src/device/curtain.ts +160 -134
  118. package/src/device/hub.ts +228 -39
  119. package/src/device/humidifier.ts +136 -85
  120. package/src/device/iosensor.ts +52 -32
  121. package/src/device/lightstrip.ts +118 -72
  122. package/src/device/lock.ts +85 -50
  123. package/src/device/meter.ts +104 -80
  124. package/src/device/meterplus.ts +103 -80
  125. package/src/device/motion.ts +95 -59
  126. package/src/device/plug.ts +70 -44
  127. package/src/device/robotvacuumcleaner.ts +107 -56
  128. package/src/irdevice/airconditioner.ts +116 -86
  129. package/src/irdevice/airpurifier.ts +60 -39
  130. package/src/irdevice/camera.ts +40 -28
  131. package/src/irdevice/fan.ts +52 -38
  132. package/src/irdevice/light.ts +48 -34
  133. package/src/irdevice/other.ts +44 -28
  134. package/src/irdevice/tv.ts +70 -56
  135. package/src/irdevice/vacuumcleaner.ts +40 -28
  136. package/src/irdevice/waterheater.ts +48 -32
  137. package/src/platform.ts +87 -56
  138. package/src/settings.ts +41 -40
  139. package/src/utils.ts +1 -1
@@ -1,3 +1,4 @@
1
+ /* eslint-disable brace-style */
1
2
  import { Context } from 'vm';
2
3
  import { request } from 'undici';
3
4
  import { sleep } from '../utils';
@@ -24,6 +25,7 @@ export class ColorBulb {
24
25
  ColorTemperature?: CharacteristicValue;
25
26
 
26
27
  // OpenAPI Others
28
+ Version: deviceStatus['version'];
27
29
  power: deviceStatus['power'];
28
30
  color: deviceStatus['color'];
29
31
  brightness: deviceStatus['brightness'];
@@ -44,10 +46,10 @@ export class ColorBulb {
44
46
  wifiRssi: serviceData['wifiRssi'];
45
47
  brightnessBLE: serviceData['brightness'];
46
48
  color_temperature: serviceData['color_temperature'];
47
- preset: any;//serviceData['preset'];
48
- color_mode: any;//serviceData['color_mode'];
49
- speed: any;//serviceData['speed'];
50
- loop_index: any;//serviceData['loop_index'];
49
+ preset: any; //serviceData['preset'];
50
+ color_mode: any; //serviceData['color_mode'];
51
+ speed: any; //serviceData['speed'];
52
+ loop_index: any; //serviceData['loop_index'];
51
53
 
52
54
  // Config
53
55
  set_minStep?: number;
@@ -69,17 +71,22 @@ export class ColorBulb {
69
71
  doColorBulbUpdate!: Subject<void>;
70
72
 
71
73
  // Connection
72
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
73
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
74
-
75
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
74
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
75
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
76
+
77
+ constructor(
78
+ private readonly platform: SwitchBotPlatform,
79
+ private accessory: PlatformAccessory,
80
+ public device: device & devicesConfig,
81
+ ) {
76
82
  // default placeholders
77
83
  this.logs(device);
78
84
  this.scan(device);
79
85
  this.refreshRate(device);
80
86
  this.adaptiveLighting(device);
81
- this.config(device);
82
87
  this.context();
88
+ this.config(device);
89
+
83
90
  // this is subject we use to track when we need to POST changes to the SwitchBot API
84
91
  this.doColorBulbUpdate = new Subject();
85
92
  this.colorBulbUpdateInProgress = false;
@@ -213,8 +220,10 @@ export class ColorBulb {
213
220
  await this.pushChanges();
214
221
  } catch (e: any) {
215
222
  this.apiError(e);
216
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
217
- + ` Error Message: ${JSON.stringify(e.message)}`);
223
+ this.errorLog(
224
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
225
+ ` Error Message: ${JSON.stringify(e.message)}`,
226
+ );
218
227
  }
219
228
  this.colorBulbUpdateInProgress = false;
220
229
  });
@@ -232,8 +241,9 @@ export class ColorBulb {
232
241
  await this.openAPIparseStatus();
233
242
  } else {
234
243
  await this.offlineOff();
235
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
236
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
244
+ this.debugWarnLog(
245
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
246
+ );
237
247
  }
238
248
  }
239
249
 
@@ -249,7 +259,6 @@ export class ColorBulb {
249
259
  }
250
260
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
251
261
 
252
-
253
262
  // Brightness
254
263
  this.Brightness = Number(this.brightnessBLE);
255
264
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
@@ -260,8 +269,10 @@ export class ColorBulb {
260
269
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.blue}`);
261
270
 
262
271
  const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
263
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
264
- + ` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`);
272
+ this.debugLog(
273
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
274
+ ` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`,
275
+ );
265
276
 
266
277
  // Hue
267
278
  this.Hue = hue;
@@ -305,8 +316,9 @@ export class ColorBulb {
305
316
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
306
317
 
307
318
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
308
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
309
- + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
319
+ this.debugLog(
320
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
321
+ );
310
322
 
311
323
  // Hue
312
324
  this.Hue = hue;
@@ -341,8 +353,10 @@ export class ColorBulb {
341
353
  await this.openAPIRefreshStatus();
342
354
  } else {
343
355
  await this.offlineOff();
344
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
345
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
356
+ this.debugWarnLog(
357
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
358
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
359
+ );
346
360
  }
347
361
  }
348
362
 
@@ -367,8 +381,10 @@ export class ColorBulb {
367
381
  // Set an event hander
368
382
  switchbot.onadvertisement = async (ad: any) => {
369
383
  this.address = ad.address;
370
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
371
- + ` BLE Address Found: ${this.address}`);
384
+ this.debugLog(
385
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
386
+ ` BLE Address Found: ${this.address}`,
387
+ );
372
388
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
373
389
  this.serviceData = ad.serviceData;
374
390
  this.powerState = ad.serviceData.power;
@@ -408,8 +424,10 @@ export class ColorBulb {
408
424
  })
409
425
  .catch(async (e: any) => {
410
426
  this.apiError(e);
411
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
412
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
427
+ this.errorLog(
428
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
429
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
430
+ );
413
431
  await this.BLERefreshConnection(switchbot);
414
432
  });
415
433
  } else {
@@ -436,8 +454,10 @@ export class ColorBulb {
436
454
  this.updateHomeKitCharacteristics();
437
455
  } catch (e: any) {
438
456
  this.apiError(e);
439
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
440
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
457
+ this.errorLog(
458
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
459
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
460
+ );
441
461
  }
442
462
  }
443
463
 
@@ -455,14 +475,15 @@ export class ColorBulb {
455
475
  async pushChanges(): Promise<void> {
456
476
  if (!this.device.enableCloudService && this.OpenAPI) {
457
477
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
458
- } else/* if (this.BLE) {
478
+ } /* if (this.BLE) {
459
479
  await this.BLEpushChanges();
460
- } else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
480
+ } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
461
481
  await this.openAPIpushChanges();
462
482
  } else {
463
483
  await this.offlineOff();
464
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
465
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
484
+ this.debugWarnLog(
485
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
486
+ );
466
487
  }
467
488
  // Refresh the status from the API
468
489
  interval(15000)
@@ -508,8 +529,10 @@ export class ColorBulb {
508
529
  })
509
530
  .catch(async (e: any) => {
510
531
  this.apiError(e);
511
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
512
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
532
+ this.errorLog(
533
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
534
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
535
+ );
513
536
  await this.BLEPushConnection();
514
537
  });
515
538
  // Push Brightness Update
@@ -525,8 +548,9 @@ export class ColorBulb {
525
548
  await this.BLEpushRGBChanges();
526
549
  }
527
550
  } else {
528
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
529
- + `OnCached: ${this.accessory.context.On}`);
551
+ this.debugLog(
552
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
553
+ );
530
554
  }
531
555
  }
532
556
 
@@ -555,13 +579,18 @@ export class ColorBulb {
555
579
  })
556
580
  .catch(async (e: any) => {
557
581
  this.apiError(e);
558
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
559
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
582
+ this.errorLog(
583
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}` +
584
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
585
+ );
560
586
  await this.BLEPushConnection();
561
587
  });
562
588
  } else {
563
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
564
- + `BrightnessCached: ${this.accessory.context.Brightness}`);
589
+ this.debugLog(
590
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
591
+ `Brightness: ${this.Brightness}, ` +
592
+ `BrightnessCached: ${this.accessory.context.Brightness}`,
593
+ );
565
594
  }
566
595
  }
567
596
 
@@ -590,14 +619,17 @@ export class ColorBulb {
590
619
  })
591
620
  .catch(async (e: any) => {
592
621
  this.apiError(e);
593
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with `
594
- + `${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
622
+ this.errorLog(
623
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with ` +
624
+ `${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`,
625
+ );
595
626
  await this.BLEPushConnection();
596
627
  });
597
628
  } else {
598
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
599
- `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
600
-
629
+ this.debugLog(
630
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
631
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
632
+ );
601
633
  }
602
634
  }
603
635
 
@@ -623,7 +655,7 @@ export class ColorBulb {
623
655
  id: this.device.bleMac,
624
656
  })
625
657
  .then(async (device_list: any) => {
626
- this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
658
+ this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
627
659
  return await device_list[0].setRGB(this.Brightness, red, green, blue);
628
660
  })
629
661
  .then(() => {
@@ -632,13 +664,17 @@ export class ColorBulb {
632
664
  })
633
665
  .catch(async (e: any) => {
634
666
  this.apiError(e);
635
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
636
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
667
+ this.errorLog(
668
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}` +
669
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
670
+ );
637
671
  await this.BLEPushConnection();
638
672
  });
639
673
  } else {
640
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, `
641
- + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
674
+ this.debugLog(
675
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
676
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
677
+ );
642
678
  }
643
679
  }
644
680
 
@@ -652,9 +688,9 @@ export class ColorBulb {
652
688
  command = 'turnOff';
653
689
  }
654
690
  const bodyChange = JSON.stringify({
655
- 'command': `${command}`,
656
- 'parameter': 'default',
657
- 'commandType': 'command',
691
+ command: `${command}`,
692
+ parameter: 'default',
693
+ commandType: 'command',
658
694
  });
659
695
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
660
696
  try {
@@ -669,13 +705,17 @@ export class ColorBulb {
669
705
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
670
706
  } catch (e: any) {
671
707
  this.apiError(e);
672
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
673
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
708
+ this.errorLog(
709
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
710
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
674
711
  );
675
712
  }
676
713
  } else {
677
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
678
- + `OnCached: ${this.accessory.context.On}`);
714
+ this.debugLog(
715
+ `${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
716
+ `On: ${this.On}, ` +
717
+ `OnCached: ${this.accessory.context.On}`,
718
+ );
679
719
  }
680
720
  // Push Hue & Saturation Update
681
721
  if (this.On) {
@@ -699,9 +739,9 @@ export class ColorBulb {
699
739
  const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
700
740
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
701
741
  const bodyChange = JSON.stringify({
702
- 'command': 'setColor',
703
- 'parameter': `${red}:${green}:${blue}`,
704
- 'commandType': 'command',
742
+ command: 'setColor',
743
+ parameter: `${red}:${green}:${blue}`,
744
+ commandType: 'command',
705
745
  });
706
746
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
707
747
  try {
@@ -716,13 +756,16 @@ export class ColorBulb {
716
756
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
717
757
  } catch (e: any) {
718
758
  this.apiError(e);
719
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
720
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
759
+ this.errorLog(
760
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}` +
761
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
721
762
  );
722
763
  }
723
764
  } else {
724
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
725
- + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
765
+ this.debugLog(
766
+ `${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
767
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
768
+ );
726
769
  }
727
770
  }
728
771
 
@@ -732,9 +775,9 @@ export class ColorBulb {
732
775
  const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
733
776
  this.cacheKelvin = kelvin;
734
777
  const bodyChange = JSON.stringify({
735
- 'command': 'setColorTemperature',
736
- 'parameter': `${kelvin}`,
737
- 'commandType': 'command',
778
+ command: 'setColorTemperature',
779
+ parameter: `${kelvin}`,
780
+ commandType: 'command',
738
781
  });
739
782
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
740
783
  try {
@@ -749,13 +792,16 @@ export class ColorBulb {
749
792
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
750
793
  } catch (e: any) {
751
794
  this.apiError(e);
752
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
753
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
795
+ this.errorLog(
796
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}` +
797
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
754
798
  );
755
799
  }
756
800
  } else {
757
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
758
- `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
801
+ this.debugLog(
802
+ `${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
803
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
804
+ );
759
805
  }
760
806
  }
761
807
 
@@ -763,9 +809,9 @@ export class ColorBulb {
763
809
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
764
810
  if (this.Brightness !== this.accessory.context.Brightness) {
765
811
  const bodyChange = JSON.stringify({
766
- 'command': 'setBrightness',
767
- 'parameter': `${this.Brightness}`,
768
- 'commandType': 'command',
812
+ command: 'setBrightness',
813
+ parameter: `${this.Brightness}`,
814
+ commandType: 'command',
769
815
  });
770
816
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
771
817
  try {
@@ -780,13 +826,17 @@ export class ColorBulb {
780
826
  this.debugLog(`Headers: ${JSON.stringify(headers)}`);
781
827
  } catch (e: any) {
782
828
  this.apiError(e);
783
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
784
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
829
+ this.errorLog(
830
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}` +
831
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
785
832
  );
786
833
  }
787
834
  } else {
788
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
789
- + `BrightnessCached: ${this.accessory.context.Brightness}`);
835
+ this.debugLog(
836
+ `${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` +
837
+ `Brightness: ${this.Brightness}, ` +
838
+ `BrightnessCached: ${this.accessory.context.Brightness}`,
839
+ );
790
840
  }
791
841
  }
792
842
 
@@ -1038,14 +1088,16 @@ export class ColorBulb {
1038
1088
  this.offlineOff();
1039
1089
  break;
1040
1090
  case 171:
1041
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
1042
- + `Hub: ${this.device.hubDeviceId}`);
1091
+ this.errorLog(
1092
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
1093
+ `Hub: ${this.device.hubDeviceId}`,
1094
+ );
1043
1095
  this.offlineOff();
1044
1096
  break;
1045
1097
  case 190:
1046
1098
  this.errorLog(
1047
1099
  `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
1048
- ` Or command format is invalid, statusCode: ${statusCode}`,
1100
+ ` Or command format is invalid, statusCode: ${statusCode}`,
1049
1101
  );
1050
1102
  break;
1051
1103
  case 100:
@@ -1055,8 +1107,10 @@ export class ColorBulb {
1055
1107
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
1056
1108
  break;
1057
1109
  default:
1058
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
1059
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
1110
+ this.infoLog(
1111
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
1112
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
1113
+ );
1060
1114
  }
1061
1115
  }
1062
1116
 
@@ -1077,14 +1131,17 @@ export class ColorBulb {
1077
1131
 
1078
1132
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
1079
1133
  let FirmwareRevision: string;
1080
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
1081
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
1134
+ this.debugLog(
1135
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
1136
+ );
1082
1137
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1083
1138
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1084
- if (accessory.context.FirmwareRevision) {
1085
- FirmwareRevision = accessory.context.FirmwareRevision;
1086
- } else if (device.firmware) {
1139
+ if (device.firmware) {
1087
1140
  FirmwareRevision = device.firmware;
1141
+ } else if (device.version) {
1142
+ FirmwareRevision = JSON.stringify(device.version);
1143
+ } if (accessory.context.FirmwareRevision) {
1144
+ FirmwareRevision = accessory.context.FirmwareRevision;
1088
1145
  } else {
1089
1146
  FirmwareRevision = this.platform.version;
1090
1147
  }
@@ -1158,7 +1215,7 @@ export class ColorBulb {
1158
1215
  config['maxRetry'] = device.maxRetry;
1159
1216
  }
1160
1217
  if (Object.entries(config).length !== 0) {
1161
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1218
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1162
1219
  }
1163
1220
  }
1164
1221