@switchbot/homebridge-switchbot 2.6.0-beta.4 → 2.6.0

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 (143) hide show
  1. package/.vscode/tasks.json +13 -0
  2. package/CHANGELOG.md +4 -2
  3. package/README.md +18 -9
  4. package/dist/device/blindtilt.d.ts +1 -5
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +80 -140
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +1 -5
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +79 -138
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +2 -6
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +157 -304
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +2 -6
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +164 -311
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +1 -5
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +36 -72
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +1 -5
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +78 -138
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/hub.d.ts +2 -6
  29. package/dist/device/hub.d.ts.map +1 -1
  30. package/dist/device/hub.js +30 -63
  31. package/dist/device/hub.js.map +1 -1
  32. package/dist/device/humidifier.d.ts +1 -5
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +115 -228
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts +1 -5
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +38 -74
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/{striplight.d.ts → lightstrip.d.ts} +2 -10
  41. package/dist/device/lightstrip.d.ts.map +1 -0
  42. package/dist/device/{striplight.js → lightstrip.js} +138 -194
  43. package/dist/device/lightstrip.js.map +1 -0
  44. package/dist/device/lock.d.ts +1 -5
  45. package/dist/device/lock.d.ts.map +1 -1
  46. package/dist/device/lock.js +66 -126
  47. package/dist/device/lock.js.map +1 -1
  48. package/dist/device/meter.d.ts +1 -5
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +38 -74
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts +1 -5
  53. package/dist/device/meterplus.d.ts.map +1 -1
  54. package/dist/device/meterplus.js +39 -75
  55. package/dist/device/meterplus.js.map +1 -1
  56. package/dist/device/motion.d.ts +1 -5
  57. package/dist/device/motion.d.ts.map +1 -1
  58. package/dist/device/motion.js +35 -72
  59. package/dist/device/motion.js.map +1 -1
  60. package/dist/device/plug.d.ts +1 -5
  61. package/dist/device/plug.d.ts.map +1 -1
  62. package/dist/device/plug.js +65 -126
  63. package/dist/device/plug.js.map +1 -1
  64. package/dist/device/robotvacuumcleaner.d.ts +1 -5
  65. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  66. package/dist/device/robotvacuumcleaner.js +79 -151
  67. package/dist/device/robotvacuumcleaner.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts +3 -7
  69. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  70. package/dist/irdevice/airconditioner.js +34 -62
  71. package/dist/irdevice/airconditioner.js.map +1 -1
  72. package/dist/irdevice/airpurifier.d.ts +3 -7
  73. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  74. package/dist/irdevice/airpurifier.js +31 -59
  75. package/dist/irdevice/airpurifier.js.map +1 -1
  76. package/dist/irdevice/camera.d.ts +1 -5
  77. package/dist/irdevice/camera.d.ts.map +1 -1
  78. package/dist/irdevice/camera.js +30 -57
  79. package/dist/irdevice/camera.js.map +1 -1
  80. package/dist/irdevice/fan.d.ts +2 -6
  81. package/dist/irdevice/fan.d.ts.map +1 -1
  82. package/dist/irdevice/fan.js +39 -66
  83. package/dist/irdevice/fan.js.map +1 -1
  84. package/dist/irdevice/light.d.ts +1 -5
  85. package/dist/irdevice/light.d.ts.map +1 -1
  86. package/dist/irdevice/light.js +32 -59
  87. package/dist/irdevice/light.js.map +1 -1
  88. package/dist/irdevice/other.d.ts +1 -5
  89. package/dist/irdevice/other.d.ts.map +1 -1
  90. package/dist/irdevice/other.js +30 -57
  91. package/dist/irdevice/other.js.map +1 -1
  92. package/dist/irdevice/tv.d.ts +3 -7
  93. package/dist/irdevice/tv.d.ts.map +1 -1
  94. package/dist/irdevice/tv.js +46 -76
  95. package/dist/irdevice/tv.js.map +1 -1
  96. package/dist/irdevice/vacuumcleaner.d.ts +2 -6
  97. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  98. package/dist/irdevice/vacuumcleaner.js +30 -58
  99. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  100. package/dist/irdevice/waterheater.d.ts +7 -23
  101. package/dist/irdevice/waterheater.d.ts.map +1 -1
  102. package/dist/irdevice/waterheater.js +41 -74
  103. package/dist/irdevice/waterheater.js.map +1 -1
  104. package/dist/platform.d.ts +14 -5
  105. package/dist/platform.d.ts.map +1 -1
  106. package/dist/platform.js +156 -149
  107. package/dist/platform.js.map +1 -1
  108. package/dist/settings.d.ts +4 -0
  109. package/dist/settings.d.ts.map +1 -1
  110. package/dist/settings.js +5 -1
  111. package/dist/settings.js.map +1 -1
  112. package/nodemon.json +1 -1
  113. package/package.json +10 -10
  114. package/src/device/blindtilt.ts +122 -181
  115. package/src/device/bot.ts +96 -149
  116. package/src/device/ceilinglight.ts +172 -315
  117. package/src/device/colorbulb.ts +178 -324
  118. package/src/device/contact.ts +48 -78
  119. package/src/device/curtain.ts +93 -148
  120. package/src/device/hub.ts +34 -63
  121. package/src/device/humidifier.ts +135 -243
  122. package/src/device/iosensor.ts +49 -79
  123. package/src/device/{striplight.ts → lightstrip.ts} +148 -200
  124. package/src/device/lock.ts +78 -134
  125. package/src/device/meter.ts +48 -78
  126. package/src/device/meterplus.ts +50 -80
  127. package/src/device/motion.ts +46 -77
  128. package/src/device/plug.ts +76 -134
  129. package/src/device/robotvacuumcleaner.ts +91 -159
  130. package/src/irdevice/airconditioner.ts +56 -81
  131. package/src/irdevice/airpurifier.ts +41 -67
  132. package/src/irdevice/camera.ts +35 -60
  133. package/src/irdevice/fan.ts +46 -71
  134. package/src/irdevice/light.ts +38 -63
  135. package/src/irdevice/other.ts +35 -60
  136. package/src/irdevice/tv.ts +52 -80
  137. package/src/irdevice/vacuumcleaner.ts +36 -62
  138. package/src/irdevice/waterheater.ts +46 -76
  139. package/src/platform.ts +144 -158
  140. package/src/settings.ts +5 -0
  141. package/.github/npm-version-script.js +0 -81
  142. package/dist/device/striplight.d.ts.map +0 -1
  143. package/dist/device/striplight.js.map +0 -1
@@ -1,14 +1,11 @@
1
- import https from 'https';
2
- import crypto from 'crypto';
3
1
  import { Context } from 'vm';
4
- import { IncomingMessage } from 'http';
5
- import superStringify from 'super-stringify';
2
+ import { request } from 'undici';
3
+ import { sleep } from '../utils';
6
4
  import { interval, Subject } from 'rxjs';
7
5
  import { SwitchBotPlatform } from '../platform';
8
6
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
7
+ import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
9
8
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
10
- import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, HostDomain, DevicePath } from '../settings';
11
- import { sleep } from '../utils';
12
9
 
13
10
  /**
14
11
  * Platform Accessory
@@ -188,7 +185,7 @@ export class ColorBulb {
188
185
  this.accessory.context.adaptiveLighting = true;
189
186
  this.debugLog(
190
187
  `${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
191
- ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
188
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
192
189
  );
193
190
  }
194
191
 
@@ -217,7 +214,7 @@ export class ColorBulb {
217
214
  } catch (e: any) {
218
215
  this.apiError(e);
219
216
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
220
- + ` Error Message: ${superStringify(e.message)}`);
217
+ + ` Error Message: ${JSON.stringify(e.message)}`);
221
218
  }
222
219
  this.colorBulbUpdateInProgress = false;
223
220
  });
@@ -236,7 +233,7 @@ export class ColorBulb {
236
233
  } else {
237
234
  await this.offlineOff();
238
235
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
239
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
236
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
240
237
  }
241
238
  }
242
239
 
@@ -264,7 +261,7 @@ export class ColorBulb {
264
261
 
265
262
  const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
266
263
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
267
- + ` hs: ${superStringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`);
264
+ + ` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`);
268
265
 
269
266
  // Hue
270
267
  this.Hue = hue;
@@ -301,15 +298,15 @@ export class ColorBulb {
301
298
 
302
299
  // Color, Hue & Brightness
303
300
  if (this.color) {
304
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${superStringify(this.color)}`);
301
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
305
302
  const [red, green, blue] = this.color!.split(':');
306
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${superStringify(red)}`);
307
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${superStringify(green)}`);
308
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${superStringify(blue)}`);
303
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
304
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
305
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
309
306
 
310
307
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
311
308
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
312
- + ` hs: ${superStringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
309
+ + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
313
310
 
314
311
  // Hue
315
312
  this.Hue = hue;
@@ -345,7 +342,7 @@ export class ColorBulb {
345
342
  } else {
346
343
  await this.offlineOff();
347
344
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
348
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
345
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
349
346
  }
350
347
  }
351
348
 
@@ -371,8 +368,8 @@ export class ColorBulb {
371
368
  switchbot.onadvertisement = async (ad: any) => {
372
369
  this.address = ad.address;
373
370
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
374
- + ` BLE Address Found: ${this.address}`);
375
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
371
+ + ` BLE Address Found: ${this.address}`);
372
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
376
373
  this.serviceData = ad.serviceData;
377
374
  this.powerState = ad.serviceData.power;
378
375
  this.state = ad.serviceData.state;
@@ -386,7 +383,7 @@ export class ColorBulb {
386
383
  this.color_mode = ad.serviceData.color_mode;
387
384
  this.speed = ad.serviceData.speed;
388
385
  this.loop_index = ad.serviceData.loop_index;
389
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
386
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
390
387
  /*this.debugLog(
391
388
  `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
392
389
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
@@ -406,13 +403,13 @@ export class ColorBulb {
406
403
  return await sleep(this.scanDuration * 1000);
407
404
  })
408
405
  .then(async () => {
409
- // Stop to monitor
406
+ // Stop to monitor
410
407
  await this.stopScanning(switchbot);
411
408
  })
412
409
  .catch(async (e: any) => {
413
410
  this.apiError(e);
414
411
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
415
- + ` Connection, Error Message: ${superStringify(e.message)}`);
412
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
416
413
  await this.BLERefreshConnection(switchbot);
417
414
  });
418
415
  } else {
@@ -423,56 +420,24 @@ export class ColorBulb {
423
420
  async openAPIRefreshStatus() {
424
421
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
425
422
  try {
426
- const t = Date.now();
427
- const nonce = 'requestID';
428
- const data = this.platform.config.credentials?.token + t + nonce;
429
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
430
- const sign = signTerm.toString('base64');
431
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
432
- const options = {
433
- hostname: HostDomain,
434
- port: 443,
435
- path: `${DevicePath}/${this.device.deviceId}/status`,
436
- method: 'GET',
437
- headers: {
438
- Authorization: this.platform.config.credentials?.token,
439
- sign: sign,
440
- nonce: nonce,
441
- t: t,
442
- 'Content-Type': 'application/json',
443
- },
444
- };
445
- const req = https.request(options, (res) => {
446
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
447
- this.statusCode({ res });
448
- let rawData = '';
449
- res.on('data', (d) => {
450
- rawData += d;
451
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
452
- });
453
- res.on('end', () => {
454
- try {
455
- this.deviceStatus = JSON.parse(rawData);
456
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
457
- this.power = this.deviceStatus.body.power;
458
- this.color = this.deviceStatus.body.color;
459
- this.brightness = this.deviceStatus.body.brightness;
460
- this.colorTemperature = this.deviceStatus.body.colorTemperature;
461
- this.openAPIparseStatus();
462
- this.updateHomeKitCharacteristics();
463
- } catch (e: any) {
464
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
465
- }
466
- });
423
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
424
+ headers: this.platform.generateHeaders(),
467
425
  });
468
- req.on('error', (e: any) => {
469
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
470
- });
471
- req.end();
426
+ const deviceStatus = await body.json();
427
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
428
+ this.statusCode(statusCode);
429
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
430
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
431
+ this.power = deviceStatus.body.power;
432
+ this.color = deviceStatus.body.color;
433
+ this.brightness = deviceStatus.body.brightness;
434
+ this.colorTemperature = deviceStatus.body.colorTemperature;
435
+ this.openAPIparseStatus();
436
+ this.updateHomeKitCharacteristics();
472
437
  } catch (e: any) {
473
438
  this.apiError(e);
474
439
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
475
- + ` Connection, Error Message: ${superStringify(e.message)}`);
440
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
476
441
  }
477
442
  }
478
443
 
@@ -497,7 +462,7 @@ export class ColorBulb {
497
462
  } else {
498
463
  await this.offlineOff();
499
464
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
500
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
465
+ + ` ${this.device.connectionType}, pushChanges will not happen.`);
501
466
  }
502
467
  // Refresh the status from the API
503
468
  interval(15000)
@@ -544,7 +509,7 @@ export class ColorBulb {
544
509
  .catch(async (e: any) => {
545
510
  this.apiError(e);
546
511
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
547
- + ` Connection, Error Message: ${superStringify(e.message)}`);
512
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
548
513
  await this.BLEPushConnection();
549
514
  });
550
515
  // Push Brightness Update
@@ -561,7 +526,7 @@ export class ColorBulb {
561
526
  }
562
527
  } else {
563
528
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
564
- +`OnCached: ${this.accessory.context.On}`);
529
+ + `OnCached: ${this.accessory.context.On}`);
565
530
  }
566
531
  }
567
532
 
@@ -591,12 +556,12 @@ export class ColorBulb {
591
556
  .catch(async (e: any) => {
592
557
  this.apiError(e);
593
558
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
594
- + ` Connection, Error Message: ${superStringify(e.message)}`);
559
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
595
560
  await this.BLEPushConnection();
596
561
  });
597
562
  } else {
598
563
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
599
- +`BrightnessCached: ${this.accessory.context.Brightness}`);
564
+ + `BrightnessCached: ${this.accessory.context.Brightness}`);
600
565
  }
601
566
  }
602
567
 
@@ -626,12 +591,12 @@ export class ColorBulb {
626
591
  .catch(async (e: any) => {
627
592
  this.apiError(e);
628
593
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with `
629
- + `${this.device.connectionType} Connection, Error Message: ${superStringify(e.message)}`);
594
+ + `${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
630
595
  await this.BLEPushConnection();
631
596
  });
632
597
  } else {
633
598
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
634
- `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
599
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
635
600
 
636
601
  }
637
602
  }
@@ -639,11 +604,11 @@ export class ColorBulb {
639
604
  async BLEpushRGBChanges(): Promise<void> {
640
605
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
641
606
  if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
642
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
643
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
607
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
608
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
644
609
 
645
610
  const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
646
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
611
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
647
612
 
648
613
  const switchbot = await this.platform.connectBLE();
649
614
  // Convert to BLE Address
@@ -668,7 +633,7 @@ export class ColorBulb {
668
633
  .catch(async (e: any) => {
669
634
  this.apiError(e);
670
635
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
671
- + ` Connection, Error Message: ${superStringify(e.message)}`);
636
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
672
637
  await this.BLEPushConnection();
673
638
  });
674
639
  } else {
@@ -678,258 +643,146 @@ export class ColorBulb {
678
643
  }
679
644
 
680
645
  async openAPIpushChanges(): Promise<void> {
681
- try {
682
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
683
- if (this.On !== this.accessory.context.On) {
684
- // Make Push On request to the API
685
- const t = Date.now();
686
- const nonce = 'requestID';
687
- const data = this.platform.config.credentials?.token + t + nonce;
688
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
689
- .update(Buffer.from(data, 'utf-8'))
690
- .digest();
691
- const sign = signTerm.toString('base64');
692
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
693
-
694
- let command = '';
695
- if (this.On) {
696
- command = 'turnOn';
697
- } else {
698
- command = 'turnOff';
699
- }
700
- const body = superStringify({
701
- 'command': `${command}`,
702
- 'parameter': 'default',
703
- 'commandType': 'command',
704
- });
705
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
706
- const options = {
707
- hostname: HostDomain,
708
- port: 443,
709
- path: `${DevicePath}/${this.device.deviceId}/commands`,
646
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
647
+ if (this.On !== this.accessory.context.On) {
648
+ let command = '';
649
+ if (this.On) {
650
+ command = 'turnOn';
651
+ } else {
652
+ command = 'turnOff';
653
+ }
654
+ const body = JSON.stringify({
655
+ 'command': `${command}`,
656
+ 'parameter': 'default',
657
+ 'commandType': 'command',
658
+ });
659
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
660
+ try {
661
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
710
662
  method: 'POST',
711
- headers: {
712
- 'Authorization': this.platform.config.credentials?.token,
713
- 'sign': sign,
714
- 'nonce': nonce,
715
- 't': t,
716
- 'Content-Type': 'application/json',
717
- 'Content-Length': body.length,
718
- },
719
- };
720
- const req = https.request(options, res => {
721
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
722
- this.statusCode({ res });
723
- res.on('data', d => {
724
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
725
- });
726
- });
727
- req.on('error', (e: any) => {
728
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
663
+ headers: this.platform.generateHeaders(),
729
664
  });
730
- req.write(body);
731
- req.end();
732
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${superStringify(req)}`);
733
- } else {
734
- this.debugLog(
735
- `${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
736
- +`OnCached: ${this.accessory.context.On}`,
665
+ const deviceStatus = await body.json();
666
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
667
+ this.statusCode(statusCode);
668
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
669
+ } catch (e: any) {
670
+ this.apiError(e);
671
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
672
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
737
673
  );
738
674
  }
739
- // Push Brightness Update
740
- if (this.On) {
741
- await this.pushBrightnessChanges();
742
- }
743
- // Push ColorTemperature Update
744
- if (this.On) {
745
- await this.pushColorTemperatureChanges();
746
- }
747
- // Push Hue & Saturation Update
748
- if (this.On) {
749
- await this.pushHueSaturationChanges();
750
- }
751
- } catch (e: any) {
752
- this.apiError(e);
753
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
754
- + ` Connection, Error Message: ${superStringify(e.message)}`,
755
- );
675
+ } else {
676
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
677
+ + `OnCached: ${this.accessory.context.On}`);
678
+ }
679
+ // Push Hue & Saturation Update
680
+ if (this.On) {
681
+ await this.pushHueSaturationChanges();
682
+ }
683
+ // Push ColorTemperature Update
684
+ if (this.On) {
685
+ await this.pushColorTemperatureChanges();
686
+ }
687
+ // Push Brightness Update
688
+ if (this.On) {
689
+ await this.pushBrightnessChanges();
756
690
  }
757
691
  }
758
692
 
759
693
  async pushHueSaturationChanges(): Promise<void> {
760
- try {
761
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
762
- if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
763
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
764
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
765
-
766
- const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
767
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
768
- // Make Push Hue/Saturation request to the API
769
- const t = Date.now();
770
- const nonce = 'requestID';
771
- const data = this.platform.config.credentials?.token + t + nonce;
772
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
773
- .update(Buffer.from(data, 'utf-8'))
774
- .digest();
775
- const sign = signTerm.toString('base64');
776
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
777
- const body = superStringify({
778
- 'command': 'setColor',
779
- 'parameter': `${red}:${green}:${blue}`,
780
- 'commandType': 'command',
781
- });
782
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
783
- const options = {
784
- hostname: HostDomain,
785
- port: 443,
786
- path: `${DevicePath}/${this.device.deviceId}/commands`,
694
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
695
+ if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
696
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
697
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
698
+ const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
699
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
700
+ const body = JSON.stringify({
701
+ 'command': 'setColor',
702
+ 'parameter': `${red}:${green}:${blue}`,
703
+ 'commandType': 'command',
704
+ });
705
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
706
+ try {
707
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
787
708
  method: 'POST',
788
- headers: {
789
- 'Authorization': this.platform.config.credentials?.token,
790
- 'sign': sign,
791
- 'nonce': nonce,
792
- 't': t,
793
- 'Content-Type': 'application/json',
794
- 'Content-Length': body.length,
795
- },
796
- };
797
- const req = https.request(options, res => {
798
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
799
- res.on('data', d => {
800
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
801
- });
709
+ headers: this.platform.generateHeaders(),
802
710
  });
803
- req.on('error', (e: any) => {
804
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
805
- });
806
- req.write(body);
807
- req.end();
808
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${superStringify(req)}`);
809
- } else {
810
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
811
- + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
711
+ const deviceStatus = await body.json();
712
+ this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
713
+ this.statusCode(statusCode);
714
+ this.debugLog(`Headers: ${JSON.stringify(headers)}`);
715
+ } catch (e: any) {
716
+ this.apiError(e);
717
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
718
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
719
+ );
812
720
  }
813
- } catch (e: any) {
814
- this.apiError(e);
815
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
816
- + ` Connection, Error Message: ${superStringify(e.message)}`);
721
+ } else {
722
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
723
+ + `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
817
724
  }
818
725
  }
819
726
 
820
727
  async pushColorTemperatureChanges(): Promise<void> {
821
- try {
822
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
823
- if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
824
- const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
825
- this.cacheKelvin = kelvin;
826
-
827
- // Make Push On request to the API
828
- const t = Date.now();
829
- const nonce = 'requestID';
830
- const data = this.platform.config.credentials?.token + t + nonce;
831
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
832
- .update(Buffer.from(data, 'utf-8'))
833
- .digest();
834
- const sign = signTerm.toString('base64');
835
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
836
- const body = superStringify({
837
- 'command': 'setColorTemperature',
838
- 'parameter': `${kelvin}`,
839
- 'commandType': 'command',
840
- });
841
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
842
- const options = {
843
- hostname: HostDomain,
844
- port: 443,
845
- path: `${DevicePath}/${this.device.deviceId}/commands`,
728
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
729
+ if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
730
+ const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
731
+ this.cacheKelvin = kelvin;
732
+ const body = JSON.stringify({
733
+ 'command': 'setColorTemperature',
734
+ 'parameter': `${kelvin}`,
735
+ 'commandType': 'command',
736
+ });
737
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
738
+ try {
739
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
846
740
  method: 'POST',
847
- headers: {
848
- 'Authorization': this.platform.config.credentials?.token,
849
- 'sign': sign,
850
- 'nonce': nonce,
851
- 't': t,
852
- 'Content-Type': 'application/json',
853
- 'Content-Length': body.length,
854
- },
855
- };
856
- const req = https.request(options, res => {
857
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
858
- res.on('data', d => {
859
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
860
- });
741
+ headers: this.platform.generateHeaders(),
861
742
  });
862
- req.on('error', (e: any) => {
863
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
864
- });
865
- req.write(body);
866
- req.end();
867
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges: ${superStringify(req)}`);
868
- this.accessory.context.ColorTemperature = this.ColorTemperature;
869
- } else {
870
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
871
- `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
743
+ const deviceStatus = await body.json();
744
+ this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
745
+ this.statusCode(statusCode);
746
+ this.debugLog(`Headers: ${JSON.stringify(headers)}`);
747
+ } catch (e: any) {
748
+ this.apiError(e);
749
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
750
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
751
+ );
872
752
  }
873
- } catch (e: any) {
874
- this.apiError(e);
875
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
876
- + ` Connection, Error Message: ${superStringify(e.message)}`);
753
+ } else {
754
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
755
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
877
756
  }
878
757
  }
879
758
 
880
759
  async pushBrightnessChanges(): Promise<void> {
881
- try {
882
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
883
- if (this.Brightness !== this.accessory.context.Brightness) {
884
- // Make Push On request to the API
885
- const t = Date.now();
886
- const nonce = 'requestID';
887
- const data = this.platform.config.credentials?.token + t + nonce;
888
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
889
- .update(Buffer.from(data, 'utf-8'))
890
- .digest();
891
- const sign = signTerm.toString('base64');
892
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
893
- const body = superStringify({
894
- 'command': 'setBrightness',
895
- 'parameter': `${this.Brightness}`,
896
- 'commandType': 'command',
897
- });
898
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
899
- const options = {
900
- hostname: HostDomain,
901
- port: 443,
902
- path: `${DevicePath}/${this.device.deviceId}/commands`,
760
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
761
+ if (this.Brightness !== this.accessory.context.Brightness) {
762
+ const body = JSON.stringify({
763
+ 'command': 'setBrightness',
764
+ 'parameter': `${this.Brightness}`,
765
+ 'commandType': 'command',
766
+ });
767
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
768
+ try {
769
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
903
770
  method: 'POST',
904
- headers: {
905
- 'Authorization': this.platform.config.credentials?.token,
906
- 'sign': sign,
907
- 'nonce': nonce,
908
- 't': t,
909
- 'Content-Type': 'application/json',
910
- 'Content-Length': body.length,
911
- },
912
- };
913
- const req = https.request(options, res => {
914
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
915
- res.on('data', d => {
916
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
917
- });
771
+ headers: this.platform.generateHeaders(),
918
772
  });
919
- req.on('error', (e: any) => {
920
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
921
- });
922
- req.write(body);
923
- req.end();
924
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${superStringify(req)}`);
925
- } else {
926
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
927
- +`BrightnessCached: ${this.accessory.context.Brightness}`);
773
+ const deviceStatus = await body.json();
774
+ this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
775
+ this.statusCode(statusCode);
776
+ this.debugLog(`Headers: ${JSON.stringify(headers)}`);
777
+ } catch (e: any) {
778
+ this.apiError(e);
779
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
780
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
781
+ );
928
782
  }
929
- } catch (e: any) {
930
- this.apiError(e);
931
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
932
- + ` Connection, Error Message: ${superStringify(e.message)}`);
783
+ } else {
784
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
785
+ + `BrightnessCached: ${this.accessory.context.Brightness}`);
933
786
  }
934
787
  }
935
788
 
@@ -1098,7 +951,7 @@ export class ColorBulb {
1098
951
  });
1099
952
  // Set an event handler
1100
953
  switchbot.onadvertisement = (ad: any) => {
1101
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
954
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
1102
955
  };
1103
956
  await sleep(10000);
1104
957
  // Stop to monitor
@@ -1165,40 +1018,41 @@ export class ColorBulb {
1165
1018
  }
1166
1019
  }
1167
1020
 
1168
- async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
1169
- switch (res.statusCode) {
1021
+ async statusCode(statusCode: number): Promise<void> {
1022
+ switch (statusCode) {
1170
1023
  case 151:
1171
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
1024
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
1172
1025
  break;
1173
1026
  case 152:
1174
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
1027
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
1175
1028
  break;
1176
1029
  case 160:
1177
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
1030
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
1178
1031
  break;
1179
1032
  case 161:
1180
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
1181
- await this.offlineOff();
1033
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
1034
+ this.offlineOff();
1182
1035
  break;
1183
1036
  case 171:
1184
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
1185
- await this.offlineOff();
1037
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
1038
+ + `Hub: ${this.device.hubDeviceId}`);
1039
+ this.offlineOff();
1186
1040
  break;
1187
1041
  case 190:
1188
1042
  this.errorLog(
1189
1043
  `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
1190
- ` Or command: ${superStringify(res)} format is invalid`,
1044
+ ` Or command format is invalid, statusCode: ${statusCode}`,
1191
1045
  );
1192
1046
  break;
1193
1047
  case 100:
1194
- if (this.platform.debugMode) {
1195
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
1196
- }
1048
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
1049
+ break;
1050
+ case 200:
1051
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
1197
1052
  break;
1198
1053
  default:
1199
- if (this.platform.debugMode) {
1200
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
1201
- }
1054
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
1055
+ + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
1202
1056
  }
1203
1057
  }
1204
1058
 
@@ -1220,7 +1074,7 @@ export class ColorBulb {
1220
1074
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
1221
1075
  let FirmwareRevision: string;
1222
1076
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
1223
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
1077
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
1224
1078
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
1225
1079
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
1226
1080
  if (accessory.context.FirmwareRevision) {
@@ -1300,7 +1154,7 @@ export class ColorBulb {
1300
1154
  config['maxRetry'] = device.maxRetry;
1301
1155
  }
1302
1156
  if (Object.entries(config).length !== 0) {
1303
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
1157
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1304
1158
  }
1305
1159
  }
1306
1160