@switchbot/homebridge-switchbot 2.0.0-beta.12 → 2.0.0-beta.14

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 (86) hide show
  1. package/dist/device/bot.d.ts.map +1 -1
  2. package/dist/device/bot.js +19 -18
  3. package/dist/device/bot.js.map +1 -1
  4. package/dist/device/colorbulb.d.ts.map +1 -1
  5. package/dist/device/colorbulb.js +32 -25
  6. package/dist/device/colorbulb.js.map +1 -1
  7. package/dist/device/contact.d.ts.map +1 -1
  8. package/dist/device/contact.js +7 -6
  9. package/dist/device/contact.js.map +1 -1
  10. package/dist/device/curtain.d.ts.map +1 -1
  11. package/dist/device/curtain.js +14 -13
  12. package/dist/device/curtain.js.map +1 -1
  13. package/dist/device/humidifier.d.ts.map +1 -1
  14. package/dist/device/humidifier.js +18 -17
  15. package/dist/device/humidifier.js.map +1 -1
  16. package/dist/device/lock.d.ts.map +1 -1
  17. package/dist/device/lock.js +8 -7
  18. package/dist/device/lock.js.map +1 -1
  19. package/dist/device/meter.d.ts.map +1 -1
  20. package/dist/device/meter.js +9 -8
  21. package/dist/device/meter.js.map +1 -1
  22. package/dist/device/meterplus.d.ts.map +1 -1
  23. package/dist/device/meterplus.js +8 -7
  24. package/dist/device/meterplus.js.map +1 -1
  25. package/dist/device/motion.d.ts.map +1 -1
  26. package/dist/device/motion.js +7 -6
  27. package/dist/device/motion.js.map +1 -1
  28. package/dist/device/plug.d.ts.map +1 -1
  29. package/dist/device/plug.js +13 -12
  30. package/dist/device/plug.js.map +1 -1
  31. package/dist/device/striplight.d.ts +2 -2
  32. package/dist/device/striplight.d.ts.map +1 -1
  33. package/dist/device/striplight.js +44 -36
  34. package/dist/device/striplight.js.map +1 -1
  35. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  36. package/dist/irdevice/airconditioner.js +10 -9
  37. package/dist/irdevice/airconditioner.js.map +1 -1
  38. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  39. package/dist/irdevice/airpurifier.js +8 -7
  40. package/dist/irdevice/airpurifier.js.map +1 -1
  41. package/dist/irdevice/camera.d.ts.map +1 -1
  42. package/dist/irdevice/camera.js +7 -6
  43. package/dist/irdevice/camera.js.map +1 -1
  44. package/dist/irdevice/fan.d.ts.map +1 -1
  45. package/dist/irdevice/fan.js +10 -9
  46. package/dist/irdevice/fan.js.map +1 -1
  47. package/dist/irdevice/light.d.ts.map +1 -1
  48. package/dist/irdevice/light.js +9 -8
  49. package/dist/irdevice/light.js.map +1 -1
  50. package/dist/irdevice/other.d.ts.map +1 -1
  51. package/dist/irdevice/other.js +7 -6
  52. package/dist/irdevice/other.js.map +1 -1
  53. package/dist/irdevice/tv.d.ts.map +1 -1
  54. package/dist/irdevice/tv.js +16 -15
  55. package/dist/irdevice/tv.js.map +1 -1
  56. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  57. package/dist/irdevice/vacuumcleaner.js +7 -6
  58. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  59. package/dist/irdevice/waterheater.d.ts.map +1 -1
  60. package/dist/irdevice/waterheater.js +7 -6
  61. package/dist/irdevice/waterheater.js.map +1 -1
  62. package/dist/platform.d.ts.map +1 -1
  63. package/dist/platform.js +24 -23
  64. package/dist/platform.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/device/bot.ts +19 -18
  67. package/src/device/colorbulb.ts +33 -26
  68. package/src/device/contact.ts +7 -6
  69. package/src/device/curtain.ts +14 -13
  70. package/src/device/humidifier.ts +18 -17
  71. package/src/device/lock.ts +8 -7
  72. package/src/device/meter.ts +9 -8
  73. package/src/device/meterplus.ts +8 -7
  74. package/src/device/motion.ts +7 -6
  75. package/src/device/plug.ts +13 -12
  76. package/src/device/striplight.ts +47 -39
  77. package/src/irdevice/airconditioner.ts +10 -9
  78. package/src/irdevice/airpurifier.ts +8 -7
  79. package/src/irdevice/camera.ts +7 -6
  80. package/src/irdevice/fan.ts +10 -9
  81. package/src/irdevice/light.ts +9 -8
  82. package/src/irdevice/other.ts +7 -6
  83. package/src/irdevice/tv.ts +16 -15
  84. package/src/irdevice/vacuumcleaner.ts +7 -6
  85. package/src/irdevice/waterheater.ts +7 -6
  86. package/src/platform.ts +24 -23
package/src/device/bot.ts CHANGED
@@ -3,6 +3,7 @@ import crypto from 'crypto';
3
3
  import { Context } from 'vm';
4
4
  import { IncomingMessage } from 'http';
5
5
  import { interval, Subject } from 'rxjs';
6
+ import superStringify from 'super-stringify';
6
7
  import { SwitchBotPlatform } from '../platform';
7
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
9
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
@@ -362,10 +363,10 @@ export class Bot {
362
363
  } catch (e: any) {
363
364
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`);
364
365
  if (this.deviceLogging.includes('debug')) {
365
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
366
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
366
367
  }
367
368
  if (this.platform.debugMode) {
368
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
369
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${superStringify(e)}`);
369
370
  }
370
371
  }
371
372
  this.botUpdateInProgress = false;
@@ -473,7 +474,7 @@ export class Bot {
473
474
  this.mode = ad.serviceData.mode;
474
475
  this.state = ad.serviceData.state;
475
476
  this.battery = ad.serviceData.battery;
476
- this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
477
+ this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
477
478
  this.debugLog(
478
479
  `Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
479
480
  ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
@@ -509,7 +510,7 @@ export class Bot {
509
510
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
510
511
  if (this.deviceLogging.includes('debug')) {
511
512
  this.errorLog(
512
- `Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
513
+ `Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
513
514
  );
514
515
  }
515
516
  if (this.platform.config.credentials?.token) {
@@ -530,7 +531,7 @@ export class Bot {
530
531
  });
531
532
  // Set an event handler
532
533
  switchbot.onadvertisement = (ad: any) => {
533
- this.warnLog(`Bot: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
534
+ this.warnLog(`Bot: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
534
535
  };
535
536
  await switchbot.wait(10000);
536
537
  // Stop to monitor
@@ -572,7 +573,7 @@ export class Bot {
572
573
  res.on('end', () => {
573
574
  try {
574
575
  this.deviceStatus = JSON.parse(rawData);
575
- this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
576
+ this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
576
577
  this.power = this.deviceStatus.body.power;
577
578
  this.parseStatus();
578
579
  this.updateHomeKitCharacteristics();
@@ -589,11 +590,11 @@ export class Bot {
589
590
  this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
590
591
  if (this.deviceLogging.includes('debug')) {
591
592
  this.errorLog(
592
- `Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
593
+ `Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
593
594
  );
594
595
  }
595
596
  if (this.platform.debugMode) {
596
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
597
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${superStringify(e)}`);
597
598
  }
598
599
  this.apiError(e);
599
600
  }
@@ -656,11 +657,11 @@ export class Bot {
656
657
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
657
658
  if (this.deviceLogging.includes('debug')) {
658
659
  this.errorLog(
659
- `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
660
+ `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
660
661
  );
661
662
  }
662
663
  if (this.platform.debugMode) {
663
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
664
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${superStringify(e)}`);
664
665
  }
665
666
  if (this.platform.config.credentials?.token) {
666
667
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -684,11 +685,11 @@ export class Bot {
684
685
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
685
686
  if (this.deviceLogging.includes('debug')) {
686
687
  this.errorLog(
687
- `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
688
+ `Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
688
689
  );
689
690
  }
690
691
  if (this.platform.debugMode) {
691
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
692
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${superStringify(e)}`);
692
693
  }
693
694
  if (this.platform.config.credentials?.token) {
694
695
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -746,7 +747,7 @@ export class Bot {
746
747
  } else {
747
748
  throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
748
749
  }
749
- const body = JSON.stringify({
750
+ const body = superStringify({
750
751
  'command': `${command}`,
751
752
  'parameter': 'default',
752
753
  'commandType': 'command',
@@ -778,18 +779,18 @@ export class Bot {
778
779
  });
779
780
  req.write(body);
780
781
  req.end();
781
- this.debugLog(`Bot: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
782
+ this.debugLog(`Bot: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
782
783
  this.accessory.context.On = this.On;
783
784
  }
784
785
  } catch (e: any) {
785
786
  this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
786
787
  if (this.deviceLogging.includes('debug')) {
787
788
  this.errorLog(
788
- `Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
789
+ `Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
789
790
  );
790
791
  }
791
792
  if (this.platform.debugMode) {
792
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
793
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${superStringify(e)}`);
793
794
  }
794
795
  this.apiError(e);
795
796
  }
@@ -1050,7 +1051,7 @@ export class Bot {
1050
1051
  case 190:
1051
1052
  this.errorLog(
1052
1053
  `Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
1053
- ` Or command: ${JSON.stringify(res)} format is invalid`,
1054
+ ` Or command: ${superStringify(res)} format is invalid`,
1054
1055
  );
1055
1056
  break;
1056
1057
  case 100:
@@ -1165,7 +1166,7 @@ export class Bot {
1165
1166
  config['offline'] = device.offline;
1166
1167
  }
1167
1168
  if (Object.entries(config).length !== 0) {
1168
- this.infoLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1169
+ this.infoLog(`Bot: ${this.accessory.displayName} Config: ${superStringify(config)}`);
1169
1170
  }
1170
1171
  }
1171
1172
 
@@ -5,7 +5,7 @@ import { IncomingMessage } from 'http';
5
5
  import superStringify from 'super-stringify';
6
6
  import { interval, Subject } from 'rxjs';
7
7
  import { SwitchBotPlatform } from '../platform';
8
- import { debounceTime, skipWhile, tap } from 'rxjs/operators';
8
+ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
9
9
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
10
10
  import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, HostDomain, DevicePath } from '../settings';
11
11
 
@@ -211,11 +211,18 @@ export class ColorBulb {
211
211
  } catch (e: any) {
212
212
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
213
213
  if (this.deviceLogging.includes('debug')) {
214
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
214
+ this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
215
215
  }
216
216
  this.apiError(e);
217
217
  }
218
218
  this.colorBulbUpdateInProgress = false;
219
+ // Refresh the status from the API
220
+ interval(15000)
221
+ .pipe(skipWhile(() => this.colorBulbUpdateInProgress))
222
+ .pipe(take(1))
223
+ .subscribe(async () => {
224
+ await this.refreshStatus();
225
+ });
219
226
  });
220
227
  }
221
228
 
@@ -256,14 +263,14 @@ export class ColorBulb {
256
263
 
257
264
  // Color, Hue & Brightness
258
265
  if (this.color) {
259
- this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
266
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${superStringify(this.color)}`);
260
267
  const [red, green, blue] = this.color!.split(':');
261
- this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
262
- this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
263
- this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
268
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${superStringify(red)}`);
269
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${superStringify(green)}`);
270
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${superStringify(blue)}`);
264
271
 
265
272
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
266
- this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
273
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${superStringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
267
274
 
268
275
  // Hue
269
276
  this.Hue = hue;
@@ -321,7 +328,7 @@ export class ColorBulb {
321
328
  this.infoLog(`Color Bulb: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
322
329
  this.infoLog(`Color Bulb: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
323
330
  }
324
- this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
331
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
325
332
  this.serviceData = ad.serviceData;
326
333
  //this.state = ad.serviceData.state;
327
334
  //this.delay = ad.serviceData.delay;
@@ -330,7 +337,7 @@ export class ColorBulb {
330
337
  //this.wifiRssi = ad.serviceData.wifiRssi;
331
338
  //this.overload = ad.serviceData.overload;
332
339
  //this.currentPower = ad.serviceData.currentPower;
333
- this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
340
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
334
341
  /*this.debugLog(
335
342
  `Color Bulb: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
336
343
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
@@ -367,7 +374,7 @@ export class ColorBulb {
367
374
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
368
375
  if (this.deviceLogging.includes('debug')) {
369
376
  this.errorLog(
370
- `Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
377
+ `Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
371
378
  );
372
379
  }
373
380
  if (this.platform.config.credentials?.token) {
@@ -392,7 +399,7 @@ export class ColorBulb {
392
399
  });
393
400
  // Set an event handler
394
401
  switchbot.onadvertisement = (ad: any) => {
395
- this.warnLog(`Color Bulb: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
402
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
396
403
  };
397
404
  await switchbot.wait(10000);
398
405
  // Stop to monitor
@@ -441,7 +448,7 @@ export class ColorBulb {
441
448
  res.on('end', () => {
442
449
  try {
443
450
  this.deviceStatus = JSON.parse(rawData);
444
- this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
451
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
445
452
  this.power = this.deviceStatus.body.power;
446
453
  this.color = this.deviceStatus.body.color;
447
454
  this.brightness = this.deviceStatus.body.brightness;
@@ -461,7 +468,7 @@ export class ColorBulb {
461
468
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
462
469
  if (this.deviceLogging.includes('debug')) {
463
470
  this.errorLog(
464
- `Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
471
+ `Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
465
472
  );
466
473
  }
467
474
  this.apiError(e);
@@ -498,7 +505,7 @@ export class ColorBulb {
498
505
  } else {
499
506
  command = 'turnOff';
500
507
  }
501
- const body = JSON.stringify({
508
+ const body = superStringify({
502
509
  'command': `${command}`,
503
510
  'parameter': 'default',
504
511
  'commandType': 'command',
@@ -550,7 +557,7 @@ export class ColorBulb {
550
557
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
551
558
  if (this.deviceLogging.includes('debug')) {
552
559
  this.errorLog(
553
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
560
+ `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
554
561
  );
555
562
  }
556
563
  this.apiError(e);
@@ -560,11 +567,11 @@ export class ColorBulb {
560
567
  async pushHueSaturationChanges(): Promise<void> {
561
568
  try {
562
569
  if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
563
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
564
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
570
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
571
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
565
572
 
566
573
  const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
567
- this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
574
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
568
575
 
569
576
  // Make Push Hue/Saturation request to the API
570
577
  const t = Date.now();
@@ -575,7 +582,7 @@ export class ColorBulb {
575
582
  .digest();
576
583
  const sign = signTerm.toString('base64');
577
584
  this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
578
- const body = JSON.stringify({
585
+ const body = superStringify({
579
586
  'command': 'setColor',
580
587
  'parameter': `${red}:${green}:${blue}`,
581
588
  'commandType': 'command',
@@ -618,7 +625,7 @@ export class ColorBulb {
618
625
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
619
626
  if (this.deviceLogging.includes('debug')) {
620
627
  this.errorLog(
621
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
628
+ `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
622
629
  );
623
630
  }
624
631
  this.apiError(e);
@@ -640,7 +647,7 @@ export class ColorBulb {
640
647
  .digest();
641
648
  const sign = signTerm.toString('base64');
642
649
  this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
643
- const body = JSON.stringify({
650
+ const body = superStringify({
644
651
  'command': 'setColorTemperature',
645
652
  'parameter': `${kelvin}`,
646
653
  'commandType': 'command',
@@ -684,7 +691,7 @@ export class ColorBulb {
684
691
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
685
692
  if (this.deviceLogging.includes('debug')) {
686
693
  this.errorLog(
687
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
694
+ `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
688
695
  );
689
696
  }
690
697
  this.apiError(e);
@@ -703,7 +710,7 @@ export class ColorBulb {
703
710
  .digest();
704
711
  const sign = signTerm.toString('base64');
705
712
  this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
706
- const body = JSON.stringify({
713
+ const body = superStringify({
707
714
  'command': 'setBrightness',
708
715
  'parameter': `${this.Brightness}`,
709
716
  'commandType': 'command',
@@ -745,7 +752,7 @@ export class ColorBulb {
745
752
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
746
753
  if (this.deviceLogging.includes('debug')) {
747
754
  this.errorLog(
748
- `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
755
+ `Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
749
756
  );
750
757
  }
751
758
  this.apiError(e);
@@ -822,7 +829,7 @@ export class ColorBulb {
822
829
  case 190:
823
830
  this.errorLog(
824
831
  `Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
825
- ` Or command: ${JSON.stringify(res)} format is invalid`,
832
+ ` Or command: ${superStringify(res)} format is invalid`,
826
833
  );
827
834
  break;
828
835
  case 100:
@@ -934,7 +941,7 @@ export class ColorBulb {
934
941
  config['offline'] = device.offline;
935
942
  }
936
943
  if (Object.entries(config).length !== 0) {
937
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
944
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Config: ${superStringify(config)}`);
938
945
  }
939
946
  }
940
947
 
@@ -3,6 +3,7 @@ import crypto from 'crypto';
3
3
  import { Context } from 'vm';
4
4
  import { interval, Subject } from 'rxjs';
5
5
  import { skipWhile } from 'rxjs/operators';
6
+ import superStringify from 'super-stringify';
6
7
  import { SwitchBotPlatform } from '../platform';
7
8
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
8
9
  import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings';
@@ -298,7 +299,7 @@ export class Contact {
298
299
  this.doorState = ad.serviceData.doorState;
299
300
  this.lightLevel = ad.serviceData.lightLevel;
300
301
  this.battery = ad.serviceData.battery;
301
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
302
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
302
303
  this.debugLog(
303
304
  `Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
304
305
  `${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
@@ -330,7 +331,7 @@ export class Contact {
330
331
  if (this.deviceLogging.includes('debug')) {
331
332
  this.errorLog(
332
333
  `Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
333
- ` Error Message: ${JSON.stringify(e.message)}`,
334
+ ` Error Message: ${superStringify(e.message)}`,
334
335
  );
335
336
  }
336
337
  if (this.platform.config.credentials?.token) {
@@ -354,7 +355,7 @@ export class Contact {
354
355
  });
355
356
  // Set an event handler
356
357
  switchbot.onadvertisement = (ad: any) => {
357
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
358
+ this.warnLog(`Contact Sensor: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
358
359
  };
359
360
  await switchbot.wait(10000);
360
361
  // Stop to monitor
@@ -405,7 +406,7 @@ export class Contact {
405
406
  res.on('end', () => {
406
407
  try {
407
408
  this.deviceStatus = JSON.parse(rawData);
408
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
409
+ this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
409
410
  this.openState = this.deviceStatus.body.openState;
410
411
  this.moveDetected = this.deviceStatus.body.moveDetected;
411
412
  this.brightness = this.deviceStatus.body.brightness;
@@ -425,7 +426,7 @@ export class Contact {
425
426
  if (this.deviceLogging.includes('debug')) {
426
427
  this.errorLog(
427
428
  `Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
428
- ` Error Message: ${JSON.stringify(e.message)}`,
429
+ ` Error Message: ${superStringify(e.message)}`,
429
430
  );
430
431
  }
431
432
  this.apiError(e);
@@ -510,7 +511,7 @@ export class Contact {
510
511
  config['scanDuration'] = device.scanDuration;
511
512
  }
512
513
  if (Object.entries(config).length !== 0) {
513
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
514
+ this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config: ${superStringify(config)}`);
514
515
  }
515
516
  }
516
517
 
@@ -5,6 +5,7 @@ import { MqttClient } from 'mqtt';
5
5
  import { IncomingMessage } from 'http';
6
6
  import { interval, Subject } from 'rxjs';
7
7
  import { connectAsync } from 'async-mqtt';
8
+ import superStringify from 'super-stringify';
8
9
  import { SwitchBotPlatform } from '../platform';
9
10
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
10
11
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
@@ -202,7 +203,7 @@ export class Curtain {
202
203
  } catch (e: any) {
203
204
  this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges`);
204
205
  if (this.deviceLogging.includes('debug')) {
205
- this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
206
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
206
207
  }
207
208
  this.apiError(e);
208
209
  }
@@ -221,7 +222,7 @@ export class Curtain {
221
222
  ?.join(':');
222
223
  const options = this.device.mqttPubOptions || {};
223
224
  this.mqttClient?.publish(`homebridge-switchbot/curtain/${mac}/${topic}`, `${message}`, options);
224
- this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${JSON.stringify(options)}`);
225
+ this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${topic}/${message} options:${superStringify(options)}`);
225
226
  }
226
227
 
227
228
  /*
@@ -457,7 +458,7 @@ export class Curtain {
457
458
  this.battery = ad.serviceData.battery;
458
459
  this.position = ad.serviceData.position;
459
460
  this.lightLevel = ad.serviceData.lightLevel;
460
- this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
461
+ this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
461
462
  this.debugLog(
462
463
  `Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
463
464
  `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
@@ -493,7 +494,7 @@ export class Curtain {
493
494
  this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
494
495
  if (this.deviceLogging.includes('debug')) {
495
496
  this.errorLog(
496
- `Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
497
+ `Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
497
498
  );
498
499
  }
499
500
  if (this.platform.config.credentials?.token) {
@@ -517,7 +518,7 @@ export class Curtain {
517
518
  });
518
519
  // Set an event handler
519
520
  switchbot.onadvertisement = (ad: any) => {
520
- this.warnLog(`Curtain: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
521
+ this.warnLog(`Curtain: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
521
522
  };
522
523
  await switchbot.wait(10000);
523
524
  // Stop to monitor
@@ -569,7 +570,7 @@ export class Curtain {
569
570
  res.on('end', () => {
570
571
  try {
571
572
  this.deviceStatus = JSON.parse(rawData);
572
- this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
573
+ this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
573
574
  this.slidePosition = this.deviceStatus.body.slidePosition;
574
575
  this.moving = this.deviceStatus.body.moving;
575
576
  this.brightness = this.deviceStatus.body.brightness;
@@ -588,7 +589,7 @@ export class Curtain {
588
589
  this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
589
590
  if (this.deviceLogging.includes('debug')) {
590
591
  this.errorLog(
591
- `Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
592
+ `Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
592
593
  );
593
594
  }
594
595
  this.apiError(e);
@@ -655,7 +656,7 @@ export class Curtain {
655
656
  this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
656
657
  if (this.deviceLogging.includes('debug')) {
657
658
  this.errorLog(
658
- `Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
659
+ `Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
659
660
  );
660
661
  }
661
662
  if (this.platform.config.credentials?.token) {
@@ -709,7 +710,7 @@ export class Curtain {
709
710
  }
710
711
  this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
711
712
  const adjustedMode = this.setPositionMode || 'ff';
712
- const body = JSON.stringify({
713
+ const body = superStringify({
713
714
  'command': 'setPosition',
714
715
  'parameter': `0,${adjustedMode},${adjustedTargetPosition}`,
715
716
  'commandType': 'command',
@@ -741,7 +742,7 @@ export class Curtain {
741
742
  });
742
743
  req.write(body);
743
744
  req.end();
744
- this.debugLog(`Curtain: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
745
+ this.debugLog(`Curtain: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
745
746
  } else {
746
747
  this.debugLog(
747
748
  `Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
@@ -752,7 +753,7 @@ export class Curtain {
752
753
  this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
753
754
  if (this.deviceLogging.includes('debug')) {
754
755
  this.errorLog(
755
- `Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
756
+ `Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
756
757
  );
757
758
  }
758
759
  this.apiError(e);
@@ -844,7 +845,7 @@ export class Curtain {
844
845
  case 190:
845
846
  this.errorLog(
846
847
  `Curtain: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
847
- ` Or command: ${JSON.stringify(res)} format is invalid`,
848
+ ` Or command: ${superStringify(res)} format is invalid`,
848
849
  );
849
850
  break;
850
851
  case 100:
@@ -927,7 +928,7 @@ export class Curtain {
927
928
  config['scanDuration'] = device.scanDuration;
928
929
  }
929
930
  if (Object.entries(config).length !== 0) {
930
- this.infoLog(`Curtain: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
931
+ this.infoLog(`Curtain: ${this.accessory.displayName} Config: ${superStringify(config)}`);
931
932
  }
932
933
  }
933
934