@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1

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 (119) hide show
  1. package/.github/npm-version-script.js +81 -0
  2. package/.prettierrc +1 -1
  3. package/.vscode/settings.json +1 -1
  4. package/CHANGELOG.md +10 -0
  5. package/config.schema.json +8 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +49 -59
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +44 -50
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +60 -63
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +68 -70
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +22 -25
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +50 -58
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/hub.d.ts +6 -0
  25. package/dist/device/hub.d.ts.map +1 -1
  26. package/dist/device/hub.js +168 -26
  27. package/dist/device/hub.js.map +1 -1
  28. package/dist/device/humidifier.d.ts.map +1 -1
  29. package/dist/device/humidifier.js +49 -56
  30. package/dist/device/humidifier.js.map +1 -1
  31. package/dist/device/iosensor.d.ts.map +1 -1
  32. package/dist/device/iosensor.js +18 -20
  33. package/dist/device/iosensor.js.map +1 -1
  34. package/dist/device/lightstrip.d.ts.map +1 -1
  35. package/dist/device/lightstrip.js +59 -61
  36. package/dist/device/lightstrip.js.map +1 -1
  37. package/dist/device/lock.d.ts.map +1 -1
  38. package/dist/device/lock.js +40 -41
  39. package/dist/device/lock.js.map +1 -1
  40. package/dist/device/meter.d.ts +3 -3
  41. package/dist/device/meter.d.ts.map +1 -1
  42. package/dist/device/meter.js +65 -68
  43. package/dist/device/meter.js.map +1 -1
  44. package/dist/device/meterplus.d.ts.map +1 -1
  45. package/dist/device/meterplus.js +18 -20
  46. package/dist/device/meterplus.js.map +1 -1
  47. package/dist/device/motion.d.ts.map +1 -1
  48. package/dist/device/motion.js +20 -23
  49. package/dist/device/motion.js.map +1 -1
  50. package/dist/device/plug.d.ts.map +1 -1
  51. package/dist/device/plug.js +30 -33
  52. package/dist/device/plug.js.map +1 -1
  53. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  54. package/dist/device/robotvacuumcleaner.js +48 -51
  55. package/dist/device/robotvacuumcleaner.js.map +1 -1
  56. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  57. package/dist/irdevice/airconditioner.js +57 -61
  58. package/dist/irdevice/airconditioner.js.map +1 -1
  59. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  60. package/dist/irdevice/airpurifier.js +29 -31
  61. package/dist/irdevice/airpurifier.js.map +1 -1
  62. package/dist/irdevice/camera.d.ts.map +1 -1
  63. package/dist/irdevice/camera.js +17 -20
  64. package/dist/irdevice/camera.js.map +1 -1
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +27 -29
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts.map +1 -1
  69. package/dist/irdevice/light.js +23 -26
  70. package/dist/irdevice/light.js.map +1 -1
  71. package/dist/irdevice/other.d.ts.map +1 -1
  72. package/dist/irdevice/other.js +19 -20
  73. package/dist/irdevice/other.js.map +1 -1
  74. package/dist/irdevice/tv.d.ts.map +1 -1
  75. package/dist/irdevice/tv.js +44 -47
  76. package/dist/irdevice/tv.js.map +1 -1
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +17 -20
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts.map +1 -1
  81. package/dist/irdevice/waterheater.js +19 -20
  82. package/dist/irdevice/waterheater.js.map +1 -1
  83. package/dist/platform.d.ts.map +1 -1
  84. package/dist/platform.js +44 -43
  85. package/dist/platform.js.map +1 -1
  86. package/dist/settings.d.ts +1 -0
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js.map +1 -1
  89. package/dist/utils.js +1 -1
  90. package/dist/utils.js.map +1 -1
  91. package/package.json +1 -1
  92. package/src/device/blindtilt.ts +106 -72
  93. package/src/device/bot.ts +94 -58
  94. package/src/device/ceilinglight.ts +102 -68
  95. package/src/device/colorbulb.ts +134 -82
  96. package/src/device/contact.ts +54 -33
  97. package/src/device/curtain.ts +130 -101
  98. package/src/device/hub.ts +198 -35
  99. package/src/device/humidifier.ts +128 -80
  100. package/src/device/iosensor.ts +43 -27
  101. package/src/device/lightstrip.ts +108 -67
  102. package/src/device/lock.ts +73 -45
  103. package/src/device/meter.ts +94 -75
  104. package/src/device/meterplus.ts +43 -27
  105. package/src/device/motion.ts +50 -32
  106. package/src/device/plug.ts +62 -39
  107. package/src/device/robotvacuumcleaner.ts +78 -54
  108. package/src/irdevice/airconditioner.ts +111 -83
  109. package/src/irdevice/airpurifier.ts +55 -34
  110. package/src/irdevice/camera.ts +35 -23
  111. package/src/irdevice/fan.ts +47 -33
  112. package/src/irdevice/light.ts +43 -29
  113. package/src/irdevice/other.ts +39 -23
  114. package/src/irdevice/tv.ts +65 -51
  115. package/src/irdevice/vacuumcleaner.ts +35 -23
  116. package/src/irdevice/waterheater.ts +43 -27
  117. package/src/platform.ts +85 -55
  118. package/src/settings.ts +41 -40
  119. package/src/utils.ts +1 -1
@@ -1,14 +1,14 @@
1
- import { Context } from 'vm';
2
- import { hostname } from 'os';
3
- import { request } from 'undici';
4
- import { sleep } from '../utils';
5
- import { MqttClient } from 'mqtt';
6
- import { interval, Subject } from 'rxjs';
7
1
  import { connectAsync } from 'async-mqtt';
2
+ import { CharacteristicValue, PlatformAccessory, Service, Units } from 'homebridge';
3
+ import { MqttClient } from 'mqtt';
4
+ import { hostname } from 'os';
5
+ import { Subject, interval } from 'rxjs';
8
6
  import { skipWhile } from 'rxjs/operators';
7
+ import { request } from 'undici';
8
+ import { Context } from 'vm';
9
9
  import { SwitchBotPlatform } from '../platform';
10
- import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
11
- import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, Devices } from '../settings';
10
+ import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, switchbot, temperature } from '../settings';
11
+ import { sleep } from '../utils';
12
12
 
13
13
  /**
14
14
  * Platform Accessory
@@ -60,10 +60,14 @@ export class Meter {
60
60
  doMeterUpdate: Subject<void>;
61
61
 
62
62
  // Connection
63
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
64
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
65
-
66
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
63
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
64
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
65
+
66
+ constructor(
67
+ private readonly platform: SwitchBotPlatform,
68
+ private accessory: PlatformAccessory,
69
+ public device: device & devicesConfig,
70
+ ) {
67
71
  // default placeholders
68
72
  this.logs(device);
69
73
  this.scan(device);
@@ -149,11 +153,7 @@ export class Meter {
149
153
  }
150
154
 
151
155
  // Battery Service
152
- if (!this.BLE) {
153
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
154
- this.batteryService = this.accessory.getService(this.platform.Service.Battery);
155
- accessory.removeService(this.batteryService!);
156
- } else if (this.BLE && !this.batteryService) {
156
+ if (!this.batteryService) {
157
157
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
158
158
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
159
159
  `${accessory.displayName} Battery`;
@@ -190,8 +190,9 @@ export class Meter {
190
190
  await this.openAPIparseStatus();
191
191
  } else {
192
192
  await this.offlineOff();
193
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
194
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
193
+ this.debugWarnLog(
194
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
195
+ );
195
196
  }
196
197
  }
197
198
 
@@ -223,6 +224,16 @@ export class Meter {
223
224
 
224
225
  async openAPIparseStatus(): Promise<void> {
225
226
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
227
+
228
+ // Battery
229
+ this.BatteryLevel = Number(this.battery);
230
+ if (this.BatteryLevel < 15) {
231
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
232
+ } else {
233
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
234
+ }
235
+ this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
236
+
226
237
  // Current Relative Humidity
227
238
  if (!this.device.meter?.hide_humidity) {
228
239
  this.CurrentRelativeHumidity = this.Humidity!;
@@ -248,8 +259,10 @@ export class Meter {
248
259
  await this.openAPIRefreshStatus();
249
260
  } else {
250
261
  await this.offlineOff();
251
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
252
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
262
+ this.debugWarnLog(
263
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
264
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
265
+ );
253
266
  }
254
267
  }
255
268
 
@@ -274,8 +287,10 @@ export class Meter {
274
287
  // Set an event hander
275
288
  switchbot.onadvertisement = async (ad: ad) => {
276
289
  this.address = ad.address;
277
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
278
- + ` BLE Address Found: ${this.address}`);
290
+ this.debugLog(
291
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
292
+ ` BLE Address Found: ${this.address}`,
293
+ );
279
294
  if (ad.serviceData.humidity! > 0) {
280
295
  // reject unreliable data
281
296
  this.humidity = ad.serviceData.humidity;
@@ -310,8 +325,10 @@ export class Meter {
310
325
  })
311
326
  .catch(async (e: any) => {
312
327
  this.apiError(e);
313
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
314
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
328
+ this.errorLog(
329
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
330
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
331
+ );
315
332
  await this.BLERefreshConnection(switchbot);
316
333
  });
317
334
  } else {
@@ -329,18 +346,18 @@ export class Meter {
329
346
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
330
347
  this.statusCode(statusCode);
331
348
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
332
- this.debugLog(
333
- `${this.device.deviceType}: ${this.accessory.displayName
334
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
335
- );
349
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
336
350
  this.Humidity = deviceStatus.body.humidity!;
337
351
  this.Temperature = deviceStatus.body.temperature!;
352
+ this.battery = deviceStatus.body.battery!;
338
353
  this.openAPIparseStatus();
339
354
  this.updateHomeKitCharacteristics();
340
355
  } catch (e: any) {
341
356
  this.apiError(e);
342
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
343
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
357
+ this.errorLog(
358
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
359
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
360
+ );
344
361
  }
345
362
  }
346
363
 
@@ -356,8 +373,10 @@ export class Meter {
356
373
  } else {
357
374
  this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
358
375
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
359
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
360
- + ` CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
376
+ this.debugLog(
377
+ `${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic` +
378
+ ` CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
379
+ );
361
380
  if (this.device.mqttURL) {
362
381
  mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
363
382
  }
@@ -379,31 +398,30 @@ export class Meter {
379
398
  this.accessory.context.CurrentTemperature = this.CurrentTemperature;
380
399
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
381
400
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
382
-
383
401
  }
384
402
  }
385
- if (this.BLE) {
386
- if (this.BatteryLevel === undefined) {
387
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
388
- } else {
389
- if (this.device.mqttURL) {
390
- mqttmessage.push(`"battery": ${this.BatteryLevel}`);
391
- }
392
- this.accessory.context.BatteryLevel = this.BatteryLevel;
393
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
394
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
403
+
404
+ if (this.BatteryLevel === undefined) {
405
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
406
+ } else {
407
+ if (this.device.mqttURL) {
408
+ mqttmessage.push(`"battery": ${this.BatteryLevel}`);
395
409
  }
396
- if (this.StatusLowBattery === undefined) {
397
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
398
- } else {
399
- if (this.device.mqttURL) {
400
- mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
401
- }
402
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
403
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
404
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
410
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
411
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
412
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
413
+ }
414
+ if (this.StatusLowBattery === undefined) {
415
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
416
+ } else {
417
+ if (this.device.mqttURL) {
418
+ mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
405
419
  }
420
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
421
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
422
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
406
423
  }
424
+
407
425
  if (this.device.mqttURL) {
408
426
  this.mqttPublish(`{${mqttmessage.join(',')}}`);
409
427
  }
@@ -530,8 +548,10 @@ export class Meter {
530
548
  this.offlineOff();
531
549
  break;
532
550
  case 171:
533
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
534
- + `Hub: ${this.device.hubDeviceId}`);
551
+ this.errorLog(
552
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
553
+ `Hub: ${this.device.hubDeviceId}`,
554
+ );
535
555
  this.offlineOff();
536
556
  break;
537
557
  case 190:
@@ -547,8 +567,10 @@ export class Meter {
547
567
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
548
568
  break;
549
569
  default:
550
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
551
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
570
+ this.infoLog(
571
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
572
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
573
+ );
552
574
  }
553
575
  }
554
576
 
@@ -566,16 +588,15 @@ export class Meter {
566
588
  if (!this.device.meter?.hide_temperature) {
567
589
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
568
590
  }
569
- if (this.BLE) {
570
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
571
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
572
- }
591
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
592
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
573
593
  }
574
594
 
575
595
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
576
596
  let FirmwareRevision: string;
577
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
578
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
597
+ this.debugLog(
598
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
599
+ );
579
600
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
580
601
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
581
602
  if (accessory.context.FirmwareRevision) {
@@ -599,18 +620,16 @@ export class Meter {
599
620
  } else {
600
621
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
601
622
  }
602
- if (this.BLE) {
603
- if (this.BatteryLevel === undefined) {
604
- this.BatteryLevel = 100;
605
- } else {
606
- this.BatteryLevel = this.accessory.context.BatteryLevel;
607
- }
608
- if (this.StatusLowBattery === undefined) {
609
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
610
- this.accessory.context.StatusLowBattery = this.StatusLowBattery;
611
- } else {
612
- this.StatusLowBattery = this.accessory.context.StatusLowBattery;
613
- }
623
+ if (this.BatteryLevel === undefined) {
624
+ this.BatteryLevel = 100;
625
+ } else {
626
+ this.BatteryLevel = this.accessory.context.BatteryLevel;
627
+ }
628
+ if (this.StatusLowBattery === undefined) {
629
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
630
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
631
+ } else {
632
+ this.StatusLowBattery = this.accessory.context.StatusLowBattery;
614
633
  }
615
634
  }
616
635
 
@@ -61,10 +61,14 @@ export class MeterPlus {
61
61
  doMeterUpdate: Subject<void>;
62
62
 
63
63
  // 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) {
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(
68
+ private readonly platform: SwitchBotPlatform,
69
+ private accessory: PlatformAccessory,
70
+ public device: device & devicesConfig,
71
+ ) {
68
72
  // default placeholders
69
73
  this.logs(device);
70
74
  this.scan(device);
@@ -191,8 +195,9 @@ export class MeterPlus {
191
195
  await this.openAPIparseStatus();
192
196
  } else {
193
197
  await this.offlineOff();
194
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
195
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
198
+ this.debugWarnLog(
199
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
200
+ );
196
201
  }
197
202
  }
198
203
 
@@ -222,7 +227,6 @@ export class MeterPlus {
222
227
  }
223
228
  }
224
229
 
225
-
226
230
  async openAPIparseStatus(): Promise<void> {
227
231
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
228
232
  // Current Relative Humidity
@@ -250,8 +254,10 @@ export class MeterPlus {
250
254
  await this.openAPIRefreshStatus();
251
255
  } else {
252
256
  await this.offlineOff();
253
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
254
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
257
+ this.debugWarnLog(
258
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
259
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
260
+ );
255
261
  }
256
262
  }
257
263
 
@@ -276,8 +282,10 @@ export class MeterPlus {
276
282
  // Set an event hander
277
283
  switchbot.onadvertisement = async (ad: ad) => {
278
284
  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}`);
285
+ this.debugLog(
286
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
287
+ ` BLE Address Found: ${this.address}`,
288
+ );
281
289
  if (ad.serviceData.humidity! > 0) {
282
290
  // reject unreliable data
283
291
  this.humidity = ad.serviceData.humidity;
@@ -312,8 +320,10 @@ export class MeterPlus {
312
320
  })
313
321
  .catch(async (e: any) => {
314
322
  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)}`);
323
+ this.errorLog(
324
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
325
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
326
+ );
317
327
  await this.BLERefreshConnection(switchbot);
318
328
  });
319
329
  } else {
@@ -331,10 +341,7 @@ export class MeterPlus {
331
341
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
332
342
  this.statusCode(statusCode);
333
343
  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
- );
344
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
338
345
  this.Humidity = deviceStatus.body.humidity!;
339
346
  this.Temperature = deviceStatus.body.temperature!;
340
347
  this.Battery = deviceStatus.body.battery!;
@@ -342,8 +349,10 @@ export class MeterPlus {
342
349
  this.updateHomeKitCharacteristics();
343
350
  } catch (e: any) {
344
351
  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)}`);
352
+ this.errorLog(
353
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
354
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
355
+ );
347
356
  }
348
357
  }
349
358
 
@@ -359,8 +368,10 @@ export class MeterPlus {
359
368
  } else {
360
369
  this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
361
370
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
362
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
363
- + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
371
+ this.debugLog(
372
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
373
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
374
+ );
364
375
  if (this.device.mqttURL) {
365
376
  mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
366
377
  }
@@ -542,8 +553,10 @@ export class MeterPlus {
542
553
  this.offlineOff();
543
554
  break;
544
555
  case 171:
545
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
546
- + `Hub: ${this.device.hubDeviceId}`);
556
+ this.errorLog(
557
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
558
+ `Hub: ${this.device.hubDeviceId}`,
559
+ );
547
560
  this.offlineOff();
548
561
  break;
549
562
  case 190:
@@ -559,8 +572,10 @@ export class MeterPlus {
559
572
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
560
573
  break;
561
574
  default:
562
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
563
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
575
+ this.infoLog(
576
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
577
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
578
+ );
564
579
  }
565
580
  }
566
581
 
@@ -586,8 +601,9 @@ export class MeterPlus {
586
601
 
587
602
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
588
603
  let FirmwareRevision: string;
589
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
590
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
604
+ this.debugLog(
605
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
606
+ );
591
607
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
592
608
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
593
609
  if (accessory.context.FirmwareRevision) {
@@ -38,7 +38,7 @@ export class Motion {
38
38
  battery!: serviceData['battery'];
39
39
  movement!: serviceData['movement'];
40
40
  lightLevel!: serviceData['lightLevel'];
41
- is_light!: any;//serviceData['is_light'];
41
+ is_light!: any; //serviceData['is_light'];
42
42
  tested!: any;
43
43
  led!: any;
44
44
  iot!: any;
@@ -56,10 +56,14 @@ export class Motion {
56
56
  doMotionUpdate!: Subject<void>;
57
57
 
58
58
  // Connection
59
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
60
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
61
-
62
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
59
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
60
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
61
+
62
+ constructor(
63
+ private readonly platform: SwitchBotPlatform,
64
+ private accessory: PlatformAccessory,
65
+ public device: device & devicesConfig,
66
+ ) {
63
67
  // default placeholders
64
68
  this.logs(device);
65
69
  this.scan(device);
@@ -158,8 +162,9 @@ export class Motion {
158
162
  await this.openAPIparseStatus();
159
163
  } else {
160
164
  await this.offlineOff();
161
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
162
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
165
+ this.debugWarnLog(
166
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
167
+ );
163
168
  }
164
169
  }
165
170
 
@@ -168,7 +173,7 @@ export class Motion {
168
173
  // Movement
169
174
  this.MotionDetected = this.movement!;
170
175
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
171
- if ((this.MotionDetected !== this.accessory.context.MotionDetected) && this.MotionDetected) {
176
+ if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
172
177
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
173
178
  }
174
179
  // Light Level
@@ -183,8 +188,10 @@ export class Motion {
183
188
  default:
184
189
  this.CurrentAmbientLightLevel = this.set_maxLux;
185
190
  }
186
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
187
- ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
191
+ this.debugLog(
192
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
193
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
194
+ );
188
195
  if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
189
196
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
190
197
  }
@@ -199,8 +206,9 @@ export class Motion {
199
206
  } else {
200
207
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
201
208
  }
202
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
203
- + ` StatusLowBattery: ${this.StatusLowBattery}`);
209
+ this.debugLog(
210
+ `${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
211
+ );
204
212
  }
205
213
 
206
214
  async openAPIparseStatus(): Promise<void> {
@@ -236,8 +244,10 @@ export class Motion {
236
244
  await this.openAPIRefreshStatus();
237
245
  } else {
238
246
  await this.offlineOff();
239
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
240
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
247
+ this.debugWarnLog(
248
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
249
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
250
+ );
241
251
  }
242
252
  }
243
253
 
@@ -268,8 +278,10 @@ export class Motion {
268
278
  this.scanning = true;
269
279
  switchbot.onadvertisement = async (ad: any) => {
270
280
  this.address = ad.address;
271
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
272
- + ` BLE Address Found: ${this.address}`);
281
+ this.debugLog(
282
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
283
+ ` BLE Address Found: ${this.address}`,
284
+ );
273
285
  this.serviceData = ad.serviceData;
274
286
  this.movement = ad.serviceData.movement;
275
287
  this.tested = ad.serviceData.tested;
@@ -312,8 +324,10 @@ export class Motion {
312
324
  })
313
325
  .catch(async (e: any) => {
314
326
  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)}`);
327
+ this.errorLog(
328
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
329
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
330
+ );
317
331
  this.debugErrorLog('3');
318
332
  await this.BLERefreshConnection(switchbot);
319
333
  });
@@ -333,18 +347,17 @@ export class Motion {
333
347
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
334
348
  this.statusCode(statusCode);
335
349
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
336
- this.debugLog(
337
- `${this.device.deviceType}: ${this.accessory.displayName
338
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
339
- );
350
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
340
351
  this.moveDetected = deviceStatus.body.moveDetected;
341
352
  this.brightness = deviceStatus.body.brightness;
342
353
  this.openAPIparseStatus();
343
354
  this.updateHomeKitCharacteristics();
344
355
  } catch (e: any) {
345
356
  this.apiError(e);
346
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
347
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
357
+ this.errorLog(
358
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
359
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
360
+ );
348
361
  }
349
362
  }
350
363
 
@@ -380,8 +393,8 @@ export class Motion {
380
393
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
381
394
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
382
395
  this.debugLog(
383
- `${this.device.deviceType}: ${this.accessory.displayName}`
384
- + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
396
+ `${this.device.deviceType}: ${this.accessory.displayName}` +
397
+ ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
385
398
  );
386
399
  }
387
400
  }
@@ -491,8 +504,10 @@ export class Motion {
491
504
  this.offlineOff();
492
505
  break;
493
506
  case 171:
494
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
495
- + `Hub: ${this.device.hubDeviceId}`);
507
+ this.errorLog(
508
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
509
+ `Hub: ${this.device.hubDeviceId}`,
510
+ );
496
511
  this.offlineOff();
497
512
  break;
498
513
  case 190:
@@ -508,8 +523,10 @@ export class Motion {
508
523
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
509
524
  break;
510
525
  default:
511
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
512
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
526
+ this.infoLog(
527
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
528
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
529
+ );
513
530
  }
514
531
  }
515
532
 
@@ -531,8 +548,9 @@ export class Motion {
531
548
 
532
549
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
533
550
  let FirmwareRevision: string;
534
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
535
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
551
+ this.debugLog(
552
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
553
+ );
536
554
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
537
555
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
538
556
  if (accessory.context.FirmwareRevision) {