@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
@@ -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
 
@@ -6,6 +6,7 @@ import { MqttClient } from 'mqtt';
6
6
  import { connectAsync } from 'async-mqtt';
7
7
  import { interval, Subject } from 'rxjs';
8
8
  import { skipWhile } from 'rxjs/operators';
9
+ import superStringify from 'super-stringify';
9
10
  import { SwitchBotPlatform } from '../platform';
10
11
  import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
11
12
  import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings';
@@ -187,7 +188,7 @@ export class Meter {
187
188
  ?.join(':');
188
189
  const options = this.device.mqttPubOptions || {};
189
190
  this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
190
- this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
191
+ this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${superStringify(options)}`);
191
192
  }
192
193
 
193
194
  /*
@@ -327,10 +328,10 @@ export class Meter {
327
328
  this.humidity = ad.serviceData.humidity;
328
329
  this.battery = ad.serviceData.battery;
329
330
  }
330
- this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
331
+ this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
331
332
  this.debugLog(
332
333
  `Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
333
- `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
334
+ `temperature: ${superStringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
334
335
  `battery: ${ad.serviceData.battery}`,
335
336
  );
336
337
 
@@ -359,7 +360,7 @@ export class Meter {
359
360
  this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
360
361
  if (this.deviceLogging.includes('debug')) {
361
362
  this.errorLog(
362
- `Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
363
+ `Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
363
364
  );
364
365
  }
365
366
  if (this.platform.config.credentials?.token) {
@@ -383,7 +384,7 @@ export class Meter {
383
384
  });
384
385
  // Set an event handler
385
386
  switchbot.onadvertisement = (ad: any) => {
386
- this.warnLog(`Meter: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
387
+ this.warnLog(`Meter: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
387
388
  };
388
389
  await switchbot.wait(10000);
389
390
  // Stop to monitor
@@ -434,7 +435,7 @@ export class Meter {
434
435
  res.on('end', () => {
435
436
  try {
436
437
  this.deviceStatus = JSON.parse(rawData);
437
- this.debugLog(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${JSON.stringify(this.deviceStatus)}`);
438
+ this.debugLog(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
438
439
  this.Humidity = this.deviceStatus.body.humidity!;
439
440
  this.Temperature = this.deviceStatus.body.temperature!;
440
441
  this.parseStatus();
@@ -452,7 +453,7 @@ export class Meter {
452
453
  this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
453
454
  if (this.deviceLogging.includes('debug')) {
454
455
  this.errorLog(
455
- `Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
456
+ `Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
456
457
  );
457
458
  }
458
459
  this.apiError(e);
@@ -541,7 +542,7 @@ export class Meter {
541
542
  config['scanDuration'] = device.scanDuration;
542
543
  }
543
544
  if (Object.entries(config).length !== 0) {
544
- this.infoLog(`Meter: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
545
+ this.infoLog(`Meter: ${this.accessory.displayName} Config: ${superStringify(config)}`);
545
546
  }
546
547
  }
547
548
 
@@ -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, Units, CharacteristicValue } from 'homebridge';
8
9
  import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings';
@@ -264,10 +265,10 @@ export class MeterPlus {
264
265
  this.temperature = ad.serviceData.temperature!.c;
265
266
  this.humidity = ad.serviceData.humidity;
266
267
  this.battery = ad.serviceData.battery;
267
- this.debugLog(`Meter Plus: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
268
+ this.debugLog(`Meter Plus: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
268
269
  this.debugLog(
269
270
  `Meter Plus: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
270
- `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
271
+ `temperature: ${superStringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
271
272
  `battery: ${ad.serviceData.battery}`,
272
273
  );
273
274
 
@@ -296,7 +297,7 @@ export class MeterPlus {
296
297
  this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
297
298
  if (this.deviceLogging.includes('debug')) {
298
299
  this.errorLog(
299
- `Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
300
+ `Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
300
301
  );
301
302
  }
302
303
  if (this.platform.config.credentials?.token) {
@@ -320,7 +321,7 @@ export class MeterPlus {
320
321
  });
321
322
  // Set an event handler
322
323
  switchbot.onadvertisement = (ad: any) => {
323
- this.warnLog(`Meter Plus: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
324
+ this.warnLog(`Meter Plus: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
324
325
  };
325
326
  await switchbot.wait(10000);
326
327
  // Stop to monitor
@@ -371,7 +372,7 @@ export class MeterPlus {
371
372
  res.on('end', () => {
372
373
  try {
373
374
  this.deviceStatus = JSON.parse(rawData);
374
- this.debugLog(`Meter Plus: ${this.accessory.displayName} openAPIRefreshStatus: ${JSON.stringify(this.deviceStatus)}`);
375
+ this.debugLog(`Meter Plus: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
375
376
  this.Humidity = this.deviceStatus.body.humidity!;
376
377
  this.Temperature = this.deviceStatus.body.temperature!;
377
378
  this.parseStatus();
@@ -390,7 +391,7 @@ export class MeterPlus {
390
391
  if (this.deviceLogging.includes('debug')) {
391
392
  this.errorLog(
392
393
  `Meter Plus: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
393
- ` Error Message: ${JSON.stringify(e.message)}`,
394
+ ` Error Message: ${superStringify(e.message)}`,
394
395
  );
395
396
  }
396
397
  this.apiError(e);
@@ -476,7 +477,7 @@ export class MeterPlus {
476
477
  config['scanDuration'] = device.scanDuration;
477
478
  }
478
479
  if (Object.entries(config).length !== 0) {
479
- this.infoLog(`Meter Plus: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
480
+ this.infoLog(`Meter Plus: ${this.accessory.displayName} Config: ${superStringify(config)}`);
480
481
  }
481
482
  }
482
483
 
@@ -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';
@@ -250,7 +251,7 @@ export class Motion {
250
251
  this.movement = ad.serviceData.movement;
251
252
  this.battery = ad.serviceData.battery;
252
253
  this.lightLevel = ad.serviceData.lightLevel;
253
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
254
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
254
255
  this.debugLog(
255
256
  `Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: ` +
256
257
  `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
@@ -282,7 +283,7 @@ export class Motion {
282
283
  if (this.deviceLogging.includes('debug')) {
283
284
  this.errorLog(
284
285
  `Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
285
- ` Error Message: ${JSON.stringify(e.message)}`,
286
+ ` Error Message: ${superStringify(e.message)}`,
286
287
  );
287
288
  }
288
289
  if (this.platform.config.credentials?.token) {
@@ -306,7 +307,7 @@ export class Motion {
306
307
  });
307
308
  // Set an event handler
308
309
  switchbot.onadvertisement = (ad: any) => {
309
- this.warnLog(`Motion Sensor: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
310
+ this.warnLog(`Motion Sensor: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
310
311
  };
311
312
  await switchbot.wait(10000);
312
313
  // Stop to monitor
@@ -357,7 +358,7 @@ export class Motion {
357
358
  res.on('end', () => {
358
359
  try {
359
360
  this.deviceStatus = JSON.parse(rawData);
360
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
361
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
361
362
  this.moveDetected = this.deviceStatus.body.moveDetected;
362
363
  this.brightness = this.deviceStatus.body.brightness;
363
364
  this.parseStatus();
@@ -376,7 +377,7 @@ export class Motion {
376
377
  if (this.deviceLogging.includes('debug')) {
377
378
  this.errorLog(
378
379
  `Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
379
- ` Error Message: ${JSON.stringify(e.message)}`,
380
+ ` Error Message: ${superStringify(e.message)}`,
380
381
  );
381
382
  }
382
383
  this.apiError(e);
@@ -449,7 +450,7 @@ export class Motion {
449
450
  config['offline'] = device.offline;
450
451
  }
451
452
  if (Object.entries(config).length !== 0) {
452
- this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
453
+ this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config: ${superStringify(config)}`);
453
454
  }
454
455
  }
455
456
 
@@ -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';
@@ -115,7 +116,7 @@ export class Plug {
115
116
  } catch (e: any) {
116
117
  this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges`);
117
118
  if (this.deviceLogging.includes('debug')) {
118
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
119
+ this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
119
120
  }
120
121
  this.apiError(e);
121
122
  }
@@ -198,7 +199,7 @@ export class Plug {
198
199
  this.wifiRssi = ad.serviceData.wifiRssi;
199
200
  this.overload = ad.serviceData.overload;
200
201
  this.currentPower = ad.serviceData.currentPower;
201
- this.debugLog(`Plug: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
202
+ this.debugLog(`Plug: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
202
203
  this.debugLog(
203
204
  `Plug: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
204
205
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
@@ -230,7 +231,7 @@ export class Plug {
230
231
  this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
231
232
  if (this.deviceLogging.includes('debug')) {
232
233
  this.errorLog(
233
- `Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
234
+ `Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
234
235
  );
235
236
  }
236
237
  if (this.platform.config.credentials?.token) {
@@ -262,7 +263,7 @@ export class Plug {
262
263
  });
263
264
  // Set an event handler
264
265
  switchbot.onadvertisement = (ad: any) => {
265
- this.warnLog(`Plug: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
266
+ this.warnLog(`Plug: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
266
267
  };
267
268
  await switchbot.wait(10000);
268
269
  // Stop to monitor
@@ -311,7 +312,7 @@ export class Plug {
311
312
  res.on('end', () => {
312
313
  try {
313
314
  this.deviceStatus = JSON.parse(rawData);
314
- this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
315
+ this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
315
316
  this.power = this.deviceStatus.body.power;
316
317
  this.parseStatus();
317
318
  this.updateHomeKitCharacteristics();
@@ -328,7 +329,7 @@ export class Plug {
328
329
  this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
329
330
  if (this.deviceLogging.includes('debug')) {
330
331
  this.errorLog(
331
- `Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
332
+ `Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
332
333
  );
333
334
  }
334
335
  this.apiError(e);
@@ -380,11 +381,11 @@ export class Plug {
380
381
  this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
381
382
  if (this.deviceLogging.includes('debug')) {
382
383
  this.errorLog(
383
- `Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
384
+ `Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
384
385
  );
385
386
  }
386
387
  if (this.platform.debugMode) {
387
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
388
+ this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${superStringify(e)}`);
388
389
  }
389
390
  if (this.platform.config.credentials?.token) {
390
391
  this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -427,7 +428,7 @@ export class Plug {
427
428
  } else {
428
429
  command = 'turnOff';
429
430
  }
430
- const body = JSON.stringify({
431
+ const body = superStringify({
431
432
  'command': `${command}`,
432
433
  'parameter': 'default',
433
434
  'commandType': 'command',
@@ -459,7 +460,7 @@ export class Plug {
459
460
  });
460
461
  req.write(body);
461
462
  req.end();
462
- this.debugLog(`Plug: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
463
+ this.debugLog(`Plug: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
463
464
  }
464
465
  interval(5000)
465
466
  .pipe(take(1))
@@ -506,7 +507,7 @@ export class Plug {
506
507
  case 190:
507
508
  this.errorLog(
508
509
  `Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
509
- ` Or command: ${JSON.stringify(res)} format is invalid`,
510
+ ` Or command: ${superStringify(res)} format is invalid`,
510
511
  );
511
512
  break;
512
513
  case 100:
@@ -589,7 +590,7 @@ export class Plug {
589
590
  config['offline'] = device.offline;
590
591
  }
591
592
  if (Object.entries(config).length !== 0) {
592
- this.infoLog(`Plug: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
593
+ this.infoLog(`Plug: ${this.accessory.displayName} Config: ${superStringify(config)}`);
593
594
  }
594
595
  }
595
596