@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
@@ -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
 
@@ -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, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
@@ -172,7 +173,7 @@ export class StripLight {
172
173
  } catch (e: any) {
173
174
  this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges`);
174
175
  if (this.deviceLogging.includes('debug')) {
175
- this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
176
+ this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
176
177
  }
177
178
  this.apiError(e);
178
179
  }
@@ -224,14 +225,14 @@ export class StripLight {
224
225
 
225
226
  // Color, Hue & Brightness
226
227
  if (this.color) {
227
- this.debugLog(`Strip Light: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
228
+ this.debugLog(`Strip Light: ${this.accessory.displayName} color: ${superStringify(this.color)}`);
228
229
  const [red, green, blue] = this.color!.split(':');
229
- this.debugLog(`Strip Light: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
230
- this.debugLog(`Strip Light: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
231
- this.debugLog(`Strip Light: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
230
+ this.debugLog(`Strip Light: ${this.accessory.displayName} red: ${superStringify(red)}`);
231
+ this.debugLog(`Strip Light: ${this.accessory.displayName} green: ${superStringify(green)}`);
232
+ this.debugLog(`Strip Light: ${this.accessory.displayName} blue: ${superStringify(blue)}`);
232
233
 
233
234
  const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
234
- this.debugLog(`Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
235
+ this.debugLog(`Strip Light: ${this.accessory.displayName} hs: ${superStringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
235
236
 
236
237
  // Hue
237
238
  this.Hue = hue;
@@ -278,7 +279,7 @@ export class StripLight {
278
279
  this.infoLog(`Strip Light: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
279
280
  this.infoLog(`Strip Light: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
280
281
  }
281
- this.errorLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
282
+ this.errorLog(`Strip Light: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
282
283
  this.serviceData = ad.serviceData;
283
284
  //this.state = ad.serviceData.state;
284
285
  //this.delay = ad.serviceData.delay;
@@ -287,7 +288,7 @@ export class StripLight {
287
288
  //this.wifiRssi = ad.serviceData.wifiRssi;
288
289
  //this.overload = ad.serviceData.overload;
289
290
  //this.currentPower = ad.serviceData.currentPower;
290
- this.debugLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
291
+ this.debugLog(`Strip Light: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
291
292
  /*this.debugLog(
292
293
  `Strip Light: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
293
294
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
@@ -324,7 +325,7 @@ export class StripLight {
324
325
  this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
325
326
  if (this.deviceLogging.includes('debug')) {
326
327
  this.errorLog(
327
- `Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
328
+ `Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
328
329
  );
329
330
  }
330
331
  if (this.platform.config.credentials?.token) {
@@ -349,7 +350,7 @@ export class StripLight {
349
350
  });
350
351
  // Set an event handler
351
352
  switchbot.onadvertisement = (ad: any) => {
352
- this.warnLog(`Strip Light: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
353
+ this.warnLog(`Strip Light: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
353
354
  };
354
355
  await switchbot.wait(10000);
355
356
  // Stop to monitor
@@ -398,7 +399,7 @@ export class StripLight {
398
399
  res.on('end', () => {
399
400
  try {
400
401
  this.deviceStatus = JSON.parse(rawData);
401
- this.debugLog(`Strip Light: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
402
+ this.debugLog(`Strip Light: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
402
403
  this.power = this.deviceStatus.body.power;
403
404
  this.color = this.deviceStatus.body.color;
404
405
  this.brightness = this.deviceStatus.body.brightness;
@@ -417,7 +418,7 @@ export class StripLight {
417
418
  this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
418
419
  if (this.deviceLogging.includes('debug')) {
419
420
  this.errorLog(
420
- `Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
421
+ `Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
421
422
  );
422
423
  }
423
424
  this.apiError(e);
@@ -453,7 +454,7 @@ export class StripLight {
453
454
  } else {
454
455
  command = 'turnOff';
455
456
  }
456
- const body = JSON.stringify({
457
+ const body = superStringify({
457
458
  'command': `${command}`,
458
459
  'parameter': 'default',
459
460
  'commandType': 'command',
@@ -485,7 +486,7 @@ export class StripLight {
485
486
  });
486
487
  req.write(body);
487
488
  req.end();
488
- this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
489
+ this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
489
490
  }
490
491
  // Push Brightness Update
491
492
  if (this.On) {
@@ -500,7 +501,7 @@ export class StripLight {
500
501
  this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
501
502
  if (this.deviceLogging.includes('debug')) {
502
503
  this.errorLog(
503
- `Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
504
+ `Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
504
505
  );
505
506
  }
506
507
  this.apiError(e);
@@ -510,11 +511,11 @@ export class StripLight {
510
511
  async pushHueSaturationChanges(): Promise<void> {
511
512
  try {
512
513
  if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
513
- this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
514
- this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
514
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
515
+ this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
515
516
 
516
517
  const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
517
- this.debugLog(`Strip Light: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
518
+ this.debugLog(`Strip Light: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
518
519
  // Make Push On request to the API
519
520
  const t = Date.now();
520
521
  const nonce = 'requestID';
@@ -524,7 +525,7 @@ export class StripLight {
524
525
  .digest();
525
526
  const sign = signTerm.toString('base64');
526
527
  this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
527
- const body = JSON.stringify({
528
+ const body = superStringify({
528
529
  'command': 'setColor',
529
530
  'parameter': `${red}:${green}:${blue}`,
530
531
  'commandType': 'command',
@@ -556,7 +557,7 @@ export class StripLight {
556
557
  });
557
558
  req.write(body);
558
559
  req.end();
559
- this.debugLog(`Strip Light: ${this.accessory.displayName} pushHueSaturationChanges: ${JSON.stringify(req)}`);
560
+ this.debugLog(`Strip Light: ${this.accessory.displayName} pushHueSaturationChanges: ${superStringify(req)}`);
560
561
  } else {
561
562
  this.debugLog(
562
563
  `Strip Light: ${this.accessory.displayName} No Changes.` +
@@ -569,7 +570,7 @@ export class StripLight {
569
570
  if (this.deviceLogging.includes('debug')) {
570
571
  this.errorLog(
571
572
  `Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection,`
572
- + ` Error Message: ${JSON.stringify(e.message)}`,
573
+ + ` Error Message: ${superStringify(e.message)}`,
573
574
  );
574
575
  }
575
576
  this.apiError(e);
@@ -588,7 +589,7 @@ export class StripLight {
588
589
  .digest();
589
590
  const sign = signTerm.toString('base64');
590
591
  this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
591
- const body = JSON.stringify({
592
+ const body = superStringify({
592
593
  'command': 'setBrightness',
593
594
  'parameter': `${this.Brightness}`,
594
595
  'commandType': 'command',
@@ -620,7 +621,7 @@ export class StripLight {
620
621
  });
621
622
  req.write(body);
622
623
  req.end();
623
- this.debugLog(`Strip Light: ${this.accessory.displayName} pushBrightnessChanges: ${JSON.stringify(req)}`);
624
+ this.debugLog(`Strip Light: ${this.accessory.displayName} pushBrightnessChanges: ${superStringify(req)}`);
624
625
  } else {
625
626
  this.debugLog(
626
627
  `Strip Light: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, `
@@ -632,7 +633,7 @@ export class StripLight {
632
633
  if (this.deviceLogging.includes('debug')) {
633
634
  this.errorLog(
634
635
  `Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection,`
635
- + ` Error Message: ${JSON.stringify(e.message)}`,
636
+ + ` Error Message: ${superStringify(e.message)}`,
636
637
  );
637
638
  }
638
639
  this.apiError(e);
@@ -700,7 +701,7 @@ export class StripLight {
700
701
  case 190:
701
702
  this.errorLog(
702
703
  `Strip Light: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
703
- ` Or command: ${JSON.stringify(res)} format is invalid`,
704
+ ` Or command: ${superStringify(res)} format is invalid`,
704
705
  );
705
706
  break;
706
707
  case 100:
@@ -783,7 +784,7 @@ export class StripLight {
783
784
  config['offline'] = device.offline;
784
785
  }
785
786
  if (Object.entries(config).length !== 0) {
786
- this.infoLog(`Strip Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
787
+ this.infoLog(`Strip Light: ${this.accessory.displayName} Config: ${superStringify(config)}`);
787
788
  }
788
789
  }
789
790
 
@@ -1,6 +1,7 @@
1
1
  import https from 'https';
2
2
  import crypto from 'crypto';
3
3
  import { IncomingMessage } from 'http';
4
+ import superStringify from 'super-stringify';
4
5
  import { SwitchBotPlatform } from '../platform';
5
6
  import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
6
7
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
@@ -110,14 +111,14 @@ export class AirConditioner {
110
111
  this.TargetHeaterCoolerState = 1 || 2;
111
112
  this.ValidValues = [1, 2];
112
113
  this.debugLog(
113
- `Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},` +
114
+ `Air Conditioner: ${this.accessory.displayName} ValidValues: ${superStringify(this.ValidValues)},` +
114
115
  ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
115
116
  );
116
117
  } else {
117
118
  this.TargetHeaterCoolerState = 0 || 1 || 2;
118
119
  this.ValidValues = [0, 1, 2];
119
120
  this.debugLog(
120
- `Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},` +
121
+ `Air Conditioner: ${this.accessory.displayName} ValidValues: ${superStringify(this.ValidValues)},` +
121
122
  ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
122
123
  );
123
124
  }
@@ -183,7 +184,7 @@ export class AirConditioner {
183
184
  */
184
185
  async pushAirConditionerOnChanges(): Promise<void> {
185
186
  if (this.Active !== this.platform.Characteristic.Active.ACTIVE || this.pushOn) {
186
- const body = JSON.stringify({
187
+ const body = superStringify({
187
188
  'command': 'turnOn',
188
189
  'parameter': 'default',
189
190
  'commandType': 'command',
@@ -193,7 +194,7 @@ export class AirConditioner {
193
194
  }
194
195
 
195
196
  async pushAirConditionerOffChanges(): Promise<void> {
196
- const body = JSON.stringify({
197
+ const body = superStringify({
197
198
  'command': 'turnOff',
198
199
  'parameter': 'default',
199
200
  'commandType': 'command',
@@ -243,7 +244,7 @@ export class AirConditioner {
243
244
  } else {
244
245
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
245
246
  }
246
- const body = JSON.stringify({
247
+ const body = superStringify({
247
248
  'command': 'setAll',
248
249
  'parameter': `${parameter}`,
249
250
  'commandType': 'command',
@@ -290,7 +291,7 @@ export class AirConditioner {
290
291
  });
291
292
  req.write(body);
292
293
  req.end();
293
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
294
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
294
295
  this.CurrentTemperatureCached = this.CurrentTemperature;
295
296
  this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
296
297
  this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
@@ -303,7 +304,7 @@ export class AirConditioner {
303
304
  } catch (e: any) {
304
305
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
305
306
  if (this.deviceLogging.includes('debug')) {
306
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
307
+ this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
307
308
  }
308
309
  this.apiError(e);
309
310
  }
@@ -329,7 +330,7 @@ export class AirConditioner {
329
330
  case 190:
330
331
  this.errorLog(
331
332
  `Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
332
- ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
333
+ ` with server, Or command: ${superStringify(res)} format is invalid`,
333
334
  );
334
335
  break;
335
336
  case 100:
@@ -620,7 +621,7 @@ export class AirConditioner {
620
621
  config['logging'] = device.logging;
621
622
  }
622
623
  if (Object.entries(config).length !== 0) {
623
- this.infoLog(`Air Conditioner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
624
+ this.infoLog(`Air Conditioner: ${this.accessory.displayName} Config: ${superStringify(config)}`);
624
625
  }
625
626
  }
626
627