@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
package/src/platform.ts CHANGED
@@ -22,6 +22,7 @@ import https from 'https';
22
22
  import crypto from 'crypto';
23
23
  import { Buffer } from 'buffer';
24
24
  import fakegato from 'fakegato-history';
25
+ import superStringify from 'super-stringify';
25
26
  import { readFileSync, writeFileSync } from 'fs';
26
27
  import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
27
28
  import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, DevicePath, HostDomain } from './settings';
@@ -65,9 +66,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
65
66
  this.verifyConfig();
66
67
  this.debugLog('Config OK');
67
68
  } catch (e: any) {
68
- this.errorLog(JSON.stringify(e.message));
69
+ this.errorLog(superStringify(e.message));
69
70
  if (this.platformLogging?.includes('debug')) {
70
- this.errorLog(JSON.stringify(e));
71
+ this.errorLog(superStringify(e));
71
72
  }
72
73
  return;
73
74
  }
@@ -89,9 +90,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
89
90
  this.discoverDevices();
90
91
  }
91
92
  } catch (e: any) {
92
- this.errorLog('Failed to Discover Devices.', JSON.stringify(e.message));
93
+ this.errorLog('Failed to Discover Devices.', superStringify(e.message));
93
94
  if (this.platformLogging?.includes('debug')) {
94
- this.errorLog(JSON.stringify(e));
95
+ this.errorLog(superStringify(e));
95
96
  }
96
97
  }
97
98
  });
@@ -145,7 +146,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
145
146
  platformConfig['pushRate'] = this.config.options.pushRate;
146
147
  }
147
148
  if (Object.entries(platformConfig).length !== 0) {
148
- this.infoLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
149
+ this.infoLog(`Platform Config: ${superStringify(platformConfig)}`);
149
150
  }
150
151
 
151
152
  if (this.config.options) {
@@ -263,7 +264,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
263
264
  this.warnLog(`Token: ${pluginConfig.credentials.token}`);
264
265
  }
265
266
  // save the config, ensuring we maintain pretty json
266
- writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
267
+ writeFileSync(this.api.user.configPath(), superStringify(currentConfig, null, 4));
267
268
  this.verifyConfig();
268
269
  } catch (e: any) {
269
270
  this.errorLog(e);
@@ -297,7 +298,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
297
298
  };
298
299
  const req = https.request(options, (res) => {
299
300
  this.debugLog(`statusCode: ${res.statusCode}`);
300
- this.debugLog(`headers: ${JSON.stringify(res.headers)}`);
301
+ this.debugLog(`headers: ${superStringify(res.headers)}`);
301
302
  let rawData = '';
302
303
  res.on('data', (d) => {
303
304
  rawData += d;
@@ -306,7 +307,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
306
307
  res.on('end', () => {
307
308
  try {
308
309
  const devicesAPI = JSON.parse(rawData);
309
- this.debugLog(`devicesAPI: ${JSON.stringify(devicesAPI.body)}`);
310
+ this.debugLog(`devicesAPI: ${superStringify(devicesAPI.body)}`);
310
311
 
311
312
  // SwitchBot Devices
312
313
  if (devicesAPI.body.deviceList.length !== 0) {
@@ -316,7 +317,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
316
317
  }
317
318
  const deviceLists = devicesAPI.body.deviceList;
318
319
  if (!this.config.options?.devices) {
319
- this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
320
+ this.debugLog(`SwitchBot Device Config Not Set: ${superStringify(this.config.options?.devices)}`);
320
321
  const devices = deviceLists.map((v: any) => v);
321
322
  for (const device of devices) {
322
323
  if (device.deviceType) {
@@ -327,7 +328,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
327
328
  }
328
329
  }
329
330
  } else if (this.config.credentials?.token && this.config.options.devices) {
330
- this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
331
+ this.debugLog(`SwitchBot Device Config Set: ${superStringify(this.config.options?.devices)}`);
331
332
  const deviceConfigs = this.config.options?.devices;
332
333
 
333
334
  const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
@@ -340,7 +341,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
340
341
  }));
341
342
 
342
343
  const devices = mergeBydeviceId(deviceLists, deviceConfigs);
343
- this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
344
+ this.debugLog(`SwitchBot Devices: ${superStringify(devices)}`);
344
345
  for (const device of devices) {
345
346
  if (device.deviceType) {
346
347
  if (device.configDeviceName) {
@@ -361,7 +362,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
361
362
  }
362
363
  const irDeviceLists = devicesAPI.body.infraredRemoteList;
363
364
  if (!this.config.options?.irdevices) {
364
- this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
365
+ this.debugLog(`IR Device Config Not Set: ${superStringify(this.config.options?.irdevices)}`);
365
366
  const devices = irDeviceLists.map((v: any) => v);
366
367
  for (const device of devices) {
367
368
  if (device.remoteType) {
@@ -369,7 +370,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
369
370
  }
370
371
  }
371
372
  } else {
372
- this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
373
+ this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
373
374
  const irDeviceConfig = this.config.options?.irdevices;
374
375
 
375
376
  const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
@@ -382,7 +383,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
382
383
  }));
383
384
 
384
385
  const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
385
- this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
386
+ this.debugLog(`IR Devices: ${superStringify(devices)}`);
386
387
  for (const device of devices) {
387
388
  if (device.remoteType) {
388
389
  this.createIRDevice(device);
@@ -399,7 +400,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
399
400
  });
400
401
  req.end();
401
402
  } else if (!this.config.credentials?.token && this.config.options?.devices) {
402
- this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
403
+ this.debugLog(`SwitchBot Device Manual Config Set: ${superStringify(this.config.options?.devices)}`);
403
404
  const deviceConfigs = this.config.options?.devices;
404
405
  const devices = deviceConfigs.map((v: any) => v);
405
406
  for (const device of devices) {
@@ -452,10 +453,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
452
453
  this.errorLog('Failed to Discover Devices');
453
454
  }
454
455
  if (this.platformLogging === 'debug') {
455
- this.errorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
456
+ this.errorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
456
457
  }
457
458
  if (this.platformLogging === 'debugMode') {
458
- this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
459
+ this.errorLog(`Failed to Discover Devices, Error: ${superStringify(e)}`);
459
460
  }
460
461
  }
461
462
 
@@ -659,7 +660,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
659
660
  if (this.registerDevice(device)) {
660
661
  this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
661
662
 
662
- this.debugLog(JSON.stringify(device.bot?.mode));
663
+ this.debugLog(superStringify(device.bot?.mode));
663
664
 
664
665
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
665
666
  existingAccessory.context.model = device.deviceType;
@@ -680,7 +681,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
680
681
  // the accessory does not yet exist, so we need to create it
681
682
  this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
682
683
 
683
- this.debugLog(JSON.stringify(device.bot?.mode));
684
+ this.debugLog(superStringify(device.bot?.mode));
684
685
 
685
686
  // create a new accessory
686
687
  const accessory = new this.api.platformAccessory(device.deviceName, uuid);
@@ -1787,13 +1788,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1787
1788
 
1788
1789
  public deviceListInfo(devices) {
1789
1790
  if (this.platformLogging?.includes('debug')) {
1790
- this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
1791
+ this.warnLog(`deviceListInfoStatus: ${superStringify(devices)}`);
1791
1792
  }
1792
1793
  }
1793
1794
 
1794
1795
  public async deviceInfo(device: (irdevice & devicesConfig) | (device & devicesConfig)) {
1795
1796
  if (this.platformLogging?.includes('debug')) {
1796
- this.warnLog(JSON.stringify(device));
1797
+ this.warnLog(superStringify(device));
1797
1798
 
1798
1799
  const t = Date.now();
1799
1800
  const nonce = 'requestID';
@@ -1827,9 +1828,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1827
1828
 
1828
1829
  this.deviceStatus = req;
1829
1830
  if (this.deviceStatus.message === 'success') {
1830
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
1831
+ this.warnLog(`${device.deviceName} deviceInfoStatus: ${superStringify(this.deviceStatus)}`);
1831
1832
  } else {
1832
- this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus.message)}`);
1833
+ this.warnLog(`${device.deviceName} deviceInfoStatus: ${superStringify(this.deviceStatus.message)}`);
1833
1834
  this.warnLog('Unable to retreive deviceInfoStatus.');
1834
1835
  }
1835
1836
  }