@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
@@ -3,8 +3,8 @@
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
9
  * Platform Accessory
10
10
  * An instance of this class is created for each accessory your platform registers
@@ -66,7 +66,7 @@ export class Bot extends deviceBase {
66
66
  On: accessory.context.On ?? false,
67
67
  };
68
68
  accessory.context.Switch = this.Switch;
69
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
69
+ this.debugLog('Displaying as Switch');
70
70
  // Initialize Switch Characteristics
71
71
  this.Switch.Service
72
72
  .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
@@ -96,7 +96,7 @@ export class Bot extends deviceBase {
96
96
  On: accessory.context.On ?? false,
97
97
  };
98
98
  accessory.context.GarageDoor = this.GarageDoor;
99
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
99
+ this.debugLog('Displaying as Garage Door Opener');
100
100
  // Initialize GarageDoor Characteristics
101
101
  this.GarageDoor.Service
102
102
  .setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
@@ -131,7 +131,7 @@ export class Bot extends deviceBase {
131
131
  On: accessory.context.On ?? false,
132
132
  };
133
133
  accessory.context.Door = this.Door;
134
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
134
+ this.debugLog('Displaying as Door');
135
135
  // Initialize Door Characteristics
136
136
  this.Door.Service
137
137
  .setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
@@ -166,7 +166,7 @@ export class Bot extends deviceBase {
166
166
  On: accessory.context.On ?? false,
167
167
  };
168
168
  accessory.context.Window = this.Window;
169
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
169
+ this.debugLog('Displaying as Window');
170
170
  // Initialize Window Characteristics
171
171
  this.Window.Service
172
172
  .setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
@@ -201,7 +201,7 @@ export class Bot extends deviceBase {
201
201
  On: accessory.context.On ?? false,
202
202
  };
203
203
  accessory.context.WindowCovering = this.WindowCovering;
204
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
204
+ this.debugLog('Displaying as Window Covering');
205
205
  // Initialize WindowCovering Characteristics
206
206
  this.WindowCovering.Service
207
207
  .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
@@ -236,7 +236,7 @@ export class Bot extends deviceBase {
236
236
  On: accessory.context.On ?? false,
237
237
  };
238
238
  accessory.context.LockMechanism = this.LockMechanism;
239
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
239
+ this.debugLog('Displaying as Lock');
240
240
  // Initialize Lock Characteristics
241
241
  this.LockMechanism.Service
242
242
  .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
@@ -265,7 +265,7 @@ export class Bot extends deviceBase {
265
265
  On: accessory.context.On ?? false,
266
266
  };
267
267
  accessory.context.Faucet = this.Faucet;
268
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
268
+ this.debugLog('Displaying as Faucet');
269
269
  // Initialize Faucet Characteristics
270
270
  this.Faucet.Service
271
271
  .setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
@@ -294,7 +294,7 @@ export class Bot extends deviceBase {
294
294
  On: accessory.context.On ?? false,
295
295
  };
296
296
  accessory.context.Fan = this.Fan;
297
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
297
+ this.debugLog('Displaying as Fan');
298
298
  // Initialize Fan Characteristics
299
299
  this.Fan.Service
300
300
  .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
@@ -324,7 +324,7 @@ export class Bot extends deviceBase {
324
324
  On: accessory.context.On ?? false,
325
325
  };
326
326
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch;
327
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
327
+ this.debugLog('Displaying as Stateful Programmable Switch');
328
328
  // Initialize StatefulProgrammableSwitch Characteristics
329
329
  this.StatefulProgrammableSwitch.Service
330
330
  .setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
@@ -353,7 +353,7 @@ export class Bot extends deviceBase {
353
353
  On: accessory.context.On ?? false,
354
354
  };
355
355
  accessory.context.Outlet = this.Outlet;
356
- this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
356
+ this.debugLog('Displaying as Outlet');
357
357
  // Initialize Outlet Characteristics
358
358
  this.Outlet.Service
359
359
  .setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
@@ -377,14 +377,14 @@ export class Bot extends deviceBase {
377
377
  this.refreshStatus();
378
378
  // Retrieve initial values and updateHomekit
379
379
  this.updateHomeKitCharacteristics();
380
+ // regisiter webhook event handler
381
+ this.registerWebhook();
380
382
  // Start an update interval
381
383
  interval(this.deviceRefreshRate * 1000)
382
384
  .pipe(skipWhile(() => this.botUpdateInProgress))
383
385
  .subscribe(async () => {
384
386
  await this.refreshStatus();
385
387
  });
386
- // regisiter webhook event handler
387
- this.registerWebhook(accessory, device);
388
388
  // Watch for Bot change events
389
389
  // We put in a debounce of 1000ms so we don't make duplicate calls
390
390
  this.doBotUpdate
@@ -405,9 +405,8 @@ export class Bot extends deviceBase {
405
405
  }
406
406
  }
407
407
  catch (e) {
408
- this.apiError(e);
409
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed pushChanges with ${device.connectionType} Connection,`
410
- + ` Error Message: ${JSON.stringify(e.message)}`);
408
+ await this.apiError(e);
409
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
411
410
  }
412
411
  this.botUpdateInProgress = false;
413
412
  });
@@ -416,40 +415,33 @@ export class Bot extends deviceBase {
416
415
  * Parse the device status from the SwitchBotBLE API
417
416
  */
418
417
  async BLEparseStatus(serviceData) {
419
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
418
+ await this.debugLog('BLEparseStatus');
420
419
  // BLEmode (true if Switch Mode) | (false if Press Mode)
421
420
  if (serviceData.mode) {
422
421
  this.accessory.context.On = await this.getOn();
423
422
  if (this.getOn() === undefined) {
424
423
  this.setOn(Boolean(serviceData.state));
425
424
  }
426
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode,`
427
- + ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
425
+ this.debugLog(`Switch Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
428
426
  }
429
427
  else {
430
428
  this.setOn(false);
431
429
  this.accessory.context.On = await this.getOn();
432
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode,`
433
- + ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
430
+ this.debugLog(`Press Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
434
431
  }
432
+ // BatteryLevel
435
433
  this.Battery.BatteryLevel = Number(serviceData.battery);
436
- if (this.Battery.BatteryLevel < 10) {
437
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
438
- }
439
- else {
440
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
441
- }
442
- if (Number.isNaN(this.Battery.BatteryLevel)) {
443
- this.Battery.BatteryLevel = 100;
444
- }
445
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
446
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
434
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
435
+ // StatusLowBattery
436
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
437
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
438
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
447
439
  }
448
440
  /**
449
441
  * Parse the device status from the SwitchBot OpenAPI
450
442
  */
451
443
  async openAPIparseStatus(deviceStatus) {
452
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
444
+ await this.debugLog('openAPIparseStatus');
453
445
  if (this.botMode === 'press') {
454
446
  this.setOn(false);
455
447
  this.accessory.context.On = await this.getOn();
@@ -460,25 +452,19 @@ export class Bot extends deviceBase {
460
452
  this.setOn(false);
461
453
  }
462
454
  }
463
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.accessory.context.On}`);
464
- // Battery
465
- this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
466
- if (this.Battery.BatteryLevel < 10) {
467
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
468
- }
469
- else {
470
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
471
- }
472
- if (Number.isNaN(this.Battery.BatteryLevel)) {
473
- this.Battery.BatteryLevel = 100;
474
- }
475
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
476
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
455
+ await this.debugLog(`On: ${this.accessory.context.On}`);
456
+ // Battery Level
457
+ this.Battery.BatteryLevel = Number(deviceStatus.battery);
458
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
459
+ // StatusLowBattery
460
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
461
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
462
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
477
463
  // Firmware Version
478
- const version = deviceStatus.body.version?.toString();
479
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
480
- if (deviceStatus.body.version) {
481
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
464
+ const version = deviceStatus.version.toString();
465
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
466
+ if (deviceStatus.version) {
467
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
482
468
  this.accessory
483
469
  .getService(this.hap.Service.AccessoryInformation)
484
470
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -486,15 +472,35 @@ export class Bot extends deviceBase {
486
472
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
487
473
  .updateValue(deviceVersion);
488
474
  this.accessory.context.deviceVersion = deviceVersion;
489
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
475
+ await this.debugLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
490
476
  }
491
477
  }
478
+ async parseStatusWebhook(context) {
479
+ await this.debugLog('parseStatusWebhook');
480
+ const getOn = await this.getOn();
481
+ await this.debugLog(`(power, battery, deviceMode) = Webhook:(${context.power}, ${context.battery}, ${context.deviceMode}),`
482
+ + ` current:(${getOn}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
483
+ // On
484
+ const setOn = context.power === 'on' ? true : false;
485
+ await this.setOn(setOn);
486
+ await this.debugLog(`On: ${setOn}`);
487
+ // BatteryLevel
488
+ this.Battery.BatteryLevel = context.battery;
489
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
490
+ // StatusLowBattery
491
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
492
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
493
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
494
+ // Mode
495
+ this.botMode = context.deviceMode;
496
+ await this.debugLog(`Mode: ${this.botMode}`);
497
+ }
492
498
  /**
493
499
  * Asks the SwitchBot API for the latest device information
494
500
  */
495
501
  async refreshStatus() {
496
502
  if (!this.device.enableCloudService && this.OpenAPI) {
497
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
503
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
498
504
  }
499
505
  else if (this.BLE) {
500
506
  await this.BLERefreshStatus();
@@ -504,12 +510,11 @@ export class Bot extends deviceBase {
504
510
  }
505
511
  else {
506
512
  await this.offlineOff();
507
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
508
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
513
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
509
514
  }
510
515
  }
511
516
  async BLERefreshStatus() {
512
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
517
+ await this.debugLog('BLERefreshStatus');
513
518
  const switchbot = await this.switchbotBLE();
514
519
  if (switchbot === undefined) {
515
520
  await this.BLERefreshConnection(switchbot);
@@ -520,63 +525,55 @@ export class Bot extends deviceBase {
520
525
  // Start to monitor advertisement packets
521
526
  const serviceData = await this.monitorAdvertisementPackets(switchbot);
522
527
  // Update HomeKit
523
- if (serviceData.model !== '' && serviceData.modelName !== '') {
528
+ if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
524
529
  await this.BLEparseStatus(serviceData);
525
530
  await this.updateHomeKitCharacteristics();
526
531
  }
527
532
  else {
528
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
533
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
529
534
  await this.BLERefreshConnection(switchbot);
530
535
  }
531
536
  })();
532
537
  }
533
538
  }
534
539
  async openAPIRefreshStatus() {
535
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
540
+ await this.debugLog('openAPIRefreshStatus');
536
541
  try {
537
542
  const { body, statusCode } = await this.deviceRefreshStatus();
538
543
  const deviceStatus = await body.json();
539
- await this.refreshStatusCodes(statusCode, deviceStatus);
544
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
540
545
  ;
541
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
542
- await this.successfulRefreshStatus(statusCode, deviceStatus);
543
- await this.openAPIparseStatus(deviceStatus);
546
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
547
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
548
+ await this.openAPIparseStatus(deviceStatus.body);
544
549
  await this.updateHomeKitCharacteristics();
545
550
  }
546
551
  else {
547
- await this.statusCodes(statusCode, deviceStatus);
552
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
553
+ await this.debugWarnLog(statusCode, deviceStatus);
548
554
  }
549
555
  }
550
556
  catch (e) {
551
- this.apiError(e);
552
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
553
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
557
+ await this.apiError(e);
558
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
554
559
  }
555
560
  }
556
- async registerWebhook(accessory, device) {
557
- if (device.webhook) {
558
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
559
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
561
+ async registerWebhook() {
562
+ if (this.device.webhook) {
563
+ await this.debugLog('is listening webhook.');
564
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
560
565
  try {
561
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
562
- const { power, battery, deviceMode } = context;
563
- const { botMode } = this;
564
- const On = await this.getOn();
565
- const { BatteryLevel } = this.Battery;
566
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (power, battery, deviceMode) = Webhook:(${power}, ${battery}, ${deviceMode}),`
567
- + ` current:(${On}, ${BatteryLevel}, ${botMode})`);
568
- await this.setOn(power);
569
- this.Battery.BatteryLevel = battery;
570
- this.botMode = deviceMode;
571
- this.updateHomeKitCharacteristics();
566
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
567
+ await this.parseStatusWebhook(context);
568
+ await this.updateHomeKitCharacteristics();
572
569
  }
573
570
  catch (e) {
574
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
571
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
575
572
  }
576
573
  };
577
574
  }
578
575
  else {
579
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
576
+ await this.debugLog('is not listening webhook.');
580
577
  }
581
578
  }
582
579
  /**
@@ -588,7 +585,7 @@ export class Bot extends deviceBase {
588
585
  */
589
586
  async pushChanges() {
590
587
  if (!this.device.enableCloudService && this.OpenAPI) {
591
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
588
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
592
589
  }
593
590
  else if (this.BLE) {
594
591
  await this.BLEpushChanges();
@@ -598,8 +595,7 @@ export class Bot extends deviceBase {
598
595
  }
599
596
  else {
600
597
  await this.offlineOff();
601
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
602
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
598
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
603
599
  }
604
600
  // Refresh the status from the API
605
601
  interval(15000)
@@ -610,27 +606,24 @@ export class Bot extends deviceBase {
610
606
  });
611
607
  }
612
608
  async BLEpushChanges() {
613
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
609
+ await this.debugLog('BLEpushChanges');
614
610
  const On = await this.getOn();
615
611
  if (On !== this.accessory.context.On || this.allowPush) {
616
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
617
- const switchbot = await this.platform.connectBLE();
618
- // Convert to BLE Address
612
+ this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
613
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
619
614
  await this.convertBLEAddress();
620
615
  //if (switchbot !== false) {
621
616
  if (this.botMode === 'press') {
622
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
617
+ this.debugLog(`Bot Mode: ${this.botMode}`);
623
618
  switchbot
624
619
  .discover({ model: 'H', quick: true, id: this.device.bleMac })
625
620
  .then(async (device_list) => {
626
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
621
+ this.infoLog(`On: ${On}`);
627
622
  return await device_list[0].press({ id: this.device.bleMac });
628
623
  })
629
- .then(() => {
630
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
631
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
632
- + `On: ${On} sent over BLE, sent successfully`);
633
- this.accessory.context.On = On;
624
+ .then(async () => {
625
+ await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
626
+ await this.updateHomeKitCharacteristics();
634
627
  setTimeout(() => {
635
628
  if (this.botDeviceType === 'switch') {
636
629
  this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
@@ -638,22 +631,21 @@ export class Bot extends deviceBase {
638
631
  else {
639
632
  this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
640
633
  }
641
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}, Switch Timeout`);
634
+ this.debugLog(`On: ${On}, Switch Timeout`);
642
635
  }, 500);
643
636
  })
644
637
  .catch(async (e) => {
645
- this.apiError(e);
646
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
647
- + ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
638
+ await this.apiError(e);
639
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
648
640
  await this.BLEPushConnection();
649
641
  });
650
642
  }
651
643
  else if (this.botMode === 'switch') {
652
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
644
+ this.debugLog(`Press Mode: ${this.botMode}`);
653
645
  switchbot
654
646
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
655
647
  .then(async (device_list) => {
656
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
648
+ this.infoLog(`On: ${On}`);
657
649
  return await this.retryBLE({
658
650
  max: await this.maxRetryBLE(),
659
651
  fn: async () => {
@@ -666,30 +658,29 @@ export class Bot extends deviceBase {
666
658
  },
667
659
  });
668
660
  })
669
- .then(() => {
670
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
671
- this.accessory.context.On = On;
661
+ .then(async () => {
662
+ await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
663
+ await this.updateHomeKitCharacteristics();
672
664
  })
673
665
  .catch(async (e) => {
674
- this.apiError(e);
675
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
676
- + ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
666
+ await this.apiError(e);
667
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
677
668
  await this.BLEPushConnection();
678
669
  });
679
670
  }
680
671
  else {
681
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
672
+ await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
682
673
  }
683
674
  }
684
675
  else {
685
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, On: ${On}, OnCached: ${this.accessory.context.On}`);
676
+ await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
686
677
  }
687
678
  }
688
679
  async openAPIpushChanges() {
689
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
680
+ await this.debugLog('openAPIpushChanges');
690
681
  let On = await this.getOn();
691
682
  if (this.multiPressCount > 0) {
692
- this.debugLog(`${this.device.deviceType}: ${this.multiPressCount} request(s) queued.`);
683
+ await this.debugLog(`${this.multiPressCount} request(s) queued.`);
693
684
  On = true;
694
685
  }
695
686
  if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
@@ -697,33 +688,33 @@ export class Bot extends deviceBase {
697
688
  if (this.botMode === 'switch' && On) {
698
689
  command = 'turnOn';
699
690
  On = true;
700
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
691
+ await this.debugLog(`Switch Mode, Turning ${On}`);
701
692
  }
702
693
  else if (this.botMode === 'switch' && !On) {
703
694
  command = 'turnOff';
704
695
  On = false;
705
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
696
+ await this.debugLog(`Switch Mode, Turning ${On}`);
706
697
  }
707
698
  else if (this.botMode === 'press' || this.botMode === 'multipress') {
708
699
  command = 'press';
709
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode`);
700
+ await this.debugLog('Press Mode');
710
701
  On = false;
711
702
  }
712
703
  else {
713
- throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Parameters not set for this Bot.`);
704
+ throw new Error('Device Parameters not set for this Bot.');
714
705
  }
715
706
  const bodyChange = JSON.stringify({
716
707
  command: `${command}`,
717
708
  parameter: 'default',
718
709
  commandType: 'command',
719
710
  });
720
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
711
+ this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
721
712
  try {
722
713
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
723
714
  const deviceStatus = await body.json();
724
- await this.pushStatusCodes(statusCode, deviceStatus);
725
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
726
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
715
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
716
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
717
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
727
718
  await this.updateHomeKitCharacteristics();
728
719
  }
729
720
  else {
@@ -733,21 +724,19 @@ export class Bot extends deviceBase {
733
724
  if (this.device.bot?.mode === 'multipress') {
734
725
  this.multiPressCount--;
735
726
  if (this.multiPressCount > 0) {
736
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Multi Press Count: ${this.multiPressCount}`);
727
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
737
728
  On = true;
738
- this.openAPIpushChanges();
729
+ await this.openAPIpushChanges();
739
730
  }
740
731
  }
741
732
  }
742
733
  catch (e) {
743
- this.apiError(e);
744
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
745
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
734
+ await this.apiError(e);
735
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
746
736
  }
747
737
  }
748
738
  else {
749
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges,`
750
- + ` On: ${On}, OnCached: ${this.accessory.context.On}`);
739
+ await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
751
740
  }
752
741
  }
753
742
  /**
@@ -756,7 +745,8 @@ export class Bot extends deviceBase {
756
745
  async OnSet(value) {
757
746
  if (this.botDeviceType === 'garagedoor') {
758
747
  if (this.GarageDoor) {
759
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
748
+ await this.debugLog(`Set TargetDoorState: ${value}`);
749
+ this.infoLog(`Set TargetDoorState: ${value}`);
760
750
  if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
761
751
  await this.setOn(false);
762
752
  this.GarageDoor.On = false;
@@ -769,7 +759,7 @@ export class Bot extends deviceBase {
769
759
  }
770
760
  else if (this.botDeviceType === 'door') {
771
761
  if (this.Door) {
772
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
762
+ await this.debugLog(`Set TargetPosition: ${value}`);
773
763
  if (value === 0) {
774
764
  await this.setOn(false);
775
765
  this.Door.On = false;
@@ -782,7 +772,7 @@ export class Bot extends deviceBase {
782
772
  }
783
773
  else if (this.botDeviceType === 'window') {
784
774
  if (this.Window) {
785
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
775
+ await this.debugLog(`Set TargetPosition: ${value}`);
786
776
  if (value === 0) {
787
777
  await this.setOn(false);
788
778
  this.Window.On = false;
@@ -795,7 +785,7 @@ export class Bot extends deviceBase {
795
785
  }
796
786
  else if (this.botDeviceType === 'windowcovering') {
797
787
  if (this.WindowCovering) {
798
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
788
+ await this.debugLog(`Set TargetPosition: ${value}`);
799
789
  if (value === 0) {
800
790
  await this.setOn(false);
801
791
  this.WindowCovering.On = false;
@@ -808,7 +798,7 @@ export class Bot extends deviceBase {
808
798
  }
809
799
  else if (this.botDeviceType === 'lock') {
810
800
  if (this.LockMechanism) {
811
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
801
+ await this.debugLog(`Set LockTargetState: ${value}`);
812
802
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
813
803
  await this.setOn(false);
814
804
  this.LockMechanism.On = false;
@@ -821,7 +811,7 @@ export class Bot extends deviceBase {
821
811
  }
822
812
  else if (this.botDeviceType === 'faucet') {
823
813
  if (this.Faucet) {
824
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
814
+ await this.debugLog(`Set Active: ${value}`);
825
815
  if (value === this.hap.Characteristic.Active.INACTIVE) {
826
816
  await this.setOn(false);
827
817
  this.Faucet.On = false;
@@ -834,7 +824,7 @@ export class Bot extends deviceBase {
834
824
  }
835
825
  else if (this.botDeviceType === 'stateful') {
836
826
  if (this.StatefulProgrammableSwitch) {
837
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
827
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
838
828
  if (value === 0) {
839
829
  await this.setOn(false);
840
830
  this.StatefulProgrammableSwitch.On = false;
@@ -847,7 +837,7 @@ export class Bot extends deviceBase {
847
837
  }
848
838
  else if (this.botDeviceType === 'switch') {
849
839
  if (this.Switch) {
850
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
840
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
851
841
  if (value === 0) {
852
842
  await this.setOn(false);
853
843
  this.Switch.On = false;
@@ -860,7 +850,7 @@ export class Bot extends deviceBase {
860
850
  }
861
851
  else {
862
852
  if (this.Outlet) {
863
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
853
+ await this.debugLog(`Set On: ${value}`);
864
854
  await this.setOn(Boolean(value));
865
855
  this.Outlet.On = value;
866
856
  }
@@ -868,7 +858,7 @@ export class Bot extends deviceBase {
868
858
  if (this.device.bot?.mode === 'multipress') {
869
859
  if (value === true) {
870
860
  this.multiPressCount++;
871
- this.debugLog(`${this.device.deviceType} set to Multi-Press. Multi-Press count: ${this.multiPressCount}`);
861
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
872
862
  }
873
863
  }
874
864
  this.doBotUpdate.next();
@@ -880,216 +870,203 @@ export class Bot extends deviceBase {
880
870
  // State
881
871
  if (this.botDeviceType === 'garagedoor') {
882
872
  if (this.GarageDoor?.On === undefined) {
883
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.GarageDoor?.On}`);
873
+ await this.debugLog(`On: ${this.GarageDoor?.On}`);
884
874
  }
885
875
  else {
886
876
  if (this.GarageDoor.On) {
887
877
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
888
878
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
889
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
890
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
879
+ await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
891
880
  }
892
881
  else {
893
882
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
894
883
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
895
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
896
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
884
+ await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
897
885
  }
898
886
  }
899
887
  await this.setOn(Boolean(this.GarageDoor?.On));
900
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor?.On}`);
888
+ await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
901
889
  }
902
890
  else if (this.botDeviceType === 'door') {
903
891
  if (this.Door?.On === undefined) {
904
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Door?.On}`);
892
+ await this.debugLog(`On: ${this.Door?.On}`);
905
893
  }
906
894
  else {
907
895
  if (this.Door.On) {
908
896
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
909
897
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
910
898
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
911
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
912
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
899
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
913
900
  }
914
901
  else {
915
902
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
916
903
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
917
904
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
918
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
919
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
905
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
920
906
  }
921
907
  }
922
908
  await this.setOn(Boolean(this.Door?.On));
923
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Door On: ${this.Door?.On}`);
909
+ await this.debugLog(`Door On: ${this.Door?.On}`);
924
910
  }
925
911
  else if (this.botDeviceType === 'window') {
926
912
  if (this.Window?.On === undefined) {
927
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Window?.On}`);
913
+ await this.debugLog(`On: ${this.Window?.On}`);
928
914
  }
929
915
  else {
930
916
  if (this.Window.On) {
931
917
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
932
918
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
933
919
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
934
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
935
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
920
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
936
921
  }
937
922
  else {
938
923
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
939
924
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
940
925
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
941
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
942
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
926
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
943
927
  }
944
928
  }
945
929
  await this.setOn(Boolean(this.Window?.On));
946
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window On: ${this.Window?.On}`);
930
+ await this.debugLog(`Window On: ${this.Window?.On}`);
947
931
  }
948
932
  else if (this.botDeviceType === 'windowcovering') {
949
933
  if (this.WindowCovering?.On === undefined) {
950
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.WindowCovering?.On}`);
934
+ await this.debugLog(`On: ${this.WindowCovering?.On}`);
951
935
  }
952
936
  else {
953
937
  if (this.WindowCovering.On) {
954
938
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
955
939
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
956
940
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
957
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
958
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
941
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
959
942
  }
960
943
  else {
961
944
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
962
945
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
963
946
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
964
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
965
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
947
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
966
948
  }
967
949
  }
968
950
  await this.setOn(Boolean(this.WindowCovering?.On));
969
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering?.On}`);
951
+ await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
970
952
  }
971
953
  else if (this.botDeviceType === 'lock') {
972
954
  if (this.LockMechanism?.On === undefined) {
973
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockMechanism?.On}`);
955
+ await this.debugLog(`On: ${this.LockMechanism?.On}`);
974
956
  }
975
957
  else {
976
958
  if (this.LockMechanism.On) {
977
959
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
978
960
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
979
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
980
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
961
+ await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
981
962
  }
982
963
  else {
983
964
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
984
965
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
985
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
986
- + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
966
+ await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
987
967
  }
988
968
  }
989
969
  await this.setOn(Boolean(this.LockMechanism?.On));
990
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.LockMechanism?.On}`);
970
+ await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
991
971
  }
992
972
  else if (this.botDeviceType === 'faucet') {
993
973
  if (this.Faucet?.On === undefined) {
994
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Faucet?.On}`);
974
+ await this.debugLog(`On: ${this.Faucet?.On}`);
995
975
  }
996
976
  else {
997
977
  if (this.Faucet.On) {
998
978
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
999
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
979
+ await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1000
980
  }
1001
981
  else {
1002
982
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
1003
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
983
+ await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1004
984
  }
1005
985
  }
1006
986
  await this.setOn(Boolean(this.Faucet?.On));
1007
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Faucet On: ${this.Faucet?.On}`);
987
+ await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
1008
988
  }
1009
989
  else if (this.botDeviceType === 'fan') {
1010
990
  if (this.Fan?.On === undefined) {
1011
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan?.On}`);
991
+ await this.debugLog(`On: ${this.Fan?.On}`);
1012
992
  }
1013
993
  else {
1014
994
  if (this.Fan.On) {
1015
995
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1016
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
996
+ await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1017
997
  }
1018
998
  else {
1019
999
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1020
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
1000
+ await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1021
1001
  }
1022
1002
  }
1023
1003
  await this.setOn(Boolean(this.Fan?.On));
1024
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Fan On: ${this.Fan?.On}`);
1004
+ await this.debugLog(`Fan On: ${this.Fan?.On}`);
1025
1005
  }
1026
1006
  else if (this.botDeviceType === 'stateful') {
1027
1007
  if (this.StatefulProgrammableSwitch?.On === undefined) {
1028
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch?.On}`);
1008
+ await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
1029
1009
  }
1030
1010
  else {
1031
1011
  if (this.StatefulProgrammableSwitch.On) {
1032
1012
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1033
1013
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
1034
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1035
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
1014
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1036
1015
  }
1037
1016
  else {
1038
1017
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1039
1018
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
1040
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1041
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
1019
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1042
1020
  }
1043
1021
  }
1044
1022
  await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
1045
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1023
+ await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1046
1024
  }
1047
1025
  else if (this.botDeviceType === 'switch') {
1048
1026
  if (this.Switch?.On === undefined) {
1049
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Switch?.On}`);
1027
+ await this.debugLog(`On: ${this.Switch?.On}`);
1050
1028
  }
1051
1029
  else {
1052
1030
  this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
1053
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
1031
+ await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
1054
1032
  }
1055
1033
  await this.setOn(Boolean(this.Switch?.On));
1056
1034
  }
1057
1035
  else {
1058
1036
  if (this.Outlet?.On === undefined) {
1059
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Outlet?.On}`);
1037
+ await this.debugLog(`On: ${this.Outlet?.On}`);
1060
1038
  }
1061
1039
  else {
1062
1040
  this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
1063
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet.On}`);
1041
+ await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
1064
1042
  }
1065
1043
  await this.setOn(Boolean(this.Outlet?.On));
1066
1044
  }
1067
1045
  this.accessory.context.On = await this.getOn();
1068
1046
  // BatteryLevel
1069
1047
  if (this.Battery.BatteryLevel === undefined) {
1070
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
1048
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
1071
1049
  }
1072
1050
  else {
1073
1051
  this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
1074
1052
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
1075
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1053
+ await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1076
1054
  }
1077
1055
  // StatusLowBattery
1078
1056
  if (this.Battery.StatusLowBattery === undefined) {
1079
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1057
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1080
1058
  }
1081
1059
  else {
1082
1060
  this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
1083
1061
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
1084
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1085
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1062
+ await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1086
1063
  }
1087
1064
  }
1088
1065
  async removeOutletService(accessory) {
1089
1066
  // If outletService still present, then remove first
1090
1067
  if (this.Outlet?.Service) {
1091
1068
  this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet);
1092
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
1069
+ await this.warnLog('Removing Leftover Outlet Service');
1093
1070
  accessory.removeService(this.Outlet.Service);
1094
1071
  }
1095
1072
  }
@@ -1097,7 +1074,7 @@ export class Bot extends deviceBase {
1097
1074
  // If garageDoorService still present, then remove first
1098
1075
  if (this.GarageDoor?.Service) {
1099
1076
  this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener);
1100
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
1077
+ await this.warnLog('Removing Leftover Garage Door Service');
1101
1078
  accessory.removeService(this.GarageDoor.Service);
1102
1079
  }
1103
1080
  }
@@ -1105,7 +1082,7 @@ export class Bot extends deviceBase {
1105
1082
  // If doorService still present, then remove first
1106
1083
  if (this.Door?.Service) {
1107
1084
  this.Door.Service = this.accessory.getService(this.hap.Service.Door);
1108
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
1085
+ await this.warnLog('Removing Leftover Door Service');
1109
1086
  accessory.removeService(this.Door.Service);
1110
1087
  }
1111
1088
  }
@@ -1113,7 +1090,7 @@ export class Bot extends deviceBase {
1113
1090
  // If lockService still present, then remove first
1114
1091
  if (this.LockMechanism?.Service) {
1115
1092
  this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism);
1116
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
1093
+ this.warnLog('Removing Leftover Lock Service');
1117
1094
  accessory.removeService(this.LockMechanism.Service);
1118
1095
  }
1119
1096
  }
@@ -1121,7 +1098,7 @@ export class Bot extends deviceBase {
1121
1098
  // If faucetService still present, then remove first
1122
1099
  if (this.Faucet?.Service) {
1123
1100
  this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet);
1124
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
1101
+ await this.warnLog('Removing Leftover Faucet Service');
1125
1102
  accessory.removeService(this.Faucet.Service);
1126
1103
  }
1127
1104
  }
@@ -1129,7 +1106,7 @@ export class Bot extends deviceBase {
1129
1106
  // If fanService still present, then remove first
1130
1107
  if (this.Fan?.Service) {
1131
1108
  this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2);
1132
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
1109
+ this.warnLog('Removing Leftover Fan Service');
1133
1110
  accessory.removeService(this.Fan.Service);
1134
1111
  }
1135
1112
  }
@@ -1137,7 +1114,7 @@ export class Bot extends deviceBase {
1137
1114
  // If windowService still present, then remove first
1138
1115
  if (this.Window?.Service) {
1139
1116
  this.Window.Service = this.accessory.getService(this.hap.Service.Window);
1140
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
1117
+ await this.warnLog('Removing Leftover Window Service');
1141
1118
  accessory.removeService(this.Window.Service);
1142
1119
  }
1143
1120
  }
@@ -1145,7 +1122,7 @@ export class Bot extends deviceBase {
1145
1122
  // If windowCoveringService still present, then remove first
1146
1123
  if (this.WindowCovering?.Service) {
1147
1124
  this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering);
1148
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
1125
+ await this.warnLog('Removing Leftover Window Covering Service');
1149
1126
  accessory.removeService(this.WindowCovering.Service);
1150
1127
  }
1151
1128
  }
@@ -1153,7 +1130,7 @@ export class Bot extends deviceBase {
1153
1130
  // If statefulProgrammableSwitchService still present, then remove first
1154
1131
  if (this.StatefulProgrammableSwitch?.Service) {
1155
1132
  this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
1156
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
1133
+ await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
1157
1134
  accessory.removeService(this.StatefulProgrammableSwitch.Service);
1158
1135
  }
1159
1136
  }
@@ -1161,7 +1138,7 @@ export class Bot extends deviceBase {
1161
1138
  // If switchService still present, then remove first
1162
1139
  if (this.Switch?.Service) {
1163
1140
  this.Switch.Service = this.accessory.getService(this.hap.Service.Switch);
1164
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
1141
+ await this.warnLog('Removing Leftover Switch Service');
1165
1142
  accessory.removeService(this.Switch.Service);
1166
1143
  }
1167
1144
  }
@@ -1255,39 +1232,39 @@ export class Bot extends deviceBase {
1255
1232
  //Bot Device Type
1256
1233
  if (!device.bot?.deviceType && this.accessory.context.deviceType) {
1257
1234
  this.botDeviceType = this.accessory.context.deviceType;
1258
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
1235
+ await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
1259
1236
  }
1260
1237
  else if (device.bot?.deviceType) {
1261
1238
  this.accessory.context.deviceType = device.bot.deviceType;
1262
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Accessory Cache: ${this.accessory.context.deviceType}`);
1239
+ await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
1263
1240
  this.botDeviceType = this.accessory.context.deviceType;
1264
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}`);
1241
+ await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
1265
1242
  }
1266
1243
  else {
1267
1244
  this.botDeviceType = 'outlet';
1268
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
1269
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using default deviceType: ${this.botDeviceType}`);
1245
+ await this.errorLog(`No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
1246
+ await this.warnLog(`Using default deviceType: ${this.botDeviceType}`);
1270
1247
  }
1271
1248
  // Bot Mode
1272
1249
  if (!device.bot?.mode) {
1273
1250
  this.botMode = 'switch';
1274
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
1275
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`);
1251
+ await this.warnLog('does not have bot mode set in the Plugin\'s SwitchBot Device Settings,');
1252
+ await this.warnLog(`is defaulting to "${this.botMode}" mode, you may experience issues.`);
1276
1253
  }
1277
1254
  else if (device.bot?.mode === 'switch') {
1278
1255
  this.botMode = 'switch';
1279
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1256
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1280
1257
  }
1281
1258
  else if (device.bot?.mode === 'press') {
1282
1259
  this.botMode = 'press';
1283
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1260
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1284
1261
  }
1285
1262
  else if (device.bot?.mode === 'multipress') {
1286
1263
  this.botMode = 'multipress';
1287
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1264
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1288
1265
  }
1289
1266
  else {
1290
- throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1267
+ throw new Error(`Bot Mode: ${this.botMode}`);
1291
1268
  }
1292
1269
  // Bot Double Press
1293
1270
  if (device.bot?.doublePress) {
@@ -1300,11 +1277,11 @@ export class Bot extends deviceBase {
1300
1277
  // Bot Press PushRate
1301
1278
  if (device?.bot?.pushRatePress) {
1302
1279
  this.pushRatePress = device?.bot?.pushRatePress;
1303
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
1280
+ await this.debugLog(`Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
1304
1281
  }
1305
1282
  else {
1306
1283
  this.pushRatePress = 15;
1307
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Bot pushRatePress: ${this.pushRatePress}`);
1284
+ await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
1308
1285
  }
1309
1286
  // Bot Allow Push
1310
1287
  if (device.bot?.allowPush) {
@@ -1313,21 +1290,20 @@ export class Bot extends deviceBase {
1313
1290
  else {
1314
1291
  this.allowPush = false;
1315
1292
  }
1316
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1293
+ await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
1317
1294
  // Bot Multi Press Count
1318
1295
  this.multiPressCount = 0;
1319
1296
  }
1320
1297
  async BLEPushConnection() {
1321
1298
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1322
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
1299
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
1323
1300
  await this.openAPIpushChanges();
1324
1301
  }
1325
1302
  }
1326
1303
  async BLERefreshConnection(switchbot) {
1327
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
1328
- + ` ${JSON.stringify(switchbot)}`);
1304
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
1329
1305
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1330
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
1306
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
1331
1307
  await this.openAPIRefreshStatus();
1332
1308
  }
1333
1309
  }