@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10

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 (139) hide show
  1. package/.prettierrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +10 -0
  4. package/config.schema.json +8 -0
  5. package/dist/device/blindtilt.d.ts +1 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +58 -65
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +1 -0
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +52 -55
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +1 -0
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +68 -68
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +1 -0
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +76 -75
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +2 -0
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +67 -59
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +2 -0
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +81 -94
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/hub.d.ts +9 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +197 -30
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +58 -62
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts +1 -0
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +28 -26
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/lightstrip.d.ts +1 -0
  41. package/dist/device/lightstrip.d.ts.map +1 -1
  42. package/dist/device/lightstrip.js +68 -67
  43. package/dist/device/lightstrip.js.map +1 -1
  44. package/dist/device/lock.d.ts +2 -0
  45. package/dist/device/lock.d.ts.map +1 -1
  46. package/dist/device/lock.js +51 -47
  47. package/dist/device/lock.js.map +1 -1
  48. package/dist/device/meter.d.ts +5 -3
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +75 -74
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts +4 -3
  53. package/dist/device/meterplus.d.ts.map +1 -1
  54. package/dist/device/meterplus.js +74 -74
  55. package/dist/device/meterplus.js.map +1 -1
  56. package/dist/device/motion.d.ts +2 -0
  57. package/dist/device/motion.d.ts.map +1 -1
  58. package/dist/device/motion.js +66 -54
  59. package/dist/device/motion.js.map +1 -1
  60. package/dist/device/plug.d.ts +1 -0
  61. package/dist/device/plug.d.ts.map +1 -1
  62. package/dist/device/plug.js +39 -39
  63. package/dist/device/plug.js.map +1 -1
  64. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  65. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  66. package/dist/device/robotvacuumcleaner.js +74 -53
  67. package/dist/device/robotvacuumcleaner.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  69. package/dist/irdevice/airconditioner.js +64 -66
  70. package/dist/irdevice/airconditioner.js.map +1 -1
  71. package/dist/irdevice/airpurifier.d.ts +1 -1
  72. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  73. package/dist/irdevice/airpurifier.js +32 -34
  74. package/dist/irdevice/airpurifier.js.map +1 -1
  75. package/dist/irdevice/camera.d.ts +1 -1
  76. package/dist/irdevice/camera.d.ts.map +1 -1
  77. package/dist/irdevice/camera.js +20 -23
  78. package/dist/irdevice/camera.js.map +1 -1
  79. package/dist/irdevice/fan.d.ts +2 -2
  80. package/dist/irdevice/fan.d.ts.map +1 -1
  81. package/dist/irdevice/fan.js +30 -32
  82. package/dist/irdevice/fan.js.map +1 -1
  83. package/dist/irdevice/light.d.ts +1 -1
  84. package/dist/irdevice/light.d.ts.map +1 -1
  85. package/dist/irdevice/light.js +26 -29
  86. package/dist/irdevice/light.js.map +1 -1
  87. package/dist/irdevice/other.d.ts +1 -1
  88. package/dist/irdevice/other.d.ts.map +1 -1
  89. package/dist/irdevice/other.js +22 -23
  90. package/dist/irdevice/other.js.map +1 -1
  91. package/dist/irdevice/tv.d.ts +2 -2
  92. package/dist/irdevice/tv.d.ts.map +1 -1
  93. package/dist/irdevice/tv.js +47 -50
  94. package/dist/irdevice/tv.js.map +1 -1
  95. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  96. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  97. package/dist/irdevice/vacuumcleaner.js +20 -23
  98. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  99. package/dist/irdevice/waterheater.d.ts +1 -1
  100. package/dist/irdevice/waterheater.d.ts.map +1 -1
  101. package/dist/irdevice/waterheater.js +22 -23
  102. package/dist/irdevice/waterheater.js.map +1 -1
  103. package/dist/platform.d.ts.map +1 -1
  104. package/dist/platform.js +46 -44
  105. package/dist/platform.js.map +1 -1
  106. package/dist/settings.d.ts +1 -0
  107. package/dist/settings.d.ts.map +1 -1
  108. package/dist/settings.js.map +1 -1
  109. package/dist/utils.js +1 -1
  110. package/dist/utils.js.map +1 -1
  111. package/package.json +3 -3
  112. package/src/device/blindtilt.ts +114 -78
  113. package/src/device/bot.ts +102 -63
  114. package/src/device/ceilinglight.ts +113 -73
  115. package/src/device/colorbulb.ts +144 -87
  116. package/src/device/contact.ts +98 -63
  117. package/src/device/curtain.ts +160 -134
  118. package/src/device/hub.ts +228 -39
  119. package/src/device/humidifier.ts +136 -85
  120. package/src/device/iosensor.ts +52 -32
  121. package/src/device/lightstrip.ts +118 -72
  122. package/src/device/lock.ts +85 -50
  123. package/src/device/meter.ts +104 -80
  124. package/src/device/meterplus.ts +103 -80
  125. package/src/device/motion.ts +95 -59
  126. package/src/device/plug.ts +70 -44
  127. package/src/device/robotvacuumcleaner.ts +107 -56
  128. package/src/irdevice/airconditioner.ts +116 -86
  129. package/src/irdevice/airpurifier.ts +60 -39
  130. package/src/irdevice/camera.ts +40 -28
  131. package/src/irdevice/fan.ts +52 -38
  132. package/src/irdevice/light.ts +48 -34
  133. package/src/irdevice/other.ts +44 -28
  134. package/src/irdevice/tv.ts +70 -56
  135. package/src/irdevice/vacuumcleaner.ts +40 -28
  136. package/src/irdevice/waterheater.ts +48 -32
  137. package/src/platform.ts +87 -56
  138. package/src/settings.ts +41 -40
  139. package/src/utils.ts +1 -1
@@ -1,3 +1,4 @@
1
+ /* eslint-disable brace-style */
1
2
  import { Context } from 'vm';
2
3
  import { request } from 'undici';
3
4
  import { sleep } from '../utils';
@@ -54,16 +55,20 @@ export class Humidifier {
54
55
  doHumidifierUpdate!: Subject<void>;
55
56
 
56
57
  // Connection
57
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
58
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
59
-
60
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
58
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
59
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
60
+
61
+ constructor(
62
+ private readonly platform: SwitchBotPlatform,
63
+ private accessory: PlatformAccessory,
64
+ public device: device & devicesConfig,
65
+ ) {
61
66
  // default placeholders
62
67
  this.logs(device);
63
68
  this.scan(device);
64
69
  this.refreshRate(device);
65
- this.config(device);
66
70
  this.context();
71
+ this.config(device);
67
72
 
68
73
  // this is subject we use to track when we need to POST changes to the SwitchBot API
69
74
  this.doHumidifierUpdate = new Subject();
@@ -184,8 +189,10 @@ export class Humidifier {
184
189
  await this.pushChanges();
185
190
  } catch (e: any) {
186
191
  this.apiError(e);
187
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
188
- + ` Error Message: ${JSON.stringify(e.message)}`);
192
+ this.errorLog(
193
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
194
+ ` Error Message: ${JSON.stringify(e.message)}`,
195
+ );
189
196
  }
190
197
  this.humidifierUpdateInProgress = false;
191
198
  });
@@ -203,8 +210,9 @@ export class Humidifier {
203
210
  await this.openAPIparseStatus();
204
211
  } else {
205
212
  await this.offlineOff();
206
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
207
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
213
+ this.debugWarnLog(
214
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
215
+ );
208
216
  }
209
217
  }
210
218
 
@@ -254,14 +262,16 @@ export class Humidifier {
254
262
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
255
263
  }
256
264
  }
257
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
258
- + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
259
265
  this.debugLog(
260
- `${this.device.deviceType}: ${this.accessory.displayName}`
261
- + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
266
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
267
+ );
268
+ this.debugLog(
269
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
270
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
271
+ );
272
+ this.debugLog(
273
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
262
274
  );
263
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
264
- + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
265
275
  // Active
266
276
  switch (this.power) {
267
277
  case 'on':
@@ -278,7 +288,6 @@ export class Humidifier {
278
288
  this.WaterLevel = 100;
279
289
  }
280
290
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
281
-
282
291
  }
283
292
 
284
293
  /**
@@ -293,8 +302,10 @@ export class Humidifier {
293
302
  await this.openAPIRefreshStatus();
294
303
  } else {
295
304
  await this.offlineOff();
296
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
297
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
305
+ this.debugWarnLog(
306
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
307
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
308
+ );
298
309
  }
299
310
  }
300
311
 
@@ -319,8 +330,10 @@ export class Humidifier {
319
330
  // Set an event hander
320
331
  switchbot.onadvertisement = async (ad: ad) => {
321
332
  this.address = ad.address;
322
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
323
- + ` BLE Address Found: ${this.address}`);
333
+ this.debugLog(
334
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
335
+ ` BLE Address Found: ${this.address}`,
336
+ );
324
337
  this.serviceData = ad.serviceData;
325
338
  this.autoMode = ad.serviceData.autoMode;
326
339
  this.onState = ad.serviceData.onState;
@@ -349,8 +362,10 @@ export class Humidifier {
349
362
  })
350
363
  .catch(async (e: any) => {
351
364
  this.apiError(e);
352
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
353
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
365
+ this.errorLog(
366
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
367
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
368
+ );
354
369
  await this.BLERefreshConnection(switchbot);
355
370
  });
356
371
  } else {
@@ -368,10 +383,7 @@ export class Humidifier {
368
383
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
369
384
  this.statusCode(statusCode);
370
385
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
371
- this.debugLog(
372
- `${this.device.deviceType}: ${this.accessory.displayName
373
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
374
- );
386
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
375
387
  this.auto = deviceStatus.body.auto;
376
388
  this.power = deviceStatus.body.power;
377
389
  this.lackWater = deviceStatus.body.lackWater;
@@ -382,8 +394,10 @@ export class Humidifier {
382
394
  this.updateHomeKitCharacteristics();
383
395
  } catch (e: any) {
384
396
  this.apiError(e);
385
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
386
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
397
+ this.errorLog(
398
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
399
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
400
+ );
387
401
  }
388
402
  }
389
403
 
@@ -393,14 +407,15 @@ export class Humidifier {
393
407
  async pushChanges(): Promise<void> {
394
408
  if (!this.device.enableCloudService && this.OpenAPI) {
395
409
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
396
- } else /*if (this.BLE) {
410
+ } /*if (this.BLE) {
397
411
  await this.BLEpushChanges();
398
- } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
412
+ } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
399
413
  await this.openAPIpushChanges();
400
414
  } else {
401
415
  await this.offlineOff();
402
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
403
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
416
+ this.debugWarnLog(
417
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
418
+ );
404
419
  }
405
420
  interval(5000)
406
421
  .pipe(take(1))
@@ -433,21 +448,25 @@ export class Humidifier {
433
448
  })
434
449
  .catch(async (e: any) => {
435
450
  this.apiError(e);
436
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
437
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
451
+ this.errorLog(
452
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
453
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
454
+ );
438
455
  await this.BLEPushConnection();
439
456
  });
440
457
  }
441
458
 
442
459
  async openAPIpushChanges(): Promise<void> {
443
460
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
444
- if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
445
- this.Active === this.platform.Characteristic.Active.ACTIVE) {
461
+ if (
462
+ this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
463
+ this.Active === this.platform.Characteristic.Active.ACTIVE
464
+ ) {
446
465
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
447
466
  const bodyChange = JSON.stringify({
448
- 'command': 'setMode',
449
- 'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
450
- 'commandType': 'command',
467
+ command: 'setMode',
468
+ parameter: `${this.RelativeHumidityHumidifierThreshold}`,
469
+ commandType: 'command',
451
470
  });
452
471
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
453
472
  try {
@@ -462,8 +481,9 @@ export class Humidifier {
462
481
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
463
482
  } catch (e: any) {
464
483
  this.apiError(e);
465
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
466
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
484
+ this.errorLog(
485
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
486
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
467
487
  );
468
488
  }
469
489
  } else if (
@@ -481,13 +501,15 @@ export class Humidifier {
481
501
  */
482
502
  async pushAutoChanges(): Promise<void> {
483
503
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
484
- if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
485
- this.Active === this.platform.Characteristic.Active.ACTIVE) {
504
+ if (
505
+ this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
506
+ this.Active === this.platform.Characteristic.Active.ACTIVE
507
+ ) {
486
508
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
487
509
  const bodyChange = JSON.stringify({
488
- 'command': 'setMode',
489
- 'parameter': 'auto',
490
- 'commandType': 'command',
510
+ command: 'setMode',
511
+ parameter: 'auto',
512
+ commandType: 'command',
491
513
  });
492
514
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
493
515
  try {
@@ -502,13 +524,16 @@ export class Humidifier {
502
524
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
503
525
  } catch (e: any) {
504
526
  this.apiError(e);
505
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
506
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
527
+ this.errorLog(
528
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}` +
529
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
507
530
  );
508
531
  }
509
532
  } else {
510
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
511
- `TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`);
533
+ this.debugLog(
534
+ `${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
535
+ `TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`,
536
+ );
512
537
  }
513
538
  }
514
539
 
@@ -520,9 +545,9 @@ export class Humidifier {
520
545
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
521
546
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
522
547
  const bodyChange = JSON.stringify({
523
- 'command': 'turnOff',
524
- 'parameter': 'default',
525
- 'commandType': 'command',
548
+ command: 'turnOff',
549
+ parameter: 'default',
550
+ commandType: 'command',
526
551
  });
527
552
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
528
553
  try {
@@ -537,8 +562,9 @@ export class Humidifier {
537
562
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
538
563
  } catch (e: any) {
539
564
  this.apiError(e);
540
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
541
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
565
+ this.errorLog(
566
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}` +
567
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
542
568
  );
543
569
  }
544
570
  } else {
@@ -600,8 +626,9 @@ export class Humidifier {
600
626
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
601
627
  } else {
602
628
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
603
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
604
- + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
629
+ this.debugLog(
630
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
631
+ );
605
632
  this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
606
633
  }
607
634
  if (this.OpenAPI) {
@@ -614,23 +641,34 @@ export class Humidifier {
614
641
  }
615
642
  }
616
643
  if (this.CurrentHumidifierDehumidifierState === undefined) {
617
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
618
- + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
644
+ this.debugLog(
645
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
646
+ ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
647
+ );
619
648
  } else {
620
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState,
621
- this.CurrentHumidifierDehumidifierState);
622
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
623
- ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
649
+ this.humidifierService.updateCharacteristic(
650
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState,
651
+ this.CurrentHumidifierDehumidifierState,
652
+ );
653
+ this.debugLog(
654
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
655
+ ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
656
+ );
624
657
  this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
625
658
  }
626
659
  if (this.TargetHumidifierDehumidifierState === undefined) {
627
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
628
- + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
660
+ this.debugLog(
661
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
662
+ );
629
663
  } else {
630
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState,
631
- this.TargetHumidifierDehumidifierState);
632
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
633
- ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
664
+ this.humidifierService.updateCharacteristic(
665
+ this.platform.Characteristic.TargetHumidifierDehumidifierState,
666
+ this.TargetHumidifierDehumidifierState,
667
+ );
668
+ this.debugLog(
669
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
670
+ ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
671
+ );
634
672
  this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
635
673
  }
636
674
  if (this.Active === undefined) {
@@ -641,13 +679,19 @@ export class Humidifier {
641
679
  this.accessory.context.Active = this.Active;
642
680
  }
643
681
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
644
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
645
- + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
682
+ this.debugLog(
683
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
684
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
685
+ );
646
686
  } else {
647
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
648
- this.RelativeHumidityHumidifierThreshold);
649
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
650
- ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
687
+ this.humidifierService.updateCharacteristic(
688
+ this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
689
+ this.RelativeHumidityHumidifierThreshold,
690
+ );
691
+ this.debugLog(
692
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
693
+ ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
694
+ );
651
695
  this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
652
696
  }
653
697
  if (!this.device.humidifier?.hide_temperature && !this.BLE) {
@@ -743,8 +787,10 @@ export class Humidifier {
743
787
  this.offlineOff();
744
788
  break;
745
789
  case 171:
746
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
747
- + `Hub: ${this.device.hubDeviceId}`);
790
+ this.errorLog(
791
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
792
+ `Hub: ${this.device.hubDeviceId}`,
793
+ );
748
794
  this.offlineOff();
749
795
  break;
750
796
  case 190:
@@ -760,8 +806,10 @@ export class Humidifier {
760
806
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
761
807
  break;
762
808
  default:
763
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
764
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
809
+ this.infoLog(
810
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
811
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
812
+ );
765
813
  }
766
814
  }
767
815
 
@@ -792,14 +840,17 @@ export class Humidifier {
792
840
 
793
841
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
794
842
  let FirmwareRevision: string;
795
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
796
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
843
+ this.debugLog(
844
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
845
+ );
797
846
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
798
847
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
799
- if (accessory.context.FirmwareRevision) {
800
- FirmwareRevision = accessory.context.FirmwareRevision;
801
- } else if (device.firmware) {
848
+ if (device.firmware) {
802
849
  FirmwareRevision = device.firmware;
850
+ } else if (device.version) {
851
+ FirmwareRevision = JSON.stringify(device.version);
852
+ } else if (accessory.context.FirmwareRevision) {
853
+ FirmwareRevision = accessory.context.FirmwareRevision;
803
854
  } else {
804
855
  FirmwareRevision = this.platform.version;
805
856
  }
@@ -882,7 +933,7 @@ export class Humidifier {
882
933
  config['offline'] = device.offline;
883
934
  }
884
935
  if (Object.entries(config).length !== 0) {
885
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
936
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
886
937
  }
887
938
  }
888
939
 
@@ -29,6 +29,7 @@ export class IOSensor {
29
29
  StatusLowBattery?: CharacteristicValue;
30
30
 
31
31
  // OpenAPI Others
32
+ Version: deviceStatus['version'];
32
33
  Battery: deviceStatus['battery'];
33
34
  Temperature: deviceStatus['temperature'];
34
35
  Humidity: deviceStatus['humidity'];
@@ -61,18 +62,22 @@ export class IOSensor {
61
62
  doIOSensorUpdate: Subject<void>;
62
63
 
63
64
  // Connection
64
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
65
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
66
-
67
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
65
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
66
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
67
+
68
+ constructor(
69
+ private readonly platform: SwitchBotPlatform,
70
+ private accessory: PlatformAccessory,
71
+ public device: device & devicesConfig,
72
+ ) {
68
73
  // default placeholders
69
74
  this.logs(device);
70
75
  this.scan(device);
71
76
  this.refreshRate(device);
72
- this.config(device);
73
77
  this.context();
74
78
  this.setupHistoryService(device);
75
79
  this.setupMqtt(device);
80
+ this.config(device);
76
81
 
77
82
  // this is subject we use to track when we need to POST changes to the SwitchBot API
78
83
  this.doIOSensorUpdate = new Subject();
@@ -182,8 +187,9 @@ export class IOSensor {
182
187
  await this.openAPIparseStatus();
183
188
  } else {
184
189
  await this.offlineOff();
185
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
186
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
190
+ this.debugWarnLog(
191
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
192
+ );
187
193
  }
188
194
  }
189
195
 
@@ -213,7 +219,6 @@ export class IOSensor {
213
219
  }
214
220
  }
215
221
 
216
-
217
222
  async openAPIparseStatus(): Promise<void> {
218
223
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
219
224
  // Battery
@@ -250,8 +255,10 @@ export class IOSensor {
250
255
  await this.openAPIRefreshStatus();
251
256
  } else {
252
257
  await this.offlineOff();
253
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
254
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
258
+ this.debugWarnLog(
259
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
260
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
261
+ );
255
262
  }
256
263
  }
257
264
 
@@ -276,8 +283,10 @@ export class IOSensor {
276
283
  // Set an event hander
277
284
  switchbot.onadvertisement = async (ad: ad) => {
278
285
  this.address = ad.address;
279
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
280
- + ` BLE Address Found: ${this.address}`);
286
+ this.debugLog(
287
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
288
+ ` BLE Address Found: ${this.address}`,
289
+ );
281
290
  if (ad.serviceData.humidity! > 0) {
282
291
  // reject unreliable data
283
292
  this.humidity = ad.serviceData.humidity;
@@ -312,8 +321,10 @@ export class IOSensor {
312
321
  })
313
322
  .catch(async (e: any) => {
314
323
  this.apiError(e);
315
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
316
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
324
+ this.errorLog(
325
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
326
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
327
+ );
317
328
  await this.BLERefreshConnection(switchbot);
318
329
  });
319
330
  } else {
@@ -331,19 +342,19 @@ export class IOSensor {
331
342
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
332
343
  this.statusCode(statusCode);
333
344
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
334
- this.debugLog(
335
- `${this.device.deviceType}: ${this.accessory.displayName
336
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
337
- );
345
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
338
346
  this.Humidity = deviceStatus.body.humidity!;
339
347
  this.Temperature = deviceStatus.body.temperature!;
340
348
  this.Battery = deviceStatus.body.battery!;
349
+ this.Version = deviceStatus.body.version!;
341
350
  this.openAPIparseStatus();
342
351
  this.updateHomeKitCharacteristics();
343
352
  } catch (e: any) {
344
353
  this.apiError(e);
345
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
346
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
354
+ this.errorLog(
355
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
356
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
357
+ );
347
358
  }
348
359
  }
349
360
 
@@ -359,8 +370,10 @@ export class IOSensor {
359
370
  } else {
360
371
  this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
361
372
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
362
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
363
- + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
373
+ this.debugLog(
374
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
375
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
376
+ );
364
377
  if (this.device.mqttURL) {
365
378
  mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
366
379
  }
@@ -530,8 +543,10 @@ export class IOSensor {
530
543
  this.offlineOff();
531
544
  break;
532
545
  case 171:
533
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
534
- + `Hub: ${this.device.hubDeviceId}`);
546
+ this.errorLog(
547
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
548
+ `Hub: ${this.device.hubDeviceId}`,
549
+ );
535
550
  this.offlineOff();
536
551
  break;
537
552
  case 190:
@@ -547,8 +562,10 @@ export class IOSensor {
547
562
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
548
563
  break;
549
564
  default:
550
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
551
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
565
+ this.infoLog(
566
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
567
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
568
+ );
552
569
  }
553
570
  }
554
571
 
@@ -572,14 +589,17 @@ export class IOSensor {
572
589
 
573
590
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
574
591
  let FirmwareRevision: string;
575
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
576
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
592
+ this.debugLog(
593
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
594
+ );
577
595
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
578
596
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
579
- if (accessory.context.FirmwareRevision) {
580
- FirmwareRevision = accessory.context.FirmwareRevision;
581
- } else if (device.firmware) {
597
+ if (device.firmware) {
582
598
  FirmwareRevision = device.firmware;
599
+ } else if (device.version) {
600
+ FirmwareRevision = JSON.stringify(device.version);
601
+ } else if (accessory.context.FirmwareRevision) {
602
+ FirmwareRevision = accessory.context.FirmwareRevision;
583
603
  } else {
584
604
  FirmwareRevision = this.platform.version;
585
605
  }
@@ -644,7 +664,7 @@ export class IOSensor {
644
664
  config['scanDuration'] = device.scanDuration;
645
665
  }
646
666
  if (Object.entries(config).length !== 0) {
647
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
667
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
648
668
  }
649
669
  }
650
670