@switchbot/homebridge-switchbot 2.0.0-beta.13 → 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 (84) 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.js +25 -25
  5. package/dist/device/colorbulb.js.map +1 -1
  6. package/dist/device/contact.d.ts.map +1 -1
  7. package/dist/device/contact.js +7 -6
  8. package/dist/device/contact.js.map +1 -1
  9. package/dist/device/curtain.d.ts.map +1 -1
  10. package/dist/device/curtain.js +14 -13
  11. package/dist/device/curtain.js.map +1 -1
  12. package/dist/device/humidifier.d.ts.map +1 -1
  13. package/dist/device/humidifier.js +18 -17
  14. package/dist/device/humidifier.js.map +1 -1
  15. package/dist/device/lock.d.ts.map +1 -1
  16. package/dist/device/lock.js +8 -7
  17. package/dist/device/lock.js.map +1 -1
  18. package/dist/device/meter.d.ts.map +1 -1
  19. package/dist/device/meter.js +9 -8
  20. package/dist/device/meter.js.map +1 -1
  21. package/dist/device/meterplus.d.ts.map +1 -1
  22. package/dist/device/meterplus.js +8 -7
  23. package/dist/device/meterplus.js.map +1 -1
  24. package/dist/device/motion.d.ts.map +1 -1
  25. package/dist/device/motion.js +7 -6
  26. package/dist/device/motion.js.map +1 -1
  27. package/dist/device/plug.d.ts.map +1 -1
  28. package/dist/device/plug.js +13 -12
  29. package/dist/device/plug.js.map +1 -1
  30. package/dist/device/striplight.d.ts.map +1 -1
  31. package/dist/device/striplight.js +27 -26
  32. package/dist/device/striplight.js.map +1 -1
  33. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  34. package/dist/irdevice/airconditioner.js +10 -9
  35. package/dist/irdevice/airconditioner.js.map +1 -1
  36. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  37. package/dist/irdevice/airpurifier.js +8 -7
  38. package/dist/irdevice/airpurifier.js.map +1 -1
  39. package/dist/irdevice/camera.d.ts.map +1 -1
  40. package/dist/irdevice/camera.js +7 -6
  41. package/dist/irdevice/camera.js.map +1 -1
  42. package/dist/irdevice/fan.d.ts.map +1 -1
  43. package/dist/irdevice/fan.js +10 -9
  44. package/dist/irdevice/fan.js.map +1 -1
  45. package/dist/irdevice/light.d.ts.map +1 -1
  46. package/dist/irdevice/light.js +9 -8
  47. package/dist/irdevice/light.js.map +1 -1
  48. package/dist/irdevice/other.d.ts.map +1 -1
  49. package/dist/irdevice/other.js +7 -6
  50. package/dist/irdevice/other.js.map +1 -1
  51. package/dist/irdevice/tv.d.ts.map +1 -1
  52. package/dist/irdevice/tv.js +16 -15
  53. package/dist/irdevice/tv.js.map +1 -1
  54. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  55. package/dist/irdevice/vacuumcleaner.js +7 -6
  56. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  57. package/dist/irdevice/waterheater.d.ts.map +1 -1
  58. package/dist/irdevice/waterheater.js +7 -6
  59. package/dist/irdevice/waterheater.js.map +1 -1
  60. package/dist/platform.d.ts.map +1 -1
  61. package/dist/platform.js +24 -23
  62. package/dist/platform.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/device/bot.ts +19 -18
  65. package/src/device/colorbulb.ts +25 -25
  66. package/src/device/contact.ts +7 -6
  67. package/src/device/curtain.ts +14 -13
  68. package/src/device/humidifier.ts +18 -17
  69. package/src/device/lock.ts +8 -7
  70. package/src/device/meter.ts +9 -8
  71. package/src/device/meterplus.ts +8 -7
  72. package/src/device/motion.ts +7 -6
  73. package/src/device/plug.ts +13 -12
  74. package/src/device/striplight.ts +27 -26
  75. package/src/irdevice/airconditioner.ts +10 -9
  76. package/src/irdevice/airpurifier.ts +8 -7
  77. package/src/irdevice/camera.ts +7 -6
  78. package/src/irdevice/fan.ts +10 -9
  79. package/src/irdevice/light.ts +9 -8
  80. package/src/irdevice/other.ts +7 -6
  81. package/src/irdevice/tv.ts +16 -15
  82. package/src/irdevice/vacuumcleaner.ts +7 -6
  83. package/src/irdevice/waterheater.ts +7 -6
  84. package/src/platform.ts +24 -23
@@ -211,7 +211,7 @@ 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
  }
@@ -263,14 +263,14 @@ export class ColorBulb {
263
263
 
264
264
  // Color, Hue & Brightness
265
265
  if (this.color) {
266
- this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
266
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${superStringify(this.color)}`);
267
267
  const [red, green, blue] = this.color!.split(':');
268
- this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
269
- this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
270
- 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)}`);
271
271
 
272
272
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
273
- 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)))}`);
274
274
 
275
275
  // Hue
276
276
  this.Hue = hue;
@@ -328,7 +328,7 @@ export class ColorBulb {
328
328
  this.infoLog(`Color Bulb: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
329
329
  this.infoLog(`Color Bulb: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
330
330
  }
331
- this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
331
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
332
332
  this.serviceData = ad.serviceData;
333
333
  //this.state = ad.serviceData.state;
334
334
  //this.delay = ad.serviceData.delay;
@@ -337,7 +337,7 @@ export class ColorBulb {
337
337
  //this.wifiRssi = ad.serviceData.wifiRssi;
338
338
  //this.overload = ad.serviceData.overload;
339
339
  //this.currentPower = ad.serviceData.currentPower;
340
- this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
340
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
341
341
  /*this.debugLog(
342
342
  `Color Bulb: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
343
343
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
@@ -374,7 +374,7 @@ export class ColorBulb {
374
374
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
375
375
  if (this.deviceLogging.includes('debug')) {
376
376
  this.errorLog(
377
- `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)}`,
378
378
  );
379
379
  }
380
380
  if (this.platform.config.credentials?.token) {
@@ -399,7 +399,7 @@ export class ColorBulb {
399
399
  });
400
400
  // Set an event handler
401
401
  switchbot.onadvertisement = (ad: any) => {
402
- this.warnLog(`Color Bulb: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
402
+ this.warnLog(`Color Bulb: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
403
403
  };
404
404
  await switchbot.wait(10000);
405
405
  // Stop to monitor
@@ -448,7 +448,7 @@ export class ColorBulb {
448
448
  res.on('end', () => {
449
449
  try {
450
450
  this.deviceStatus = JSON.parse(rawData);
451
- this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
451
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
452
452
  this.power = this.deviceStatus.body.power;
453
453
  this.color = this.deviceStatus.body.color;
454
454
  this.brightness = this.deviceStatus.body.brightness;
@@ -468,7 +468,7 @@ export class ColorBulb {
468
468
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
469
469
  if (this.deviceLogging.includes('debug')) {
470
470
  this.errorLog(
471
- `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)}`,
472
472
  );
473
473
  }
474
474
  this.apiError(e);
@@ -505,7 +505,7 @@ export class ColorBulb {
505
505
  } else {
506
506
  command = 'turnOff';
507
507
  }
508
- const body = JSON.stringify({
508
+ const body = superStringify({
509
509
  'command': `${command}`,
510
510
  'parameter': 'default',
511
511
  'commandType': 'command',
@@ -557,7 +557,7 @@ export class ColorBulb {
557
557
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
558
558
  if (this.deviceLogging.includes('debug')) {
559
559
  this.errorLog(
560
- `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)}`,
561
561
  );
562
562
  }
563
563
  this.apiError(e);
@@ -567,11 +567,11 @@ export class ColorBulb {
567
567
  async pushHueSaturationChanges(): Promise<void> {
568
568
  try {
569
569
  if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
570
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
571
- 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)}`);
572
572
 
573
573
  const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
574
- 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])}`);
575
575
 
576
576
  // Make Push Hue/Saturation request to the API
577
577
  const t = Date.now();
@@ -582,7 +582,7 @@ export class ColorBulb {
582
582
  .digest();
583
583
  const sign = signTerm.toString('base64');
584
584
  this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
585
- const body = JSON.stringify({
585
+ const body = superStringify({
586
586
  'command': 'setColor',
587
587
  'parameter': `${red}:${green}:${blue}`,
588
588
  'commandType': 'command',
@@ -625,7 +625,7 @@ export class ColorBulb {
625
625
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
626
626
  if (this.deviceLogging.includes('debug')) {
627
627
  this.errorLog(
628
- `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)}`,
629
629
  );
630
630
  }
631
631
  this.apiError(e);
@@ -647,7 +647,7 @@ export class ColorBulb {
647
647
  .digest();
648
648
  const sign = signTerm.toString('base64');
649
649
  this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
650
- const body = JSON.stringify({
650
+ const body = superStringify({
651
651
  'command': 'setColorTemperature',
652
652
  'parameter': `${kelvin}`,
653
653
  'commandType': 'command',
@@ -691,7 +691,7 @@ export class ColorBulb {
691
691
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
692
692
  if (this.deviceLogging.includes('debug')) {
693
693
  this.errorLog(
694
- `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)}`,
695
695
  );
696
696
  }
697
697
  this.apiError(e);
@@ -710,7 +710,7 @@ export class ColorBulb {
710
710
  .digest();
711
711
  const sign = signTerm.toString('base64');
712
712
  this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
713
- const body = JSON.stringify({
713
+ const body = superStringify({
714
714
  'command': 'setBrightness',
715
715
  'parameter': `${this.Brightness}`,
716
716
  'commandType': 'command',
@@ -752,7 +752,7 @@ export class ColorBulb {
752
752
  this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
753
753
  if (this.deviceLogging.includes('debug')) {
754
754
  this.errorLog(
755
- `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)}`,
756
756
  );
757
757
  }
758
758
  this.apiError(e);
@@ -829,7 +829,7 @@ export class ColorBulb {
829
829
  case 190:
830
830
  this.errorLog(
831
831
  `Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
832
- ` Or command: ${JSON.stringify(res)} format is invalid`,
832
+ ` Or command: ${superStringify(res)} format is invalid`,
833
833
  );
834
834
  break;
835
835
  case 100:
@@ -941,7 +941,7 @@ export class ColorBulb {
941
941
  config['offline'] = device.offline;
942
942
  }
943
943
  if (Object.entries(config).length !== 0) {
944
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
944
+ this.infoLog(`Color Bulb: ${this.accessory.displayName} Config: ${superStringify(config)}`);
945
945
  }
946
946
  }
947
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
 
@@ -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';
@@ -183,7 +184,7 @@ export class Humidifier {
183
184
  } catch (e: any) {
184
185
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
185
186
  if (this.deviceLogging.includes('debug')) {
186
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
187
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
187
188
  }
188
189
  this.apiError(e);
189
190
  }
@@ -315,7 +316,7 @@ export class Humidifier {
315
316
  this.autoMode = ad.serviceData.autoMode;
316
317
  this.onState = ad.serviceData.onState;
317
318
  this.percentage = ad.serviceData.percentage;
318
- this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
319
+ this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
319
320
  this.debugLog(
320
321
  `Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
321
322
  `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
@@ -346,7 +347,7 @@ export class Humidifier {
346
347
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
347
348
  if (this.deviceLogging.includes('debug')) {
348
349
  this.errorLog(
349
- `Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
350
+ `Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
350
351
  );
351
352
  }
352
353
  if (this.platform.config.credentials?.token) {
@@ -369,7 +370,7 @@ export class Humidifier {
369
370
  });
370
371
  // Set an event handler
371
372
  switchbot.onadvertisement = (ad: any) => {
372
- this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
373
+ this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
373
374
  };
374
375
  await switchbot.wait(10000);
375
376
  // Stop to monitor
@@ -419,7 +420,7 @@ export class Humidifier {
419
420
  res.on('end', () => {
420
421
  try {
421
422
  this.deviceStatus = JSON.parse(rawData);
422
- this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
423
+ this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
423
424
  this.auto = this.deviceStatus.body.auto;
424
425
  this.power = this.deviceStatus.body.power;
425
426
  this.lackWater = this.deviceStatus.body.lackWater;
@@ -442,7 +443,7 @@ export class Humidifier {
442
443
  if (this.deviceLogging.includes('debug')) {
443
444
  this.errorLog(
444
445
  `Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
445
- ` Error Message: ${JSON.stringify(e.message)}`,
446
+ ` Error Message: ${superStringify(e.message)}`,
446
447
  );
447
448
  }
448
449
  this.apiError(e);
@@ -489,7 +490,7 @@ export class Humidifier {
489
490
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
490
491
  if (this.deviceLogging.includes('debug')) {
491
492
  this.errorLog(
492
- `Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
493
+ `Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
493
494
  );
494
495
  }
495
496
  if (this.platform.config.credentials?.token) {
@@ -524,7 +525,7 @@ export class Humidifier {
524
525
  const sign = signTerm.toString('base64');
525
526
  this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
526
527
  this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
527
- const body = JSON.stringify({
528
+ const body = superStringify({
528
529
  'command': 'setMode',
529
530
  'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
530
531
  'commandType': 'command',
@@ -556,7 +557,7 @@ export class Humidifier {
556
557
  });
557
558
  req.write(body);
558
559
  req.end();
559
- this.debugLog(`Humidifier: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
560
+ this.debugLog(`Humidifier: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
560
561
  } else if (
561
562
  this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
562
563
  this.Active === this.platform.Characteristic.Active.ACTIVE
@@ -587,7 +588,7 @@ export class Humidifier {
587
588
  const sign = signTerm.toString('base64');
588
589
  this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
589
590
  this.debugLog('Pushing Auto!');
590
- const body = JSON.stringify({
591
+ const body = superStringify({
591
592
  'command': 'setMode',
592
593
  'parameter': 'auto',
593
594
  'commandType': 'command',
@@ -619,14 +620,14 @@ export class Humidifier {
619
620
  });
620
621
  req.write(body);
621
622
  req.end();
622
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(req)}`);
623
+ this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${superStringify(req)}`);
623
624
  }
624
625
  } catch (e: any) {
625
626
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
626
627
  if (this.deviceLogging.includes('debug')) {
627
628
  this.errorLog(
628
629
  `Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
629
- ` Error Message: ${JSON.stringify(e.message)}`,
630
+ ` Error Message: ${superStringify(e.message)}`,
630
631
  );
631
632
  }
632
633
  this.apiError(e);
@@ -649,7 +650,7 @@ export class Humidifier {
649
650
  const sign = signTerm.toString('base64');
650
651
  this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
651
652
  this.debugLog('Pushing Off!');
652
- const body = JSON.stringify({
653
+ const body = superStringify({
653
654
  'command': 'turnOff',
654
655
  'parameter': 'default',
655
656
  'commandType': 'command',
@@ -681,14 +682,14 @@ export class Humidifier {
681
682
  });
682
683
  req.write(body);
683
684
  req.end();
684
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(req)}`);
685
+ this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${superStringify(req)}`);
685
686
  }
686
687
  } catch (e: any) {
687
688
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
688
689
  if (this.deviceLogging.includes('debug')) {
689
690
  this.errorLog(
690
691
  `Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
691
- ` Error Message: ${JSON.stringify(e.message)}`,
692
+ ` Error Message: ${superStringify(e.message)}`,
692
693
  );
693
694
  }
694
695
  this.apiError(e);
@@ -804,7 +805,7 @@ export class Humidifier {
804
805
  case 190:
805
806
  this.errorLog(
806
807
  `Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
807
- ` Or command: ${JSON.stringify(res)} format is invalid`,
808
+ ` Or command: ${superStringify(res)} format is invalid`,
808
809
  );
809
810
  break;
810
811
  case 100:
@@ -876,7 +877,7 @@ export class Humidifier {
876
877
  config['offline'] = device.offline;
877
878
  }
878
879
  if (Object.entries(config).length !== 0) {
879
- this.infoLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
880
+ this.infoLog(`Humidifier: ${this.accessory.displayName} Config: ${superStringify(config)}`);
880
881
  }
881
882
  }
882
883
 
@@ -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';
@@ -121,7 +122,7 @@ export class Lock {
121
122
  } catch (e: any) {
122
123
  this.errorLog(`Lock: ${this.accessory.displayName} failed pushChanges`);
123
124
  if (this.deviceLogging.includes('debug')) {
124
- this.errorLog(`Lock: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
125
+ this.errorLog(`Lock: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
125
126
  }
126
127
  this.apiError(e);
127
128
  }
@@ -182,7 +183,7 @@ export class Lock {
182
183
  res.on('end', () => {
183
184
  try {
184
185
  this.deviceStatus = JSON.parse(rawData);
185
- this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
186
+ this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
186
187
  this.lockState = this.deviceStatus.body.lockState;
187
188
  this.doorState = this.deviceStatus.body.doorState;
188
189
  this.parseStatus();
@@ -200,7 +201,7 @@ export class Lock {
200
201
  this.errorLog(`Lock: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
201
202
  if (this.deviceLogging.includes('debug')) {
202
203
  this.errorLog(
203
- `Lock: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
204
+ `Lock: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
204
205
  );
205
206
  }
206
207
  this.apiError(e);
@@ -229,7 +230,7 @@ export class Lock {
229
230
  } else {
230
231
  command = 'unlock';
231
232
  }
232
- const body = JSON.stringify({
233
+ const body = superStringify({
233
234
  'command': `${command}`,
234
235
  'parameter': 'default',
235
236
  'commandType': 'command',
@@ -261,7 +262,7 @@ export class Lock {
261
262
  });
262
263
  req.write(body);
263
264
  req.end();
264
- this.debugLog(`Lock: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
265
+ this.debugLog(`Lock: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
265
266
  this.accessory.context.On = this.LockTargetState;
266
267
  interval(5000)
267
268
  .pipe(take(1))
@@ -322,7 +323,7 @@ export class Lock {
322
323
  case 190:
323
324
  this.errorLog(
324
325
  `Lock: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
325
- ` Or command: ${JSON.stringify(res)} format is invalid`,
326
+ ` Or command: ${superStringify(res)} format is invalid`,
326
327
  );
327
328
  break;
328
329
  case 100:
@@ -361,7 +362,7 @@ export class Lock {
361
362
  config['scanDuration'] = device.scanDuration;
362
363
  }
363
364
  if (Object.entries(config).length !== 0) {
364
- this.infoLog(`Lock: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
365
+ this.infoLog(`Lock: ${this.accessory.displayName} Config: ${superStringify(config)}`);
365
366
  }
366
367
  }
367
368