@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 StripLight {
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'];
@@ -59,16 +61,21 @@ export class StripLight {
59
61
  doStripLightUpdate!: Subject<void>;
60
62
 
61
63
  // Connection
62
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
63
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
64
-
65
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
64
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
65
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
66
+
67
+ constructor(
68
+ private readonly platform: SwitchBotPlatform,
69
+ private accessory: PlatformAccessory,
70
+ public device: device & devicesConfig,
71
+ ) {
66
72
  // default placeholders
67
73
  this.logs(device);
68
74
  this.scan(device);
69
75
  this.refreshRate(device);
70
- this.config(device);
71
76
  this.context();
77
+ this.config(device);
78
+
72
79
  // this is subject we use to track when we need to POST changes to the SwitchBot API
73
80
  this.doStripLightUpdate = new Subject();
74
81
  this.stripLightUpdateInProgress = false;
@@ -91,7 +98,6 @@ export class StripLight {
91
98
  (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
92
99
  `${accessory.displayName} ${device.deviceType}`;
93
100
 
94
-
95
101
  if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
96
102
  this.accessory.removeService(this.lightBulbService);
97
103
  this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
@@ -202,8 +208,10 @@ export class StripLight {
202
208
  await this.pushChanges();
203
209
  } catch (e: any) {
204
210
  this.apiError(e);
205
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
206
- + ` Error Message: ${JSON.stringify(e.message)}`);
211
+ this.errorLog(
212
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
213
+ ` Error Message: ${JSON.stringify(e.message)}`,
214
+ );
207
215
  }
208
216
  this.stripLightUpdateInProgress = false;
209
217
  });
@@ -221,8 +229,9 @@ export class StripLight {
221
229
  await this.openAPIparseStatus();
222
230
  } else {
223
231
  await this.offlineOff();
224
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
225
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
232
+ this.debugWarnLog(
233
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
234
+ );
226
235
  }
227
236
  }
228
237
 
@@ -263,8 +272,9 @@ export class StripLight {
263
272
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
264
273
 
265
274
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
266
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
267
- + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
275
+ this.debugLog(
276
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
277
+ );
268
278
 
269
279
  // Hue
270
280
  this.Hue = hue;
@@ -288,8 +298,10 @@ export class StripLight {
288
298
  await this.openAPIRefreshStatus();
289
299
  } else {
290
300
  await this.offlineOff();
291
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
292
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
301
+ this.debugWarnLog(
302
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
303
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
304
+ );
293
305
  }
294
306
  }
295
307
 
@@ -314,8 +326,10 @@ export class StripLight {
314
326
  // Set an event hander
315
327
  switchbot.onadvertisement = async (ad: any) => {
316
328
  this.address = ad.address;
317
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
318
- + ` BLE Address Found: ${this.address}`);
329
+ this.debugLog(
330
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
331
+ ` BLE Address Found: ${this.address}`,
332
+ );
319
333
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
320
334
  this.serviceData = ad.serviceData;
321
335
  //this.state = ad.serviceData.state;
@@ -350,8 +364,10 @@ export class StripLight {
350
364
  })
351
365
  .catch(async (e: any) => {
352
366
  this.apiError(e);
353
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
354
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
367
+ this.errorLog(
368
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
369
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
370
+ );
355
371
  await this.BLERefreshConnection(switchbot);
356
372
  });
357
373
  } else {
@@ -369,10 +385,7 @@ export class StripLight {
369
385
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
370
386
  this.statusCode(statusCode);
371
387
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
372
- this.debugLog(
373
- `${this.device.deviceType}: ${this.accessory.displayName
374
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
375
- );
388
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
376
389
  this.power = deviceStatus.body.power;
377
390
  this.color = deviceStatus.body.color;
378
391
  this.brightness = deviceStatus.body.brightness;
@@ -380,8 +393,10 @@ export class StripLight {
380
393
  this.updateHomeKitCharacteristics();
381
394
  } catch (e: any) {
382
395
  this.apiError(e);
383
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
384
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
396
+ this.errorLog(
397
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
398
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
399
+ );
385
400
  }
386
401
  }
387
402
 
@@ -398,14 +413,15 @@ export class StripLight {
398
413
  async pushChanges(): Promise<void> {
399
414
  if (!this.device.enableCloudService && this.OpenAPI) {
400
415
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
401
- } else /*if (this.BLE) {
416
+ } /*if (this.BLE) {
402
417
  await this.BLEpushChanges();
403
- } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
418
+ } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
404
419
  await this.openAPIpushChanges();
405
420
  } else {
406
421
  await this.offlineOff();
407
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
408
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
422
+ this.debugWarnLog(
423
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
424
+ );
409
425
  }
410
426
  // Refresh the status from the API
411
427
  interval(15000)
@@ -451,8 +467,10 @@ export class StripLight {
451
467
  })
452
468
  .catch(async (e: any) => {
453
469
  this.apiError(e);
454
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
455
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
470
+ this.errorLog(
471
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
472
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
473
+ );
456
474
  await this.BLEPushConnection();
457
475
  });
458
476
  // Push Brightness Update
@@ -464,8 +482,9 @@ export class StripLight {
464
482
  await this.BLEpushRGBChanges();
465
483
  }
466
484
  } else {
467
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
468
- + `OnCached: ${this.accessory.context.On}`);
485
+ this.debugLog(
486
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
487
+ );
469
488
  }
470
489
  }
471
490
 
@@ -494,13 +513,18 @@ export class StripLight {
494
513
  })
495
514
  .catch(async (e: any) => {
496
515
  this.apiError(e);
497
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
498
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
516
+ this.errorLog(
517
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}` +
518
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
519
+ );
499
520
  await this.BLEPushConnection();
500
521
  });
501
522
  } else {
502
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
503
- + `BrightnessCached: ${this.accessory.context.Brightness}`);
523
+ this.debugLog(
524
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
525
+ `Brightness: ${this.Brightness}, ` +
526
+ `BrightnessCached: ${this.accessory.context.Brightness}`,
527
+ );
504
528
  }
505
529
  }
506
530
 
@@ -526,7 +550,7 @@ export class StripLight {
526
550
  id: this.device.bleMac,
527
551
  })
528
552
  .then(async (device_list: any) => {
529
- this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
553
+ this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
530
554
  return await device_list[0].setRGB(this.Brightness, red, green, blue);
531
555
  })
532
556
  .then(() => {
@@ -535,13 +559,17 @@ export class StripLight {
535
559
  })
536
560
  .catch(async (e: any) => {
537
561
  this.apiError(e);
538
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
539
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
562
+ this.errorLog(
563
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}` +
564
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
565
+ );
540
566
  await this.BLEPushConnection();
541
567
  });
542
568
  } else {
543
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, `
544
- + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
569
+ this.debugLog(
570
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
571
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
572
+ );
545
573
  }
546
574
  }
547
575
 
@@ -555,9 +583,9 @@ export class StripLight {
555
583
  command = 'turnOff';
556
584
  }*/
557
585
  const bodyChange = JSON.stringify({
558
- 'command': `${command}`,
559
- 'parameter': 'default',
560
- 'commandType': 'command',
586
+ command: `${command}`,
587
+ parameter: 'default',
588
+ commandType: 'command',
561
589
  });
562
590
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
563
591
  try {
@@ -572,13 +600,17 @@ export class StripLight {
572
600
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
573
601
  } catch (e: any) {
574
602
  this.apiError(e);
575
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
576
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
603
+ this.errorLog(
604
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
605
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
577
606
  );
578
607
  }
579
608
  } else {
580
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
581
- + `OnCached: ${this.accessory.context.On}`);
609
+ this.debugLog(
610
+ `${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
611
+ `On: ${this.On}, ` +
612
+ `OnCached: ${this.accessory.context.On}`,
613
+ );
582
614
  }
583
615
  // Push Hue & Saturation Update
584
616
  if (this.On) {
@@ -599,9 +631,9 @@ export class StripLight {
599
631
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
600
632
  // Make Push On request to the API
601
633
  const bodyChange = JSON.stringify({
602
- 'command': 'setColor',
603
- 'parameter': `${red}:${green}:${blue}`,
604
- 'commandType': 'command',
634
+ command: 'setColor',
635
+ parameter: `${red}:${green}:${blue}`,
636
+ commandType: 'command',
605
637
  });
606
638
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
607
639
  try {
@@ -616,13 +648,16 @@ export class StripLight {
616
648
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
617
649
  } catch (e: any) {
618
650
  this.apiError(e);
619
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
620
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
651
+ this.errorLog(
652
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}` +
653
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
621
654
  );
622
655
  }
623
656
  } else {
624
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
625
- + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
657
+ this.debugLog(
658
+ `${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
659
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
660
+ );
626
661
  }
627
662
  }
628
663
 
@@ -630,9 +665,9 @@ export class StripLight {
630
665
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
631
666
  if (this.Brightness !== this.accessory.context.Brightness) {
632
667
  const bodyChange = JSON.stringify({
633
- 'command': 'setBrightness',
634
- 'parameter': `${this.Brightness}`,
635
- 'commandType': 'command',
668
+ command: 'setBrightness',
669
+ parameter: `${this.Brightness}`,
670
+ commandType: 'command',
636
671
  });
637
672
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
638
673
  try {
@@ -647,13 +682,17 @@ export class StripLight {
647
682
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
648
683
  } catch (e: any) {
649
684
  this.apiError(e);
650
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
651
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
685
+ this.errorLog(
686
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}` +
687
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
652
688
  );
653
689
  }
654
690
  } else {
655
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges,` + `Brightness: ${this.Brightness}, `
656
- + `BrightnessCached: ${this.accessory.context.Brightness}`);
691
+ this.debugLog(
692
+ `${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges,` +
693
+ `Brightness: ${this.Brightness}, ` +
694
+ `BrightnessCached: ${this.accessory.context.Brightness}`,
695
+ );
657
696
  }
658
697
  }
659
698
 
@@ -905,8 +944,10 @@ export class StripLight {
905
944
  this.offlineOff();
906
945
  break;
907
946
  case 171:
908
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
909
- + `Hub: ${this.device.hubDeviceId}`);
947
+ this.errorLog(
948
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
949
+ `Hub: ${this.device.hubDeviceId}`,
950
+ );
910
951
  this.offlineOff();
911
952
  break;
912
953
  case 190:
@@ -922,8 +963,10 @@ export class StripLight {
922
963
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
923
964
  break;
924
965
  default:
925
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
926
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
966
+ this.infoLog(
967
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
968
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
969
+ );
927
970
  }
928
971
  }
929
972
 
@@ -943,14 +986,17 @@ export class StripLight {
943
986
 
944
987
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
945
988
  let FirmwareRevision: string;
946
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
947
- + `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
989
+ this.debugLog(
990
+ `${this.device.deviceType}: ${this.accessory.displayName} ` + `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
991
+ );
948
992
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
949
993
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
950
- if (accessory.context.FirmwareRevision) {
951
- FirmwareRevision = accessory.context.FirmwareRevision;
952
- } else if (device.firmware) {
994
+ if (device.firmware) {
953
995
  FirmwareRevision = device.firmware;
996
+ } else if (device.version) {
997
+ FirmwareRevision = JSON.stringify(device.version);
998
+ } else if (accessory.context.FirmwareRevision) {
999
+ FirmwareRevision = accessory.context.FirmwareRevision;
954
1000
  } else {
955
1001
  FirmwareRevision = this.platform.version;
956
1002
  }
@@ -1024,7 +1070,7 @@ export class StripLight {
1024
1070
  config['maxRetry'] = device.maxRetry;
1025
1071
  }
1026
1072
  if (Object.entries(config).length !== 0) {
1027
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1073
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1028
1074
  }
1029
1075
  }
1030
1076