@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
@@ -15,6 +15,7 @@ export class Plug {
15
15
  On!: CharacteristicValue;
16
16
 
17
17
  // OpenAPI Others
18
+ Version: deviceStatus['version'];
18
19
  power: deviceStatus['power'];
19
20
  deviceStatus!: any; //deviceStatusResponse;
20
21
 
@@ -41,16 +42,20 @@ export class Plug {
41
42
  doPlugUpdate!: Subject<void>;
42
43
 
43
44
  // Connection
44
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
45
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
46
-
47
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
45
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
46
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
47
+
48
+ constructor(
49
+ private readonly platform: SwitchBotPlatform,
50
+ private accessory: PlatformAccessory,
51
+ public device: device & devicesConfig,
52
+ ) {
48
53
  // default placeholders
49
54
  this.logs(device);
50
55
  this.scan(device);
51
56
  this.refreshRate(device);
52
- this.config(device);
53
57
  this.context();
58
+ this.config(device);
54
59
 
55
60
  // this is subject we use to track when we need to POST changes to the SwitchBot API
56
61
  this.doPlugUpdate = new Subject();
@@ -114,8 +119,10 @@ export class Plug {
114
119
  await this.pushChanges();
115
120
  } catch (e: any) {
116
121
  this.apiError(e);
117
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
118
- + ` Error Message: ${JSON.stringify(e.message)}`);
122
+ this.errorLog(
123
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
124
+ ` Error Message: ${JSON.stringify(e.message)}`,
125
+ );
119
126
  }
120
127
  this.plugUpdateInProgress = false;
121
128
  });
@@ -133,8 +140,9 @@ export class Plug {
133
140
  await this.openAPIparseStatus();
134
141
  } else {
135
142
  await this.offlineOff();
136
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
137
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
143
+ this.debugWarnLog(
144
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
145
+ );
138
146
  }
139
147
  }
140
148
 
@@ -175,8 +183,10 @@ export class Plug {
175
183
  await this.openAPIRefreshStatus();
176
184
  } else {
177
185
  await this.offlineOff();
178
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
179
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
186
+ this.debugWarnLog(
187
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
188
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
189
+ );
180
190
  }
181
191
  }
182
192
 
@@ -201,8 +211,10 @@ export class Plug {
201
211
  // Set an event hander
202
212
  switchbot.onadvertisement = async (ad: any) => {
203
213
  this.address = ad.address;
204
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
205
- + ` BLE Address Found: ${this.address}`);
214
+ this.debugLog(
215
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
216
+ ` BLE Address Found: ${this.address}`,
217
+ );
206
218
  this.serviceData = ad.serviceData;
207
219
  this.state = ad.serviceData.state;
208
220
  this.delay = ad.serviceData.delay;
@@ -236,8 +248,10 @@ export class Plug {
236
248
  })
237
249
  .catch(async (e: any) => {
238
250
  this.apiError(e);
239
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
240
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
251
+ this.errorLog(
252
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
253
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
254
+ );
241
255
  await this.BLERefreshConnection(switchbot);
242
256
  });
243
257
  } else {
@@ -255,17 +269,16 @@ export class Plug {
255
269
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
256
270
  this.statusCode(statusCode);
257
271
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
258
- this.debugLog(
259
- `${this.device.deviceType}: ${this.accessory.displayName
260
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
261
- );
272
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
262
273
  this.power = deviceStatus.body.power;
263
274
  this.openAPIparseStatus();
264
275
  this.updateHomeKitCharacteristics();
265
276
  } catch (e: any) {
266
277
  this.apiError(e);
267
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
268
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
278
+ this.errorLog(
279
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
280
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
281
+ );
269
282
  }
270
283
  }
271
284
 
@@ -288,8 +301,9 @@ export class Plug {
288
301
  await this.openAPIpushChanges();
289
302
  } else {
290
303
  await this.offlineOff();
291
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
292
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
304
+ this.debugWarnLog(
305
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
306
+ );
293
307
  }
294
308
  // Refresh the status from the API
295
309
  interval(15000)
@@ -335,14 +349,15 @@ export class Plug {
335
349
  })
336
350
  .catch(async (e: any) => {
337
351
  this.apiError(e);
338
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
339
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
352
+ this.errorLog(
353
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
354
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
355
+ );
340
356
  await this.BLEPushConnection();
341
357
  });
342
358
  } else {
343
359
  this.debugLog(
344
- `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
345
- + `OnCached: ${this.accessory.context.On}`,
360
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
346
361
  );
347
362
  }
348
363
  }
@@ -357,9 +372,9 @@ export class Plug {
357
372
  command = 'turnOff';
358
373
  }
359
374
  const bodyChange = JSON.stringify({
360
- 'command': `${command}`,
361
- 'parameter': 'default',
362
- 'commandType': 'command',
375
+ command: `${command}`,
376
+ parameter: 'default',
377
+ commandType: 'command',
363
378
  });
364
379
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
365
380
  try {
@@ -374,13 +389,17 @@ export class Plug {
374
389
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
375
390
  } catch (e: any) {
376
391
  this.apiError(e);
377
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
378
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
392
+ this.errorLog(
393
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
394
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
379
395
  );
380
396
  }
381
397
  } else {
382
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
383
- + `OnCached: ${this.accessory.context.On}`);
398
+ this.debugLog(
399
+ `${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
400
+ `On: ${this.On}, ` +
401
+ `OnCached: ${this.accessory.context.On}`,
402
+ );
384
403
  }
385
404
  }
386
405
 
@@ -521,8 +540,10 @@ export class Plug {
521
540
  this.offlineOff();
522
541
  break;
523
542
  case 171:
524
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
525
- + `Hub: ${this.device.hubDeviceId}`);
543
+ this.errorLog(
544
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
545
+ `Hub: ${this.device.hubDeviceId}`,
546
+ );
526
547
  this.offlineOff();
527
548
  break;
528
549
  case 190:
@@ -538,8 +559,10 @@ export class Plug {
538
559
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
539
560
  break;
540
561
  default:
541
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
542
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
562
+ this.infoLog(
563
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
564
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
565
+ );
543
566
  }
544
567
  }
545
568
 
@@ -556,14 +579,17 @@ export class Plug {
556
579
 
557
580
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
558
581
  let FirmwareRevision: string;
559
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
560
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
582
+ this.debugLog(
583
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
584
+ );
561
585
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
562
586
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
563
- if (accessory.context.FirmwareRevision) {
564
- FirmwareRevision = accessory.context.FirmwareRevision;
565
- } else if (device.firmware) {
587
+ if (device.firmware) {
566
588
  FirmwareRevision = device.firmware;
589
+ } else if (device.version) {
590
+ FirmwareRevision = JSON.stringify(device.version);
591
+ } else if (accessory.context.FirmwareRevision) {
592
+ FirmwareRevision = accessory.context.FirmwareRevision;
567
593
  } else {
568
594
  FirmwareRevision = this.platform.version;
569
595
  }
@@ -615,7 +641,7 @@ export class Plug {
615
641
  config['maxRetry'] = device.maxRetry;
616
642
  }
617
643
  if (Object.entries(config).length !== 0) {
618
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
644
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
619
645
  }
620
646
  }
621
647
 
@@ -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';
@@ -19,6 +20,7 @@ export class RobotVacuumCleaner {
19
20
  StatusLowBattery?: CharacteristicValue;
20
21
 
21
22
  // OpenAPI Others
23
+ Battery: deviceStatus['battery'];
22
24
  power: deviceStatus['power'];
23
25
  deviceStatus!: any; //deviceStatusResponse;
24
26
 
@@ -39,16 +41,20 @@ export class RobotVacuumCleaner {
39
41
  doRobotVacuumCleanerUpdate!: Subject<void>;
40
42
 
41
43
  // Connection
42
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
43
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
44
-
45
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
44
+ private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
45
+ private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
46
+
47
+ constructor(
48
+ private readonly platform: SwitchBotPlatform,
49
+ private accessory: PlatformAccessory,
50
+ public device: device & devicesConfig,
51
+ ) {
46
52
  // default placeholders
47
53
  this.logs(device);
48
54
  this.scan(device);
49
55
  this.refreshRate(device);
50
- this.config(device);
51
56
  this.context();
57
+ this.config(device);
52
58
 
53
59
  // this is subject we use to track when we need to POST changes to the SwitchBot API
54
60
  this.doRobotVacuumCleanerUpdate = new Subject();
@@ -103,6 +109,21 @@ export class RobotVacuumCleaner {
103
109
  })
104
110
  .onSet(this.BrightnessSet.bind(this));
105
111
 
112
+ // Battery Service
113
+ if (!this.batteryService) {
114
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
115
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
116
+ `${accessory.displayName} Battery`;
117
+
118
+ this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
119
+ if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
120
+ this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
121
+ }
122
+ this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
123
+ } else {
124
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
125
+ }
126
+
106
127
  // Update Homekit
107
128
  this.updateHomeKitCharacteristics();
108
129
 
@@ -127,13 +148,15 @@ export class RobotVacuumCleaner {
127
148
  if (this.On !== this.accessory.context.On) {
128
149
  await this.pushChanges();
129
150
  }
130
- if (this.On && (this.Brightness !== this.accessory.context.Brightness)) {
151
+ if (this.On && this.Brightness !== this.accessory.context.Brightness) {
131
152
  await this.openAPIpushBrightnessChanges();
132
153
  }
133
154
  } catch (e: any) {
134
155
  this.apiError(e);
135
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
136
- + ` Error Message: ${JSON.stringify(e.message)}`);
156
+ this.errorLog(
157
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
158
+ ` Error Message: ${JSON.stringify(e.message)}`,
159
+ );
137
160
  }
138
161
  this.robotVacuumCleanerUpdateInProgress = false;
139
162
  });
@@ -145,14 +168,15 @@ export class RobotVacuumCleaner {
145
168
  async parseStatus(): Promise<void> {
146
169
  if (!this.device.enableCloudService && this.OpenAPI) {
147
170
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
148
- } else/*if (this.BLE) {
171
+ } /*if (this.BLE) {
149
172
  await this.BLEparseStatus();
150
- } else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
173
+ } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
151
174
  await this.openAPIparseStatus();
152
175
  } else {
153
176
  await this.offlineOff();
154
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
155
- + ` ${this.device.connectionType}, parseStatus will not happen.`);
177
+ this.debugWarnLog(
178
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
179
+ );
156
180
  }
157
181
  }
158
182
 
@@ -179,6 +203,15 @@ export class RobotVacuumCleaner {
179
203
  this.On = false;
180
204
  }
181
205
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
206
+
207
+ // Battery
208
+ this.BatteryLevel = Number(this.Battery);
209
+ if (this.BatteryLevel < 15) {
210
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
211
+ } else {
212
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
213
+ }
214
+ this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
182
215
  }
183
216
 
184
217
  /**
@@ -187,14 +220,16 @@ export class RobotVacuumCleaner {
187
220
  async refreshStatus(): Promise<void> {
188
221
  if (!this.device.enableCloudService && this.OpenAPI) {
189
222
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
190
- } else/*if (this.BLE) {
223
+ } /*if (this.BLE) {
191
224
  await this.BLERefreshStatus();
192
- } else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
225
+ } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
193
226
  await this.openAPIRefreshStatus();
194
227
  } else {
195
228
  await this.offlineOff();
196
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
197
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
229
+ this.debugWarnLog(
230
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
231
+ ` ${this.device.connectionType}, refreshStatus will not happen.`,
232
+ );
198
233
  }
199
234
  }
200
235
 
@@ -219,8 +254,10 @@ export class RobotVacuumCleaner {
219
254
  // Set an event hander
220
255
  switchbot.onadvertisement = async (ad: any) => {
221
256
  this.address = ad.address;
222
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
223
- + ` BLE Address Found: ${this.address}`);
257
+ this.debugLog(
258
+ `${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
259
+ ` BLE Address Found: ${this.address}`,
260
+ );
224
261
  this.serviceData = ad.serviceData;
225
262
  this.state = ad.serviceData.state;
226
263
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
@@ -248,8 +285,10 @@ export class RobotVacuumCleaner {
248
285
  })
249
286
  .catch(async (e: any) => {
250
287
  this.apiError(e);
251
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
252
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
288
+ this.errorLog(
289
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
290
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
291
+ );
253
292
  await this.BLERefreshConnection(switchbot);
254
293
  });
255
294
  } else {
@@ -267,17 +306,17 @@ export class RobotVacuumCleaner {
267
306
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
268
307
  this.statusCode(statusCode);
269
308
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
270
- this.debugLog(
271
- `${this.device.deviceType}: ${this.accessory.displayName
272
- } refreshStatus: ${JSON.stringify(deviceStatus)}`,
273
- );
309
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
274
310
  this.power = deviceStatus.body.power;
311
+ this.Battery = deviceStatus.body.battery;
275
312
  this.openAPIparseStatus();
276
313
  this.updateHomeKitCharacteristics();
277
314
  } catch (e: any) {
278
315
  this.apiError(e);
279
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
280
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
316
+ this.errorLog(
317
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
318
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
319
+ );
281
320
  }
282
321
  }
283
322
 
@@ -293,14 +332,15 @@ export class RobotVacuumCleaner {
293
332
  async pushChanges(): Promise<void> {
294
333
  if (!this.device.enableCloudService && this.OpenAPI) {
295
334
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
296
- } else/* if (this.BLE) {
335
+ } /* if (this.BLE) {
297
336
  await this.BLEpushChanges();
298
- } else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
337
+ } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
299
338
  await this.openAPIpushChanges();
300
339
  } else {
301
340
  await this.offlineOff();
302
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
303
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
341
+ this.debugWarnLog(
342
+ `${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
343
+ );
304
344
  }
305
345
  // Refresh the status from the API
306
346
  interval(15000)
@@ -346,14 +386,15 @@ export class RobotVacuumCleaner {
346
386
  })
347
387
  .catch(async (e: any) => {
348
388
  this.apiError(e);
349
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
350
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
389
+ this.errorLog(
390
+ `${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
391
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
392
+ );
351
393
  await this.BLEPushConnection();
352
394
  });
353
395
  } else {
354
396
  this.debugLog(
355
- `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
356
- + `OnCached: ${this.accessory.context.On}`,
397
+ `${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
357
398
  );
358
399
  }
359
400
  }
@@ -368,9 +409,9 @@ export class RobotVacuumCleaner {
368
409
  command = 'turnOff';
369
410
  }
370
411
  const bodyChange = JSON.stringify({
371
- 'command': `${command}`,
372
- 'parameter': 'default',
373
- 'commandType': 'command',
412
+ command: `${command}`,
413
+ parameter: 'default',
414
+ commandType: 'command',
374
415
  });
375
416
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
376
417
  try {
@@ -385,13 +426,17 @@ export class RobotVacuumCleaner {
385
426
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
386
427
  } catch (e: any) {
387
428
  this.apiError(e);
388
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
389
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
429
+ this.errorLog(
430
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
431
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
390
432
  );
391
433
  }
392
434
  } else {
393
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
394
- + `OnCached: ${this.accessory.context.On}`);
435
+ this.debugLog(
436
+ `${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
437
+ `On: ${this.On}, ` +
438
+ `OnCached: ${this.accessory.context.On}`,
439
+ );
395
440
  }
396
441
  }
397
442
 
@@ -410,8 +455,9 @@ export class RobotVacuumCleaner {
410
455
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
411
456
  } catch (e: any) {
412
457
  this.apiError(e);
413
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
414
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
458
+ this.errorLog(
459
+ `${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
460
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
415
461
  );
416
462
  }
417
463
  }
@@ -427,9 +473,9 @@ export class RobotVacuumCleaner {
427
473
  parameter = 'default';
428
474
  }
429
475
  const body = JSON.stringify({
430
- 'command': `${command}`,
431
- 'parameter': `${parameter}`,
432
- 'commandType': 'command',
476
+ command: `${command}`,
477
+ parameter: `${parameter}`,
478
+ commandType: 'command',
433
479
  });
434
480
  return body;
435
481
  }
@@ -454,9 +500,9 @@ export class RobotVacuumCleaner {
454
500
  parameter = 'default';
455
501
  }
456
502
  const body = JSON.stringify({
457
- 'command': `${command}`,
458
- 'parameter': `${parameter}`,
459
- 'commandType': 'command',
503
+ command: `${command}`,
504
+ parameter: `${parameter}`,
505
+ commandType: 'command',
460
506
  });
461
507
  return body;
462
508
  }
@@ -635,8 +681,10 @@ export class RobotVacuumCleaner {
635
681
  this.offlineOff();
636
682
  break;
637
683
  case 171:
638
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
639
- + `Hub: ${this.device.hubDeviceId}`);
684
+ this.errorLog(
685
+ `${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
686
+ `Hub: ${this.device.hubDeviceId}`,
687
+ );
640
688
  this.offlineOff();
641
689
  break;
642
690
  case 190:
@@ -652,8 +700,10 @@ export class RobotVacuumCleaner {
652
700
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
653
701
  break;
654
702
  default:
655
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
656
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
703
+ this.infoLog(
704
+ `${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
705
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
706
+ );
657
707
  }
658
708
  }
659
709
 
@@ -670,8 +720,9 @@ export class RobotVacuumCleaner {
670
720
 
671
721
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
672
722
  let FirmwareRevision: string;
673
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
674
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
723
+ this.debugLog(
724
+ `${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
725
+ );
675
726
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
676
727
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
677
728
  if (accessory.context.FirmwareRevision) {
@@ -734,7 +785,7 @@ export class RobotVacuumCleaner {
734
785
  config['maxRetry'] = device.maxRetry;
735
786
  }
736
787
  if (Object.entries(config).length !== 0) {
737
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
788
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
738
789
  }
739
790
  }
740
791