@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-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 (197) hide show
  1. package/README.md +16 -0
  2. package/dist/device/blindtilt.d.ts +15 -6
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +224 -370
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +9 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +197 -221
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +10 -5
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +214 -292
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +10 -5
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +335 -421
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +9 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +121 -200
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +20 -7
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +229 -403
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +41 -22
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +212 -181
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +9 -4
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +204 -249
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +9 -5
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +107 -233
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +12 -4
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +193 -235
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +9 -4
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +92 -159
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +10 -5
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +288 -370
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +10 -5
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +172 -219
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +9 -4
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +94 -160
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +9 -4
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +95 -157
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +9 -4
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +85 -144
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +9 -4
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +100 -127
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +172 -259
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +12 -4
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +106 -131
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +2 -1
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +2 -3
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +2 -1
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +2 -3
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +2 -1
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +2 -3
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +2 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +2 -3
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +3 -1
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +5 -1
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts +2 -1
  99. package/dist/irdevice/light.d.ts.map +1 -1
  100. package/dist/irdevice/light.js +2 -3
  101. package/dist/irdevice/light.js.map +1 -1
  102. package/dist/irdevice/other.d.ts +2 -1
  103. package/dist/irdevice/other.d.ts.map +1 -1
  104. package/dist/irdevice/other.js +2 -3
  105. package/dist/irdevice/other.js.map +1 -1
  106. package/dist/irdevice/tv.d.ts +2 -1
  107. package/dist/irdevice/tv.d.ts.map +1 -1
  108. package/dist/irdevice/tv.js +2 -3
  109. package/dist/irdevice/tv.js.map +1 -1
  110. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  111. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.js +2 -3
  113. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  114. package/dist/irdevice/waterheater.d.ts +2 -1
  115. package/dist/irdevice/waterheater.d.ts.map +1 -1
  116. package/dist/irdevice/waterheater.js +2 -3
  117. package/dist/irdevice/waterheater.js.map +1 -1
  118. package/dist/platform.d.ts +14 -14
  119. package/dist/platform.d.ts.map +1 -1
  120. package/dist/platform.js +102 -86
  121. package/dist/platform.js.map +1 -1
  122. package/dist/settings.d.ts +49 -190
  123. package/dist/settings.d.ts.map +1 -1
  124. package/dist/settings.js +19 -0
  125. package/dist/settings.js.map +1 -1
  126. package/dist/types/bledevicestatus.d.ts +279 -0
  127. package/dist/types/bledevicestatus.d.ts.map +1 -0
  128. package/dist/types/bledevicestatus.js +2 -0
  129. package/dist/types/bledevicestatus.js.map +1 -0
  130. package/dist/types/devicelist.d.ts +89 -0
  131. package/dist/types/devicelist.d.ts.map +1 -0
  132. package/dist/types/devicelist.js +6 -0
  133. package/dist/types/devicelist.js.map +1 -0
  134. package/dist/types/deviceresponse.d.ts +13 -0
  135. package/dist/types/deviceresponse.d.ts.map +1 -0
  136. package/dist/types/deviceresponse.js +2 -0
  137. package/dist/types/deviceresponse.js.map +1 -0
  138. package/dist/types/devicestatus.d.ts +149 -0
  139. package/dist/types/devicestatus.d.ts.map +1 -0
  140. package/dist/types/devicestatus.js +3 -0
  141. package/dist/types/devicestatus.js.map +1 -0
  142. package/dist/types/devicewebhookstatus.d.ts +156 -0
  143. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  144. package/dist/types/devicewebhookstatus.js +2 -0
  145. package/dist/types/devicewebhookstatus.js.map +1 -0
  146. package/dist/types/irdevicelist.d.ts +10 -0
  147. package/dist/types/irdevicelist.d.ts.map +1 -0
  148. package/dist/types/irdevicelist.js +2 -0
  149. package/dist/types/irdevicelist.js.map +1 -0
  150. package/dist/types/pushbody.d.ts +6 -0
  151. package/dist/types/pushbody.d.ts.map +1 -0
  152. package/dist/types/pushbody.js +2 -0
  153. package/dist/types/pushbody.js.map +1 -0
  154. package/dist/utils.d.ts +25 -0
  155. package/dist/utils.d.ts.map +1 -1
  156. package/dist/utils.js +28 -0
  157. package/dist/utils.js.map +1 -1
  158. package/package.json +11 -11
  159. package/src/device/blindtilt.ts +254 -376
  160. package/src/device/bot.ts +209 -224
  161. package/src/device/ceilinglight.ts +227 -297
  162. package/src/device/colorbulb.ts +345 -435
  163. package/src/device/contact.ts +139 -200
  164. package/src/device/curtain.ts +254 -414
  165. package/src/device/device.ts +221 -190
  166. package/src/device/fan.ts +222 -253
  167. package/src/device/hub.ts +127 -248
  168. package/src/device/humidifier.ts +217 -246
  169. package/src/device/iosensor.ts +115 -168
  170. package/src/device/lightstrip.ts +303 -380
  171. package/src/device/lock.ts +188 -224
  172. package/src/device/meter.ts +117 -179
  173. package/src/device/meterplus.ts +118 -176
  174. package/src/device/motion.ts +100 -146
  175. package/src/device/plug.ts +111 -131
  176. package/src/device/robotvacuumcleaner.ts +191 -258
  177. package/src/device/waterdetector.ts +124 -141
  178. package/src/irdevice/airconditioner.ts +4 -4
  179. package/src/irdevice/airpurifier.ts +4 -4
  180. package/src/irdevice/camera.ts +4 -4
  181. package/src/irdevice/fan.ts +4 -4
  182. package/src/irdevice/irdevice.ts +8 -2
  183. package/src/irdevice/light.ts +4 -4
  184. package/src/irdevice/other.ts +4 -4
  185. package/src/irdevice/tv.ts +4 -4
  186. package/src/irdevice/vacuumcleaner.ts +4 -4
  187. package/src/irdevice/waterheater.ts +4 -4
  188. package/src/platform.ts +104 -87
  189. package/src/settings.ts +30 -238
  190. package/src/types/bledevicestatus.ts +305 -0
  191. package/src/types/devicelist.ts +124 -0
  192. package/src/types/deviceresponse.ts +15 -0
  193. package/src/types/devicestatus.ts +178 -0
  194. package/src/types/devicewebhookstatus.ts +196 -0
  195. package/src/types/irdevicelist.ts +15 -0
  196. package/src/types/pushbody.ts +9 -0
  197. package/src/utils.ts +33 -0
package/src/device/bot.ts CHANGED
@@ -3,12 +3,16 @@
3
3
  * bot.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
- import { interval, Subject } from 'rxjs';
7
- import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
7
+ import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
8
8
 
9
+ import type { devicesConfig } from '../settings.js';
10
+ import type { device } from '../types/devicelist.js';
9
11
  import type { SwitchBotPlatform } from '../platform.js';
12
+ import type { botServiceData } from '../types/bledevicestatus.js';
13
+ import type { botStatus } from '../types/devicestatus.js';
14
+ import type { botWebhookContext } from '../types/devicewebhookstatus.js';
10
15
  import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
11
- import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
12
16
 
13
17
  /**
14
18
  * Platform Accessory
@@ -135,7 +139,7 @@ export class Bot extends deviceBase {
135
139
  On: accessory.context.On ?? false,
136
140
  };
137
141
  accessory.context.Switch = this.Switch as object;
138
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
142
+ this.debugLog('Displaying as Switch');
139
143
 
140
144
  // Initialize Switch Characteristics
141
145
  this.Switch.Service
@@ -166,7 +170,7 @@ export class Bot extends deviceBase {
166
170
  On: accessory.context.On ?? false,
167
171
  };
168
172
  accessory.context.GarageDoor = this.GarageDoor as object;
169
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
173
+ this.debugLog('Displaying as Garage Door Opener');
170
174
 
171
175
  // Initialize GarageDoor Characteristics
172
176
  this.GarageDoor.Service
@@ -202,7 +206,7 @@ export class Bot extends deviceBase {
202
206
  On: accessory.context.On ?? false,
203
207
  };
204
208
  accessory.context.Door = this.Door as object;
205
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
209
+ this.debugLog('Displaying as Door');
206
210
 
207
211
  // Initialize Door Characteristics
208
212
  this.Door.Service
@@ -238,7 +242,7 @@ export class Bot extends deviceBase {
238
242
  On: accessory.context.On ?? false,
239
243
  };
240
244
  accessory.context.Window = this.Window as object;
241
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
245
+ this.debugLog('Displaying as Window');
242
246
 
243
247
  // Initialize Window Characteristics
244
248
  this.Window.Service
@@ -274,7 +278,7 @@ export class Bot extends deviceBase {
274
278
  On: accessory.context.On ?? false,
275
279
  };
276
280
  accessory.context.WindowCovering = this.WindowCovering as object;
277
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
281
+ this.debugLog('Displaying as Window Covering');
278
282
 
279
283
  // Initialize WindowCovering Characteristics
280
284
  this.WindowCovering.Service
@@ -310,7 +314,7 @@ export class Bot extends deviceBase {
310
314
  On: accessory.context.On ?? false,
311
315
  };
312
316
  accessory.context.LockMechanism = this.LockMechanism as object;
313
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
317
+ this.debugLog('Displaying as Lock');
314
318
 
315
319
  // Initialize Lock Characteristics
316
320
  this.LockMechanism.Service
@@ -340,7 +344,7 @@ export class Bot extends deviceBase {
340
344
  On: accessory.context.On ?? false,
341
345
  };
342
346
  accessory.context.Faucet = this.Faucet as object;
343
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
347
+ this.debugLog('Displaying as Faucet');
344
348
 
345
349
  // Initialize Faucet Characteristics
346
350
  this.Faucet.Service
@@ -370,7 +374,7 @@ export class Bot extends deviceBase {
370
374
  On: accessory.context.On ?? false,
371
375
  };
372
376
  accessory.context.Fan = this.Fan as object;
373
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
377
+ this.debugLog('Displaying as Fan');
374
378
 
375
379
  // Initialize Fan Characteristics
376
380
  this.Fan.Service
@@ -401,7 +405,7 @@ export class Bot extends deviceBase {
401
405
  On: accessory.context.On ?? false,
402
406
  };
403
407
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
404
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
408
+ this.debugLog('Displaying as Stateful Programmable Switch');
405
409
 
406
410
  // Initialize StatefulProgrammableSwitch Characteristics
407
411
  this.StatefulProgrammableSwitch.Service
@@ -431,7 +435,7 @@ export class Bot extends deviceBase {
431
435
  On: accessory.context.On ?? false,
432
436
  };
433
437
  accessory.context.Outlet = this.Outlet as object;
434
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
438
+ this.debugLog('Displaying as Outlet');
435
439
 
436
440
  // Initialize Outlet Characteristics
437
441
  this.Outlet.Service
@@ -460,6 +464,9 @@ export class Bot extends deviceBase {
460
464
  // Retrieve initial values and updateHomekit
461
465
  this.updateHomeKitCharacteristics();
462
466
 
467
+ // regisiter webhook event handler
468
+ this.registerWebhook();
469
+
463
470
  // Start an update interval
464
471
  interval(this.deviceRefreshRate * 1000)
465
472
  .pipe(skipWhile(() => this.botUpdateInProgress))
@@ -467,9 +474,6 @@ export class Bot extends deviceBase {
467
474
  await this.refreshStatus();
468
475
  });
469
476
 
470
- // regisiter webhook event handler
471
- this.registerWebhook(accessory, device);
472
-
473
477
  // Watch for Bot change events
474
478
  // We put in a debounce of 1000ms so we don't make duplicate calls
475
479
  this.doBotUpdate
@@ -491,9 +495,8 @@ export class Bot extends deviceBase {
491
495
  await this.pushChanges();
492
496
  }
493
497
  } catch (e: any) {
494
- this.apiError(e);
495
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed pushChanges with ${device.connectionType} Connection,`
496
- + ` Error Message: ${JSON.stringify(e.message)}`);
498
+ await this.apiError(e);
499
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
497
500
  }
498
501
  this.botUpdateInProgress = false;
499
502
  });
@@ -502,42 +505,37 @@ export class Bot extends deviceBase {
502
505
  /**
503
506
  * Parse the device status from the SwitchBotBLE API
504
507
  */
505
- async BLEparseStatus(serviceData: serviceData): Promise<void> {
506
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
508
+ async BLEparseStatus(serviceData: botServiceData): Promise<void> {
509
+ await this.debugLog('BLEparseStatus');
507
510
  // BLEmode (true if Switch Mode) | (false if Press Mode)
508
511
  if (serviceData.mode) {
509
512
  this.accessory.context.On = await this.getOn();
510
513
  if (this.getOn() === undefined) {
511
514
  this.setOn(Boolean(serviceData.state));
512
515
  }
513
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode,`
514
- + ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
516
+ this.debugLog(`Switch Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
515
517
  } else {
516
518
  this.setOn(false);
517
519
  this.accessory.context.On = await this.getOn();
518
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode,`
519
- + ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
520
+ this.debugLog(`Press Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
520
521
  }
521
522
 
523
+ // BatteryLevel
522
524
  this.Battery.BatteryLevel = Number(serviceData.battery);
523
- if (this.Battery.BatteryLevel < 10) {
524
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
525
- } else {
526
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
527
- }
528
- if (Number.isNaN(this.Battery.BatteryLevel)) {
529
- this.Battery.BatteryLevel = 100;
530
- }
531
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
532
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
525
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
526
+
527
+ // StatusLowBattery
528
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
529
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
530
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
533
531
  }
534
532
 
535
533
 
536
534
  /**
537
535
  * Parse the device status from the SwitchBot OpenAPI
538
536
  */
539
- async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
540
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
537
+ async openAPIparseStatus(deviceStatus: botStatus): Promise<void> {
538
+ await this.debugLog('openAPIparseStatus');
541
539
  if (this.botMode === 'press') {
542
540
  this.setOn(false);
543
541
  this.accessory.context.On = await this.getOn();
@@ -547,26 +545,22 @@ export class Bot extends deviceBase {
547
545
  this.setOn(false);
548
546
  }
549
547
  }
550
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.accessory.context.On}`);
548
+ await this.debugLog(`On: ${this.accessory.context.On}`);
551
549
 
552
- // Battery
553
- this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
554
- if (this.Battery.BatteryLevel < 10) {
555
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
556
- } else {
557
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
558
- }
559
- if (Number.isNaN(this.Battery.BatteryLevel)) {
560
- this.Battery.BatteryLevel = 100;
561
- }
562
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
563
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
550
+ // Battery Level
551
+ this.Battery.BatteryLevel = Number(deviceStatus.battery);
552
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
553
+
554
+ // StatusLowBattery
555
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
556
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
557
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
564
558
 
565
559
  // Firmware Version
566
- const version = deviceStatus.body.version?.toString();
567
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
568
- if (deviceStatus.body.version) {
569
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
560
+ const version = deviceStatus.version.toString();
561
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
562
+ if (deviceStatus.version) {
563
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
570
564
  this.accessory
571
565
  .getService(this.hap.Service.AccessoryInformation)!
572
566
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -574,29 +568,49 @@ export class Bot extends deviceBase {
574
568
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
575
569
  .updateValue(deviceVersion);
576
570
  this.accessory.context.deviceVersion = deviceVersion;
577
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
571
+ await this.debugLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
578
572
  }
579
573
  }
580
574
 
575
+ async parseStatusWebhook(context: botWebhookContext): Promise<void> {
576
+ await this.debugLog('parseStatusWebhook');
577
+ const getOn = await this.getOn();
578
+ await this.debugLog(`(power, battery, deviceMode) = Webhook:(${context.power}, ${context.battery}, ${context.deviceMode}),`
579
+ + ` current:(${getOn}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
580
+ // On
581
+ const setOn = context.power === 'on' ? true : false;
582
+ await this.setOn(setOn);
583
+ await this.debugLog(`On: ${setOn}`);
584
+ // BatteryLevel
585
+ this.Battery.BatteryLevel = context.battery;
586
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
587
+ // StatusLowBattery
588
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
589
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
590
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
591
+ // Mode
592
+ this.botMode = context.deviceMode;
593
+ await this.debugLog(`Mode: ${this.botMode}`);
594
+ }
595
+
581
596
  /**
582
597
  * Asks the SwitchBot API for the latest device information
583
598
  */
584
599
  async refreshStatus(): Promise<void> {
585
600
  if (!this.device.enableCloudService && this.OpenAPI) {
586
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
601
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
587
602
  } else if (this.BLE) {
588
603
  await this.BLERefreshStatus();
589
604
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
590
605
  await this.openAPIRefreshStatus();
591
606
  } else {
592
607
  await this.offlineOff();
593
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
594
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
608
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
595
609
  }
596
610
  }
597
611
 
598
612
  async BLERefreshStatus(): Promise<void> {
599
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
613
+ await this.debugLog('BLERefreshStatus');
600
614
  const switchbot = await this.switchbotBLE();
601
615
 
602
616
  if (switchbot === undefined) {
@@ -605,13 +619,13 @@ export class Bot extends deviceBase {
605
619
  // Start to monitor advertisement packets
606
620
  (async () => {
607
621
  // Start to monitor advertisement packets
608
- const serviceData: serviceData = await this.monitorAdvertisementPackets(switchbot);
622
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
609
623
  // Update HomeKit
610
- if (serviceData.model !== '' && serviceData.modelName !== '') {
624
+ if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
611
625
  await this.BLEparseStatus(serviceData);
612
626
  await this.updateHomeKitCharacteristics();
613
627
  } else {
614
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
628
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
615
629
  await this.BLERefreshConnection(switchbot);
616
630
  }
617
631
  })();
@@ -619,47 +633,39 @@ export class Bot extends deviceBase {
619
633
  }
620
634
 
621
635
  async openAPIRefreshStatus(): Promise<void> {
622
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
636
+ await this.debugLog('openAPIRefreshStatus');
623
637
  try {
624
638
  const { body, statusCode } = await this.deviceRefreshStatus();
625
639
  const deviceStatus: any = await body.json();
626
- await this.refreshStatusCodes(statusCode, deviceStatus);;
627
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
628
- await this.successfulRefreshStatus(statusCode, deviceStatus);
629
- await this.openAPIparseStatus(deviceStatus);
640
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
641
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
642
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
643
+ await this.openAPIparseStatus(deviceStatus.body);
630
644
  await this.updateHomeKitCharacteristics();
631
645
  } else {
632
- await this.statusCodes(statusCode, deviceStatus);
646
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
647
+ await this.debugWarnLog(statusCode, deviceStatus);
633
648
  }
634
649
  } catch (e: any) {
635
- this.apiError(e);
636
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
637
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
650
+ await this.apiError(e);
651
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
638
652
  }
639
653
  }
640
654
 
641
- async registerWebhook(accessory: PlatformAccessory, device: device & devicesConfig) {
642
- if (device.webhook) {
643
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
644
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
655
+ async registerWebhook() {
656
+ if (this.device.webhook) {
657
+ await this.debugLog('is listening webhook.');
658
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context: botWebhookContext) => {
645
659
  try {
646
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
647
- const { power, battery, deviceMode } = context;
648
- const { botMode } = this;
649
- const On = await this.getOn();
650
- const { BatteryLevel } = this.Battery;
651
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (power, battery, deviceMode) = Webhook:(${power}, ${battery}, ${deviceMode}),`
652
- + ` current:(${On}, ${BatteryLevel}, ${botMode})`);
653
- await this.setOn(power);
654
- this.Battery.BatteryLevel = battery;
655
- this.botMode = deviceMode;
656
- this.updateHomeKitCharacteristics();
660
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
661
+ await this.parseStatusWebhook(context);
662
+ await this.updateHomeKitCharacteristics();
657
663
  } catch (e: any) {
658
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
664
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
659
665
  }
660
666
  };
661
667
  } else {
662
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
668
+ await this.debugLog('is not listening webhook.');
663
669
  }
664
670
  }
665
671
 
@@ -672,15 +678,14 @@ export class Bot extends deviceBase {
672
678
  */
673
679
  async pushChanges(): Promise<void> {
674
680
  if (!this.device.enableCloudService && this.OpenAPI) {
675
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
681
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
676
682
  } else if (this.BLE) {
677
683
  await this.BLEpushChanges();
678
684
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
679
685
  await this.openAPIpushChanges();
680
686
  } else {
681
687
  await this.offlineOff();
682
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
683
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
688
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
684
689
  }
685
690
  // Refresh the status from the API
686
691
  interval(15000)
@@ -692,48 +697,44 @@ export class Bot extends deviceBase {
692
697
  }
693
698
 
694
699
  async BLEpushChanges(): Promise<void> {
695
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
700
+ await this.debugLog('BLEpushChanges');
696
701
  const On = await this.getOn();
697
702
  if (On !== this.accessory.context.On || this.allowPush) {
698
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
699
- const switchbot = await this.platform.connectBLE();
700
- // Convert to BLE Address
703
+ this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
704
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
701
705
  await this.convertBLEAddress();
702
706
  //if (switchbot !== false) {
703
707
  if (this.botMode === 'press') {
704
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
708
+ this.debugLog(`Bot Mode: ${this.botMode}`);
705
709
  switchbot
706
710
  .discover({ model: 'H', quick: true, id: this.device.bleMac })
707
711
  .then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
708
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
712
+ this.infoLog(`On: ${On}`);
709
713
  return await device_list[0].press({ id: this.device.bleMac });
710
714
  })
711
- .then(() => {
712
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
713
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
714
- + `On: ${On} sent over BLE, sent successfully`);
715
- this.accessory.context.On = On;
715
+ .then(async () => {
716
+ await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
717
+ await this.updateHomeKitCharacteristics();
716
718
  setTimeout(() => {
717
719
  if (this.botDeviceType === 'switch') {
718
720
  this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
719
721
  } else {
720
722
  this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
721
723
  }
722
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}, Switch Timeout`);
724
+ this.debugLog(`On: ${On}, Switch Timeout`);
723
725
  }, 500);
724
726
  })
725
727
  .catch(async (e: any) => {
726
- this.apiError(e);
727
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
728
- + ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
728
+ await this.apiError(e);
729
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
729
730
  await this.BLEPushConnection();
730
731
  });
731
732
  } else if (this.botMode === 'switch') {
732
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
733
+ this.debugLog(`Press Mode: ${this.botMode}`);
733
734
  switchbot
734
735
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
735
736
  .then(async (device_list: any) => {
736
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
737
+ this.infoLog(`On: ${On}`);
737
738
  return await this.retryBLE({
738
739
  max: await this.maxRetryBLE(),
739
740
  fn: async () => {
@@ -745,29 +746,28 @@ export class Bot extends deviceBase {
745
746
  },
746
747
  });
747
748
  })
748
- .then(() => {
749
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
750
- this.accessory.context.On = On;
749
+ .then(async () => {
750
+ await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
751
+ await this.updateHomeKitCharacteristics();
751
752
  })
752
753
  .catch(async (e: any) => {
753
- this.apiError(e);
754
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
755
- + ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
754
+ await this.apiError(e);
755
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
756
756
  await this.BLEPushConnection();
757
757
  });
758
758
  } else {
759
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
759
+ await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
760
760
  }
761
761
  } else {
762
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, On: ${On}, OnCached: ${this.accessory.context.On}`);
762
+ await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
763
763
  }
764
764
  }
765
765
 
766
766
  async openAPIpushChanges(): Promise<void> {
767
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
767
+ await this.debugLog('openAPIpushChanges');
768
768
  let On = await this.getOn();
769
769
  if (this.multiPressCount > 0) {
770
- this.debugLog(`${this.device.deviceType}: ${this.multiPressCount} request(s) queued.`);
770
+ await this.debugLog(`${this.multiPressCount} request(s) queued.`);
771
771
  On = true;
772
772
  }
773
773
  if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
@@ -775,30 +775,30 @@ export class Bot extends deviceBase {
775
775
  if (this.botMode === 'switch' && On) {
776
776
  command = 'turnOn';
777
777
  On = true;
778
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
778
+ await this.debugLog(`Switch Mode, Turning ${On}`);
779
779
  } else if (this.botMode === 'switch' && !On) {
780
780
  command = 'turnOff';
781
781
  On = false;
782
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
782
+ await this.debugLog(`Switch Mode, Turning ${On}`);
783
783
  } else if (this.botMode === 'press' || this.botMode === 'multipress') {
784
784
  command = 'press';
785
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode`);
785
+ await this.debugLog('Press Mode');
786
786
  On = false;
787
787
  } else {
788
- throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Parameters not set for this Bot.`);
788
+ throw new Error('Device Parameters not set for this Bot.');
789
789
  }
790
790
  const bodyChange = JSON.stringify({
791
791
  command: `${command}`,
792
792
  parameter: 'default',
793
793
  commandType: 'command',
794
794
  });
795
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
795
+ this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
796
796
  try {
797
797
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
798
798
  const deviceStatus: any = await body.json();
799
- await this.pushStatusCodes(statusCode, deviceStatus);
800
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
801
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
799
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
800
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
801
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
802
802
  await this.updateHomeKitCharacteristics();
803
803
  } else {
804
804
  await this.statusCode(statusCode);
@@ -807,19 +807,17 @@ export class Bot extends deviceBase {
807
807
  if (this.device.bot?.mode === 'multipress') {
808
808
  this.multiPressCount--;
809
809
  if (this.multiPressCount > 0) {
810
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Multi Press Count: ${this.multiPressCount}`);
810
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
811
811
  On = true;
812
- this.openAPIpushChanges();
812
+ await this.openAPIpushChanges();
813
813
  }
814
814
  }
815
815
  } catch (e: any) {
816
- this.apiError(e);
817
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
818
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
816
+ await this.apiError(e);
817
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
819
818
  }
820
819
  } else {
821
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges,`
822
- + ` On: ${On}, OnCached: ${this.accessory.context.On}`);
820
+ await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
823
821
  }
824
822
  }
825
823
 
@@ -829,7 +827,8 @@ export class Bot extends deviceBase {
829
827
  async OnSet(value: CharacteristicValue): Promise<void> {
830
828
  if (this.botDeviceType === 'garagedoor') {
831
829
  if (this.GarageDoor) {
832
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
830
+ await this.debugLog(`Set TargetDoorState: ${value}`);
831
+ this.infoLog(`Set TargetDoorState: ${value}`);
833
832
  if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
834
833
  await this.setOn(false);
835
834
  this.GarageDoor.On = false;
@@ -840,7 +839,7 @@ export class Bot extends deviceBase {
840
839
  }
841
840
  } else if (this.botDeviceType === 'door') {
842
841
  if (this.Door) {
843
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
842
+ await this.debugLog(`Set TargetPosition: ${value}`);
844
843
  if (value === 0) {
845
844
  await this.setOn(false);
846
845
  this.Door.On = false;
@@ -851,7 +850,7 @@ export class Bot extends deviceBase {
851
850
  }
852
851
  } else if (this.botDeviceType === 'window') {
853
852
  if (this.Window) {
854
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
853
+ await this.debugLog(`Set TargetPosition: ${value}`);
855
854
  if (value === 0) {
856
855
  await this.setOn(false);
857
856
  this.Window.On = false;
@@ -862,7 +861,7 @@ export class Bot extends deviceBase {
862
861
  }
863
862
  } else if (this.botDeviceType === 'windowcovering') {
864
863
  if (this.WindowCovering) {
865
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
864
+ await this.debugLog(`Set TargetPosition: ${value}`);
866
865
  if (value === 0) {
867
866
  await this.setOn(false);
868
867
  this.WindowCovering.On = false;
@@ -873,7 +872,7 @@ export class Bot extends deviceBase {
873
872
  }
874
873
  } else if (this.botDeviceType === 'lock') {
875
874
  if (this.LockMechanism) {
876
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
875
+ await this.debugLog(`Set LockTargetState: ${value}`);
877
876
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
878
877
  await this.setOn(false);
879
878
  this.LockMechanism.On = false;
@@ -884,7 +883,7 @@ export class Bot extends deviceBase {
884
883
  }
885
884
  } else if (this.botDeviceType === 'faucet') {
886
885
  if (this.Faucet) {
887
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
886
+ await this.debugLog(`Set Active: ${value}`);
888
887
  if (value === this.hap.Characteristic.Active.INACTIVE) {
889
888
  await this.setOn(false);
890
889
  this.Faucet.On = false;
@@ -895,7 +894,7 @@ export class Bot extends deviceBase {
895
894
  }
896
895
  } else if (this.botDeviceType === 'stateful') {
897
896
  if (this.StatefulProgrammableSwitch) {
898
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
897
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
899
898
  if (value === 0) {
900
899
  await this.setOn(false);
901
900
  this.StatefulProgrammableSwitch.On = false;
@@ -906,7 +905,7 @@ export class Bot extends deviceBase {
906
905
  }
907
906
  } else if (this.botDeviceType === 'switch') {
908
907
  if (this.Switch) {
909
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
908
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
910
909
  if (value === 0) {
911
910
  await this.setOn(false);
912
911
  this.Switch.On = false;
@@ -917,7 +916,7 @@ export class Bot extends deviceBase {
917
916
  }
918
917
  } else {
919
918
  if (this.Outlet) {
920
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
919
+ await this.debugLog(`Set On: ${value}`);
921
920
  await this.setOn(Boolean(value));
922
921
  this.Outlet.On = value;
923
922
  }
@@ -925,7 +924,7 @@ export class Bot extends deviceBase {
925
924
  if (this.device.bot?.mode === 'multipress') {
926
925
  if (value === true) {
927
926
  this.multiPressCount++;
928
- this.debugLog(`${this.device.deviceType} set to Multi-Press. Multi-Press count: ${this.multiPressCount}`);
927
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
929
928
  }
930
929
  }
931
930
  this.doBotUpdate.next();
@@ -938,186 +937,173 @@ export class Bot extends deviceBase {
938
937
  // State
939
938
  if (this.botDeviceType === 'garagedoor') {
940
939
  if (this.GarageDoor?.On === undefined) {
941
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.GarageDoor?.On}`);
940
+ await this.debugLog(`On: ${this.GarageDoor?.On}`);
942
941
  } else {
943
942
  if (this.GarageDoor.On) {
944
943
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
945
944
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
946
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
947
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
945
+ await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
948
946
  } else {
949
947
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
950
948
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
951
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
952
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
949
+ await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
953
950
  }
954
951
  }
955
952
  await this.setOn(Boolean(this.GarageDoor?.On));
956
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor?.On}`);
953
+ await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
957
954
  } else if (this.botDeviceType === 'door') {
958
955
  if (this.Door?.On === undefined) {
959
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Door?.On}`);
956
+ await this.debugLog(`On: ${this.Door?.On}`);
960
957
  } else {
961
958
  if (this.Door.On) {
962
959
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
963
960
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
964
961
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
965
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
966
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
962
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
967
963
  } else {
968
964
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
969
965
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
970
966
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
971
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
972
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
967
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
973
968
  }
974
969
  }
975
970
  await this.setOn(Boolean(this.Door?.On));
976
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Door On: ${this.Door?.On}`);
971
+ await this.debugLog(`Door On: ${this.Door?.On}`);
977
972
  } else if (this.botDeviceType === 'window') {
978
973
  if (this.Window?.On === undefined) {
979
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Window?.On}`);
974
+ await this.debugLog(`On: ${this.Window?.On}`);
980
975
  } else {
981
976
  if (this.Window.On) {
982
977
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
983
978
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
984
979
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
985
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
986
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
980
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
987
981
  } else {
988
982
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
989
983
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
990
984
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
991
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
992
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
985
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
993
986
  }
994
987
  }
995
988
  await this.setOn(Boolean(this.Window?.On));
996
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window On: ${this.Window?.On}`);
989
+ await this.debugLog(`Window On: ${this.Window?.On}`);
997
990
  } else if (this.botDeviceType === 'windowcovering') {
998
991
  if (this.WindowCovering?.On === undefined) {
999
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.WindowCovering?.On}`);
992
+ await this.debugLog(`On: ${this.WindowCovering?.On}`);
1000
993
  } else {
1001
994
  if (this.WindowCovering.On) {
1002
995
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
1003
996
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
1004
997
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1005
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
1006
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
998
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
1007
999
  } else {
1008
1000
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1009
1001
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1010
1002
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1011
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
1012
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
1003
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
1013
1004
  }
1014
1005
  }
1015
1006
  await this.setOn(Boolean(this.WindowCovering?.On));
1016
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering?.On}`);
1007
+ await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
1017
1008
  } else if (this.botDeviceType === 'lock') {
1018
1009
  if (this.LockMechanism?.On === undefined) {
1019
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockMechanism?.On}`);
1010
+ await this.debugLog(`On: ${this.LockMechanism?.On}`);
1020
1011
  } else {
1021
1012
  if (this.LockMechanism.On) {
1022
1013
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
1023
1014
  this.hap.Characteristic.LockTargetState.UNSECURED);
1024
1015
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
1025
1016
  this.hap.Characteristic.LockCurrentState.UNSECURED);
1026
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
1027
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
1017
+ await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
1028
1018
  } else {
1029
1019
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
1030
1020
  this.hap.Characteristic.LockTargetState.SECURED);
1031
1021
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
1032
1022
  this.hap.Characteristic.LockCurrentState.SECURED);
1033
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1034
- + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
1023
+ await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
1035
1024
  }
1036
1025
  }
1037
1026
  await this.setOn(Boolean(this.LockMechanism?.On));
1038
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.LockMechanism?.On}`);
1027
+ await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
1039
1028
  } else if (this.botDeviceType === 'faucet') {
1040
1029
  if (this.Faucet?.On === undefined) {
1041
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Faucet?.On}`);
1030
+ await this.debugLog(`On: ${this.Faucet?.On}`);
1042
1031
  } else {
1043
1032
  if (this.Faucet.On) {
1044
1033
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
1045
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
1034
+ await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1046
1035
  } else {
1047
1036
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
1048
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
1037
+ await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1049
1038
  }
1050
1039
  }
1051
1040
  await this.setOn(Boolean(this.Faucet?.On));
1052
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Faucet On: ${this.Faucet?.On}`);
1041
+ await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
1053
1042
  } else if (this.botDeviceType === 'fan') {
1054
1043
  if (this.Fan?.On === undefined) {
1055
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan?.On}`);
1044
+ await this.debugLog(`On: ${this.Fan?.On}`);
1056
1045
  } else {
1057
1046
  if (this.Fan.On) {
1058
1047
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1059
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
1048
+ await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1060
1049
  } else {
1061
1050
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1062
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
1051
+ await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1063
1052
  }
1064
1053
  }
1065
1054
  await this.setOn(Boolean(this.Fan?.On));
1066
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Fan On: ${this.Fan?.On}`);
1055
+ await this.debugLog(`Fan On: ${this.Fan?.On}`);
1067
1056
  } else if (this.botDeviceType === 'stateful') {
1068
1057
  if (this.StatefulProgrammableSwitch?.On === undefined) {
1069
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch?.On}`);
1058
+ await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
1070
1059
  } else {
1071
1060
  if (this.StatefulProgrammableSwitch.On) {
1072
1061
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1073
1062
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1074
1063
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
1075
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1076
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
1064
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1077
1065
  } else {
1078
1066
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1079
1067
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1080
1068
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
1081
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1082
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
1069
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1083
1070
  }
1084
1071
  }
1085
1072
  await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
1086
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1073
+ await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1087
1074
  } else if (this.botDeviceType === 'switch') {
1088
1075
  if (this.Switch?.On === undefined) {
1089
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Switch?.On}`);
1076
+ await this.debugLog(`On: ${this.Switch?.On}`);
1090
1077
  } else {
1091
1078
  this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
1092
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
1079
+ await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
1093
1080
  }
1094
1081
  await this.setOn(Boolean(this.Switch?.On));
1095
1082
  } else {
1096
1083
  if (this.Outlet?.On === undefined) {
1097
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Outlet?.On}`);
1084
+ await this.debugLog(`On: ${this.Outlet?.On}`);
1098
1085
  } else {
1099
1086
  this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
1100
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet.On}`);
1087
+ await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
1101
1088
  }
1102
1089
  await this.setOn(Boolean(this.Outlet?.On));
1103
1090
  }
1104
1091
  this.accessory.context.On = await this.getOn();
1105
1092
  // BatteryLevel
1106
1093
  if (this.Battery.BatteryLevel === undefined) {
1107
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
1094
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
1108
1095
  } else {
1109
1096
  this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
1110
1097
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
1111
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1098
+ await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1112
1099
  }
1113
1100
  // StatusLowBattery
1114
1101
  if (this.Battery.StatusLowBattery === undefined) {
1115
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1102
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1116
1103
  } else {
1117
1104
  this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
1118
1105
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
1119
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1120
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1106
+ await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1121
1107
  }
1122
1108
  }
1123
1109
 
@@ -1125,7 +1111,7 @@ export class Bot extends deviceBase {
1125
1111
  // If outletService still present, then remove first
1126
1112
  if (this.Outlet?.Service) {
1127
1113
  this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
1128
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
1114
+ await this.warnLog('Removing Leftover Outlet Service');
1129
1115
  accessory.removeService(this.Outlet.Service);
1130
1116
  }
1131
1117
  }
@@ -1134,7 +1120,7 @@ export class Bot extends deviceBase {
1134
1120
  // If garageDoorService still present, then remove first
1135
1121
  if (this.GarageDoor?.Service) {
1136
1122
  this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
1137
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
1123
+ await this.warnLog('Removing Leftover Garage Door Service');
1138
1124
  accessory.removeService(this.GarageDoor.Service);
1139
1125
  }
1140
1126
  }
@@ -1143,7 +1129,7 @@ export class Bot extends deviceBase {
1143
1129
  // If doorService still present, then remove first
1144
1130
  if (this.Door?.Service) {
1145
1131
  this.Door.Service = this.accessory.getService(this.hap.Service.Door) as Service;
1146
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
1132
+ await this.warnLog('Removing Leftover Door Service');
1147
1133
  accessory.removeService(this.Door.Service);
1148
1134
  }
1149
1135
  }
@@ -1152,7 +1138,7 @@ export class Bot extends deviceBase {
1152
1138
  // If lockService still present, then remove first
1153
1139
  if (this.LockMechanism?.Service) {
1154
1140
  this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
1155
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
1141
+ this.warnLog('Removing Leftover Lock Service');
1156
1142
  accessory.removeService(this.LockMechanism.Service);
1157
1143
  }
1158
1144
  }
@@ -1161,7 +1147,7 @@ export class Bot extends deviceBase {
1161
1147
  // If faucetService still present, then remove first
1162
1148
  if (this.Faucet?.Service) {
1163
1149
  this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
1164
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
1150
+ await this.warnLog('Removing Leftover Faucet Service');
1165
1151
  accessory.removeService(this.Faucet.Service);
1166
1152
  }
1167
1153
  }
@@ -1170,7 +1156,7 @@ export class Bot extends deviceBase {
1170
1156
  // If fanService still present, then remove first
1171
1157
  if (this.Fan?.Service) {
1172
1158
  this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2) as Service;
1173
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
1159
+ this.warnLog('Removing Leftover Fan Service');
1174
1160
  accessory.removeService(this.Fan.Service);
1175
1161
  }
1176
1162
  }
@@ -1179,7 +1165,7 @@ export class Bot extends deviceBase {
1179
1165
  // If windowService still present, then remove first
1180
1166
  if (this.Window?.Service) {
1181
1167
  this.Window.Service = this.accessory.getService(this.hap.Service.Window) as Service;
1182
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
1168
+ await this.warnLog('Removing Leftover Window Service');
1183
1169
  accessory.removeService(this.Window.Service);
1184
1170
  }
1185
1171
  }
@@ -1188,7 +1174,7 @@ export class Bot extends deviceBase {
1188
1174
  // If windowCoveringService still present, then remove first
1189
1175
  if (this.WindowCovering?.Service) {
1190
1176
  this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
1191
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
1177
+ await this.warnLog('Removing Leftover Window Covering Service');
1192
1178
  accessory.removeService(this.WindowCovering.Service);
1193
1179
  }
1194
1180
  }
@@ -1197,7 +1183,7 @@ export class Bot extends deviceBase {
1197
1183
  // If statefulProgrammableSwitchService still present, then remove first
1198
1184
  if (this.StatefulProgrammableSwitch?.Service) {
1199
1185
  this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
1200
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
1186
+ await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
1201
1187
  accessory.removeService(this.StatefulProgrammableSwitch.Service);
1202
1188
  }
1203
1189
  }
@@ -1206,7 +1192,7 @@ export class Bot extends deviceBase {
1206
1192
  // If switchService still present, then remove first
1207
1193
  if (this.Switch?.Service) {
1208
1194
  this.Switch.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
1209
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
1195
+ await this.warnLog('Removing Leftover Switch Service');
1210
1196
  accessory.removeService(this.Switch.Service);
1211
1197
  }
1212
1198
  }
@@ -1285,33 +1271,33 @@ export class Bot extends deviceBase {
1285
1271
  //Bot Device Type
1286
1272
  if (!device.bot?.deviceType && this.accessory.context.deviceType) {
1287
1273
  this.botDeviceType = this.accessory.context.deviceType;
1288
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
1274
+ await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
1289
1275
  } else if (device.bot?.deviceType) {
1290
1276
  this.accessory.context.deviceType = device.bot.deviceType;
1291
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Accessory Cache: ${this.accessory.context.deviceType}`);
1277
+ await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
1292
1278
  this.botDeviceType = this.accessory.context.deviceType;
1293
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}`);
1279
+ await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
1294
1280
  } else {
1295
1281
  this.botDeviceType = 'outlet';
1296
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
1297
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using default deviceType: ${this.botDeviceType}`);
1282
+ await this.errorLog(`No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
1283
+ await this.warnLog(`Using default deviceType: ${this.botDeviceType}`);
1298
1284
  }
1299
1285
  // Bot Mode
1300
1286
  if (!device.bot?.mode) {
1301
1287
  this.botMode = 'switch';
1302
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
1303
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
1288
+ await this.warnLog('does not have bot mode set in the Plugin\'s SwitchBot Device Settings,');
1289
+ await this.warnLog(`is defaulting to "${this.botMode}" mode, you may experience issues.`);
1304
1290
  } else if (device.bot?.mode === 'switch') {
1305
1291
  this.botMode = 'switch';
1306
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1292
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1307
1293
  } else if (device.bot?.mode === 'press') {
1308
1294
  this.botMode = 'press';
1309
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1295
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1310
1296
  } else if (device.bot?.mode === 'multipress') {
1311
1297
  this.botMode = 'multipress';
1312
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1298
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1313
1299
  } else {
1314
- throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1300
+ throw new Error(`Bot Mode: ${this.botMode}`);
1315
1301
  }
1316
1302
 
1317
1303
  // Bot Double Press
@@ -1325,10 +1311,10 @@ export class Bot extends deviceBase {
1325
1311
  // Bot Press PushRate
1326
1312
  if (device?.bot?.pushRatePress) {
1327
1313
  this.pushRatePress = device?.bot?.pushRatePress;
1328
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
1314
+ await this.debugLog(`Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
1329
1315
  } else {
1330
1316
  this.pushRatePress = 15;
1331
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Bot pushRatePress: ${this.pushRatePress}`);
1317
+ await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
1332
1318
  }
1333
1319
 
1334
1320
  // Bot Allow Push
@@ -1337,23 +1323,22 @@ export class Bot extends deviceBase {
1337
1323
  } else {
1338
1324
  this.allowPush = false;
1339
1325
  }
1340
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1326
+ await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
1341
1327
  // Bot Multi Press Count
1342
1328
  this.multiPressCount = 0;
1343
1329
  }
1344
1330
 
1345
1331
  async BLEPushConnection() {
1346
1332
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1347
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
1333
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
1348
1334
  await this.openAPIpushChanges();
1349
1335
  }
1350
1336
  }
1351
1337
 
1352
1338
  async BLERefreshConnection(switchbot: any): Promise<void> {
1353
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
1354
- + ` ${JSON.stringify(switchbot)}`);
1339
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
1355
1340
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1356
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
1341
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
1357
1342
  await this.openAPIRefreshStatus();
1358
1343
  }
1359
1344
  }