@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.3

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 (187) hide show
  1. package/dist/device/blindtilt.d.ts +15 -6
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +203 -255
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -4
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +196 -218
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +9 -4
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +202 -247
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +10 -5
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +329 -378
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +9 -4
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +99 -142
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +19 -7
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +203 -264
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +28 -32
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +186 -225
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +9 -4
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +198 -227
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +9 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +106 -231
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +12 -4
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +192 -232
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +9 -4
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +91 -157
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +10 -5
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +287 -367
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +10 -5
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +171 -216
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +9 -4
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +93 -158
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +9 -4
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +94 -155
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +9 -4
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +84 -142
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +9 -4
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +99 -124
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +170 -253
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +12 -4
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +102 -128
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/irdevice/airconditioner.d.ts +2 -1
  78. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  79. package/dist/irdevice/airconditioner.js.map +1 -1
  80. package/dist/irdevice/airpurifier.d.ts +2 -1
  81. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts +2 -1
  84. package/dist/irdevice/camera.d.ts.map +1 -1
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +2 -1
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js.map +1 -1
  89. package/dist/irdevice/irdevice.d.ts +2 -1
  90. package/dist/irdevice/irdevice.d.ts.map +1 -1
  91. package/dist/irdevice/irdevice.js +1 -1
  92. package/dist/irdevice/irdevice.js.map +1 -1
  93. package/dist/irdevice/light.d.ts +2 -1
  94. package/dist/irdevice/light.d.ts.map +1 -1
  95. package/dist/irdevice/light.js.map +1 -1
  96. package/dist/irdevice/other.d.ts +2 -1
  97. package/dist/irdevice/other.d.ts.map +1 -1
  98. package/dist/irdevice/other.js.map +1 -1
  99. package/dist/irdevice/tv.d.ts +2 -1
  100. package/dist/irdevice/tv.d.ts.map +1 -1
  101. package/dist/irdevice/tv.js.map +1 -1
  102. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  103. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  104. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  105. package/dist/irdevice/waterheater.d.ts +2 -1
  106. package/dist/irdevice/waterheater.d.ts.map +1 -1
  107. package/dist/irdevice/waterheater.js.map +1 -1
  108. package/dist/platform.d.ts +5 -7
  109. package/dist/platform.d.ts.map +1 -1
  110. package/dist/platform.js +51 -34
  111. package/dist/platform.js.map +1 -1
  112. package/dist/settings.d.ts +49 -191
  113. package/dist/settings.d.ts.map +1 -1
  114. package/dist/settings.js +19 -0
  115. package/dist/settings.js.map +1 -1
  116. package/dist/types/bledevicestatus.d.ts +279 -0
  117. package/dist/types/bledevicestatus.d.ts.map +1 -0
  118. package/dist/types/bledevicestatus.js +2 -0
  119. package/dist/types/bledevicestatus.js.map +1 -0
  120. package/dist/types/devicelist.d.ts +89 -0
  121. package/dist/types/devicelist.d.ts.map +1 -0
  122. package/dist/types/devicelist.js +6 -0
  123. package/dist/types/devicelist.js.map +1 -0
  124. package/dist/types/deviceresponse.d.ts +13 -0
  125. package/dist/types/deviceresponse.d.ts.map +1 -0
  126. package/dist/types/deviceresponse.js +2 -0
  127. package/dist/types/deviceresponse.js.map +1 -0
  128. package/dist/types/devicestatus.d.ts +149 -0
  129. package/dist/types/devicestatus.d.ts.map +1 -0
  130. package/dist/types/devicestatus.js +3 -0
  131. package/dist/types/devicestatus.js.map +1 -0
  132. package/dist/types/devicewebhookstatus.d.ts +156 -0
  133. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  134. package/dist/types/devicewebhookstatus.js +2 -0
  135. package/dist/types/devicewebhookstatus.js.map +1 -0
  136. package/dist/types/irdevicelist.d.ts +10 -0
  137. package/dist/types/irdevicelist.d.ts.map +1 -0
  138. package/dist/types/irdevicelist.js +2 -0
  139. package/dist/types/irdevicelist.js.map +1 -0
  140. package/dist/types/pushbody.d.ts +6 -0
  141. package/dist/types/pushbody.d.ts.map +1 -0
  142. package/dist/types/pushbody.js +2 -0
  143. package/dist/types/pushbody.js.map +1 -0
  144. package/dist/utils.d.ts +25 -0
  145. package/dist/utils.d.ts.map +1 -1
  146. package/dist/utils.js +28 -0
  147. package/dist/utils.js.map +1 -1
  148. package/package.json +10 -10
  149. package/src/device/blindtilt.ts +223 -263
  150. package/src/device/bot.ts +208 -221
  151. package/src/device/ceilinglight.ts +210 -257
  152. package/src/device/colorbulb.ts +334 -397
  153. package/src/device/contact.ts +111 -146
  154. package/src/device/curtain.ts +220 -283
  155. package/src/device/device.ts +194 -245
  156. package/src/device/fan.ts +214 -230
  157. package/src/device/hub.ts +126 -246
  158. package/src/device/humidifier.ts +216 -243
  159. package/src/device/iosensor.ts +114 -166
  160. package/src/device/lightstrip.ts +302 -377
  161. package/src/device/lock.ts +187 -221
  162. package/src/device/meter.ts +116 -177
  163. package/src/device/meterplus.ts +117 -174
  164. package/src/device/motion.ts +99 -144
  165. package/src/device/plug.ts +110 -128
  166. package/src/device/robotvacuumcleaner.ts +189 -252
  167. package/src/device/waterdetector.ts +120 -138
  168. package/src/irdevice/airconditioner.ts +2 -1
  169. package/src/irdevice/airpurifier.ts +2 -1
  170. package/src/irdevice/camera.ts +2 -1
  171. package/src/irdevice/fan.ts +2 -1
  172. package/src/irdevice/irdevice.ts +3 -2
  173. package/src/irdevice/light.ts +2 -1
  174. package/src/irdevice/other.ts +2 -1
  175. package/src/irdevice/tv.ts +2 -1
  176. package/src/irdevice/vacuumcleaner.ts +2 -1
  177. package/src/irdevice/waterheater.ts +2 -1
  178. package/src/platform.ts +52 -34
  179. package/src/settings.ts +30 -239
  180. package/src/types/bledevicestatus.ts +305 -0
  181. package/src/types/devicelist.ts +124 -0
  182. package/src/types/deviceresponse.ts +15 -0
  183. package/src/types/devicestatus.ts +178 -0
  184. package/src/types/devicewebhookstatus.ts +196 -0
  185. package/src/types/irdevicelist.ts +15 -0
  186. package/src/types/pushbody.ts +9 -0
  187. 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,46 +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
650
  await this.apiError(e);
636
- await this.openAPIRefreshError(e);
651
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
637
652
  }
638
653
  }
639
654
 
640
- async registerWebhook(accessory: PlatformAccessory, device: device & devicesConfig) {
641
- if (device.webhook) {
642
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
643
- 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) => {
644
659
  try {
645
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
646
- const { power, battery, deviceMode } = context;
647
- const { botMode } = this;
648
- const On = await this.getOn();
649
- const { BatteryLevel } = this.Battery;
650
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (power, battery, deviceMode) = Webhook:(${power}, ${battery}, ${deviceMode}),`
651
- + ` current:(${On}, ${BatteryLevel}, ${botMode})`);
652
- await this.setOn(power);
653
- this.Battery.BatteryLevel = battery;
654
- this.botMode = deviceMode;
655
- this.updateHomeKitCharacteristics();
660
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
661
+ await this.parseStatusWebhook(context);
662
+ await this.updateHomeKitCharacteristics();
656
663
  } catch (e: any) {
657
- 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}`);
658
665
  }
659
666
  };
660
667
  } else {
661
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
668
+ await this.debugLog('is not listening webhook.');
662
669
  }
663
670
  }
664
671
 
@@ -671,14 +678,14 @@ export class Bot extends deviceBase {
671
678
  */
672
679
  async pushChanges(): Promise<void> {
673
680
  if (!this.device.enableCloudService && this.OpenAPI) {
674
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
681
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
675
682
  } else if (this.BLE) {
676
683
  await this.BLEpushChanges();
677
684
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
678
685
  await this.openAPIpushChanges();
679
686
  } else {
680
687
  await this.offlineOff();
681
- await this.pushChangeDisabled();
688
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
682
689
  }
683
690
  // Refresh the status from the API
684
691
  interval(15000)
@@ -690,48 +697,44 @@ export class Bot extends deviceBase {
690
697
  }
691
698
 
692
699
  async BLEpushChanges(): Promise<void> {
693
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
700
+ await this.debugLog('BLEpushChanges');
694
701
  const On = await this.getOn();
695
702
  if (On !== this.accessory.context.On || this.allowPush) {
696
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
697
- const switchbot = await this.platform.connectBLE();
698
- // 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);
699
705
  await this.convertBLEAddress();
700
706
  //if (switchbot !== false) {
701
707
  if (this.botMode === 'press') {
702
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
708
+ this.debugLog(`Bot Mode: ${this.botMode}`);
703
709
  switchbot
704
710
  .discover({ model: 'H', quick: true, id: this.device.bleMac })
705
711
  .then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
706
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
712
+ this.infoLog(`On: ${On}`);
707
713
  return await device_list[0].press({ id: this.device.bleMac });
708
714
  })
709
- .then(() => {
710
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
711
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
712
- + `On: ${On} sent over BLE, sent successfully`);
713
- this.accessory.context.On = On;
715
+ .then(async () => {
716
+ await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
717
+ await this.updateHomeKitCharacteristics();
714
718
  setTimeout(() => {
715
719
  if (this.botDeviceType === 'switch') {
716
720
  this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
717
721
  } else {
718
722
  this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
719
723
  }
720
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}, Switch Timeout`);
724
+ this.debugLog(`On: ${On}, Switch Timeout`);
721
725
  }, 500);
722
726
  })
723
727
  .catch(async (e: any) => {
724
- this.apiError(e);
725
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
726
- + ` 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)}`);
727
730
  await this.BLEPushConnection();
728
731
  });
729
732
  } else if (this.botMode === 'switch') {
730
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
733
+ this.debugLog(`Press Mode: ${this.botMode}`);
731
734
  switchbot
732
735
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
733
736
  .then(async (device_list: any) => {
734
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${On}`);
737
+ this.infoLog(`On: ${On}`);
735
738
  return await this.retryBLE({
736
739
  max: await this.maxRetryBLE(),
737
740
  fn: async () => {
@@ -743,29 +746,28 @@ export class Bot extends deviceBase {
743
746
  },
744
747
  });
745
748
  })
746
- .then(() => {
747
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
748
- this.accessory.context.On = On;
749
+ .then(async () => {
750
+ await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
751
+ await this.updateHomeKitCharacteristics();
749
752
  })
750
753
  .catch(async (e: any) => {
751
- this.apiError(e);
752
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
753
- + ` 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)}`);
754
756
  await this.BLEPushConnection();
755
757
  });
756
758
  } else {
757
- 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}`);
758
760
  }
759
761
  } else {
760
- 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}`);
761
763
  }
762
764
  }
763
765
 
764
766
  async openAPIpushChanges(): Promise<void> {
765
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
767
+ await this.debugLog('openAPIpushChanges');
766
768
  let On = await this.getOn();
767
769
  if (this.multiPressCount > 0) {
768
- this.debugLog(`${this.device.deviceType}: ${this.multiPressCount} request(s) queued.`);
770
+ await this.debugLog(`${this.multiPressCount} request(s) queued.`);
769
771
  On = true;
770
772
  }
771
773
  if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
@@ -773,30 +775,30 @@ export class Bot extends deviceBase {
773
775
  if (this.botMode === 'switch' && On) {
774
776
  command = 'turnOn';
775
777
  On = true;
776
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
778
+ await this.debugLog(`Switch Mode, Turning ${On}`);
777
779
  } else if (this.botMode === 'switch' && !On) {
778
780
  command = 'turnOff';
779
781
  On = false;
780
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, Turning ${On}`);
782
+ await this.debugLog(`Switch Mode, Turning ${On}`);
781
783
  } else if (this.botMode === 'press' || this.botMode === 'multipress') {
782
784
  command = 'press';
783
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode`);
785
+ await this.debugLog('Press Mode');
784
786
  On = false;
785
787
  } else {
786
- 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.');
787
789
  }
788
790
  const bodyChange = JSON.stringify({
789
791
  command: `${command}`,
790
792
  parameter: 'default',
791
793
  commandType: 'command',
792
794
  });
793
- 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},`);
794
796
  try {
795
797
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
796
798
  const deviceStatus: any = await body.json();
797
- await this.pushStatusCodes(statusCode, deviceStatus);
798
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
799
- 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)}`);
800
802
  await this.updateHomeKitCharacteristics();
801
803
  } else {
802
804
  await this.statusCode(statusCode);
@@ -805,19 +807,17 @@ export class Bot extends deviceBase {
805
807
  if (this.device.bot?.mode === 'multipress') {
806
808
  this.multiPressCount--;
807
809
  if (this.multiPressCount > 0) {
808
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Multi Press Count: ${this.multiPressCount}`);
810
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
809
811
  On = true;
810
- this.openAPIpushChanges();
812
+ await this.openAPIpushChanges();
811
813
  }
812
814
  }
813
815
  } catch (e: any) {
814
- this.apiError(e);
815
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
816
- + ` 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)}`);
817
818
  }
818
819
  } else {
819
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges,`
820
- + ` On: ${On}, OnCached: ${this.accessory.context.On}`);
820
+ await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
821
821
  }
822
822
  }
823
823
 
@@ -827,7 +827,8 @@ export class Bot extends deviceBase {
827
827
  async OnSet(value: CharacteristicValue): Promise<void> {
828
828
  if (this.botDeviceType === 'garagedoor') {
829
829
  if (this.GarageDoor) {
830
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
830
+ await this.debugLog(`Set TargetDoorState: ${value}`);
831
+ this.infoLog(`Set TargetDoorState: ${value}`);
831
832
  if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
832
833
  await this.setOn(false);
833
834
  this.GarageDoor.On = false;
@@ -838,7 +839,7 @@ export class Bot extends deviceBase {
838
839
  }
839
840
  } else if (this.botDeviceType === 'door') {
840
841
  if (this.Door) {
841
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
842
+ await this.debugLog(`Set TargetPosition: ${value}`);
842
843
  if (value === 0) {
843
844
  await this.setOn(false);
844
845
  this.Door.On = false;
@@ -849,7 +850,7 @@ export class Bot extends deviceBase {
849
850
  }
850
851
  } else if (this.botDeviceType === 'window') {
851
852
  if (this.Window) {
852
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
853
+ await this.debugLog(`Set TargetPosition: ${value}`);
853
854
  if (value === 0) {
854
855
  await this.setOn(false);
855
856
  this.Window.On = false;
@@ -860,7 +861,7 @@ export class Bot extends deviceBase {
860
861
  }
861
862
  } else if (this.botDeviceType === 'windowcovering') {
862
863
  if (this.WindowCovering) {
863
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
864
+ await this.debugLog(`Set TargetPosition: ${value}`);
864
865
  if (value === 0) {
865
866
  await this.setOn(false);
866
867
  this.WindowCovering.On = false;
@@ -871,7 +872,7 @@ export class Bot extends deviceBase {
871
872
  }
872
873
  } else if (this.botDeviceType === 'lock') {
873
874
  if (this.LockMechanism) {
874
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
875
+ await this.debugLog(`Set LockTargetState: ${value}`);
875
876
  if (value === this.hap.Characteristic.LockTargetState.SECURED) {
876
877
  await this.setOn(false);
877
878
  this.LockMechanism.On = false;
@@ -882,7 +883,7 @@ export class Bot extends deviceBase {
882
883
  }
883
884
  } else if (this.botDeviceType === 'faucet') {
884
885
  if (this.Faucet) {
885
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
886
+ await this.debugLog(`Set Active: ${value}`);
886
887
  if (value === this.hap.Characteristic.Active.INACTIVE) {
887
888
  await this.setOn(false);
888
889
  this.Faucet.On = false;
@@ -893,7 +894,7 @@ export class Bot extends deviceBase {
893
894
  }
894
895
  } else if (this.botDeviceType === 'stateful') {
895
896
  if (this.StatefulProgrammableSwitch) {
896
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
897
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
897
898
  if (value === 0) {
898
899
  await this.setOn(false);
899
900
  this.StatefulProgrammableSwitch.On = false;
@@ -904,7 +905,7 @@ export class Bot extends deviceBase {
904
905
  }
905
906
  } else if (this.botDeviceType === 'switch') {
906
907
  if (this.Switch) {
907
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
908
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
908
909
  if (value === 0) {
909
910
  await this.setOn(false);
910
911
  this.Switch.On = false;
@@ -915,7 +916,7 @@ export class Bot extends deviceBase {
915
916
  }
916
917
  } else {
917
918
  if (this.Outlet) {
918
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
919
+ await this.debugLog(`Set On: ${value}`);
919
920
  await this.setOn(Boolean(value));
920
921
  this.Outlet.On = value;
921
922
  }
@@ -923,7 +924,7 @@ export class Bot extends deviceBase {
923
924
  if (this.device.bot?.mode === 'multipress') {
924
925
  if (value === true) {
925
926
  this.multiPressCount++;
926
- this.debugLog(`${this.device.deviceType} set to Multi-Press. Multi-Press count: ${this.multiPressCount}`);
927
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
927
928
  }
928
929
  }
929
930
  this.doBotUpdate.next();
@@ -936,186 +937,173 @@ export class Bot extends deviceBase {
936
937
  // State
937
938
  if (this.botDeviceType === 'garagedoor') {
938
939
  if (this.GarageDoor?.On === undefined) {
939
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.GarageDoor?.On}`);
940
+ await this.debugLog(`On: ${this.GarageDoor?.On}`);
940
941
  } else {
941
942
  if (this.GarageDoor.On) {
942
943
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
943
944
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
944
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
945
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
945
+ await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
946
946
  } else {
947
947
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
948
948
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
949
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
950
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
949
+ await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
951
950
  }
952
951
  }
953
952
  await this.setOn(Boolean(this.GarageDoor?.On));
954
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor?.On}`);
953
+ await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
955
954
  } else if (this.botDeviceType === 'door') {
956
955
  if (this.Door?.On === undefined) {
957
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Door?.On}`);
956
+ await this.debugLog(`On: ${this.Door?.On}`);
958
957
  } else {
959
958
  if (this.Door.On) {
960
959
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
961
960
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
962
961
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
963
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
964
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
962
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
965
963
  } else {
966
964
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
967
965
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
968
966
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
969
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
970
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
967
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
971
968
  }
972
969
  }
973
970
  await this.setOn(Boolean(this.Door?.On));
974
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Door On: ${this.Door?.On}`);
971
+ await this.debugLog(`Door On: ${this.Door?.On}`);
975
972
  } else if (this.botDeviceType === 'window') {
976
973
  if (this.Window?.On === undefined) {
977
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Window?.On}`);
974
+ await this.debugLog(`On: ${this.Window?.On}`);
978
975
  } else {
979
976
  if (this.Window.On) {
980
977
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
981
978
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
982
979
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
983
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
984
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
980
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
985
981
  } else {
986
982
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
987
983
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
988
984
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
989
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
990
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
985
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
991
986
  }
992
987
  }
993
988
  await this.setOn(Boolean(this.Window?.On));
994
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window On: ${this.Window?.On}`);
989
+ await this.debugLog(`Window On: ${this.Window?.On}`);
995
990
  } else if (this.botDeviceType === 'windowcovering') {
996
991
  if (this.WindowCovering?.On === undefined) {
997
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.WindowCovering?.On}`);
992
+ await this.debugLog(`On: ${this.WindowCovering?.On}`);
998
993
  } else {
999
994
  if (this.WindowCovering.On) {
1000
995
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
1001
996
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
1002
997
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1003
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
1004
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
998
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
1005
999
  } else {
1006
1000
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1007
1001
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1008
1002
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1009
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
1010
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
1003
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
1011
1004
  }
1012
1005
  }
1013
1006
  await this.setOn(Boolean(this.WindowCovering?.On));
1014
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering?.On}`);
1007
+ await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
1015
1008
  } else if (this.botDeviceType === 'lock') {
1016
1009
  if (this.LockMechanism?.On === undefined) {
1017
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockMechanism?.On}`);
1010
+ await this.debugLog(`On: ${this.LockMechanism?.On}`);
1018
1011
  } else {
1019
1012
  if (this.LockMechanism.On) {
1020
1013
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
1021
1014
  this.hap.Characteristic.LockTargetState.UNSECURED);
1022
1015
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
1023
1016
  this.hap.Characteristic.LockCurrentState.UNSECURED);
1024
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristicc`
1025
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
1017
+ await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
1026
1018
  } else {
1027
1019
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
1028
1020
  this.hap.Characteristic.LockTargetState.SECURED);
1029
1021
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
1030
1022
  this.hap.Characteristic.LockCurrentState.SECURED);
1031
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1032
- + ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
1023
+ await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
1033
1024
  }
1034
1025
  }
1035
1026
  await this.setOn(Boolean(this.LockMechanism?.On));
1036
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Lock On: ${this.LockMechanism?.On}`);
1027
+ await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
1037
1028
  } else if (this.botDeviceType === 'faucet') {
1038
1029
  if (this.Faucet?.On === undefined) {
1039
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Faucet?.On}`);
1030
+ await this.debugLog(`On: ${this.Faucet?.On}`);
1040
1031
  } else {
1041
1032
  if (this.Faucet.On) {
1042
1033
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
1043
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
1034
+ await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1044
1035
  } else {
1045
1036
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
1046
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet.On}`);
1037
+ await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1047
1038
  }
1048
1039
  }
1049
1040
  await this.setOn(Boolean(this.Faucet?.On));
1050
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Faucet On: ${this.Faucet?.On}`);
1041
+ await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
1051
1042
  } else if (this.botDeviceType === 'fan') {
1052
1043
  if (this.Fan?.On === undefined) {
1053
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan?.On}`);
1044
+ await this.debugLog(`On: ${this.Fan?.On}`);
1054
1045
  } else {
1055
1046
  if (this.Fan.On) {
1056
1047
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1057
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
1048
+ await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1058
1049
  } else {
1059
1050
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1060
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan.On}`);
1051
+ await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1061
1052
  }
1062
1053
  }
1063
1054
  await this.setOn(Boolean(this.Fan?.On));
1064
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Fan On: ${this.Fan?.On}`);
1055
+ await this.debugLog(`Fan On: ${this.Fan?.On}`);
1065
1056
  } else if (this.botDeviceType === 'stateful') {
1066
1057
  if (this.StatefulProgrammableSwitch?.On === undefined) {
1067
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch?.On}`);
1058
+ await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
1068
1059
  } else {
1069
1060
  if (this.StatefulProgrammableSwitch.On) {
1070
1061
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1071
1062
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1072
1063
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
1073
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1074
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
1064
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1075
1065
  } else {
1076
1066
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1077
1067
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1078
1068
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
1079
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1080
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
1069
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1081
1070
  }
1082
1071
  }
1083
1072
  await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
1084
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1073
+ await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1085
1074
  } else if (this.botDeviceType === 'switch') {
1086
1075
  if (this.Switch?.On === undefined) {
1087
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Switch?.On}`);
1076
+ await this.debugLog(`On: ${this.Switch?.On}`);
1088
1077
  } else {
1089
1078
  this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
1090
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
1079
+ await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
1091
1080
  }
1092
1081
  await this.setOn(Boolean(this.Switch?.On));
1093
1082
  } else {
1094
1083
  if (this.Outlet?.On === undefined) {
1095
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Outlet?.On}`);
1084
+ await this.debugLog(`On: ${this.Outlet?.On}`);
1096
1085
  } else {
1097
1086
  this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
1098
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet.On}`);
1087
+ await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
1099
1088
  }
1100
1089
  await this.setOn(Boolean(this.Outlet?.On));
1101
1090
  }
1102
1091
  this.accessory.context.On = await this.getOn();
1103
1092
  // BatteryLevel
1104
1093
  if (this.Battery.BatteryLevel === undefined) {
1105
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
1094
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
1106
1095
  } else {
1107
1096
  this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
1108
1097
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
1109
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1098
+ await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1110
1099
  }
1111
1100
  // StatusLowBattery
1112
1101
  if (this.Battery.StatusLowBattery === undefined) {
1113
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1102
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1114
1103
  } else {
1115
1104
  this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
1116
1105
  this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
1117
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
1118
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1106
+ await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1119
1107
  }
1120
1108
  }
1121
1109
 
@@ -1123,7 +1111,7 @@ export class Bot extends deviceBase {
1123
1111
  // If outletService still present, then remove first
1124
1112
  if (this.Outlet?.Service) {
1125
1113
  this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
1126
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Outlet Service`);
1114
+ await this.warnLog('Removing Leftover Outlet Service');
1127
1115
  accessory.removeService(this.Outlet.Service);
1128
1116
  }
1129
1117
  }
@@ -1132,7 +1120,7 @@ export class Bot extends deviceBase {
1132
1120
  // If garageDoorService still present, then remove first
1133
1121
  if (this.GarageDoor?.Service) {
1134
1122
  this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
1135
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
1123
+ await this.warnLog('Removing Leftover Garage Door Service');
1136
1124
  accessory.removeService(this.GarageDoor.Service);
1137
1125
  }
1138
1126
  }
@@ -1141,7 +1129,7 @@ export class Bot extends deviceBase {
1141
1129
  // If doorService still present, then remove first
1142
1130
  if (this.Door?.Service) {
1143
1131
  this.Door.Service = this.accessory.getService(this.hap.Service.Door) as Service;
1144
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Door Service`);
1132
+ await this.warnLog('Removing Leftover Door Service');
1145
1133
  accessory.removeService(this.Door.Service);
1146
1134
  }
1147
1135
  }
@@ -1150,7 +1138,7 @@ export class Bot extends deviceBase {
1150
1138
  // If lockService still present, then remove first
1151
1139
  if (this.LockMechanism?.Service) {
1152
1140
  this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
1153
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Lock Service`);
1141
+ this.warnLog('Removing Leftover Lock Service');
1154
1142
  accessory.removeService(this.LockMechanism.Service);
1155
1143
  }
1156
1144
  }
@@ -1159,7 +1147,7 @@ export class Bot extends deviceBase {
1159
1147
  // If faucetService still present, then remove first
1160
1148
  if (this.Faucet?.Service) {
1161
1149
  this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
1162
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Faucet Service`);
1150
+ await this.warnLog('Removing Leftover Faucet Service');
1163
1151
  accessory.removeService(this.Faucet.Service);
1164
1152
  }
1165
1153
  }
@@ -1168,7 +1156,7 @@ export class Bot extends deviceBase {
1168
1156
  // If fanService still present, then remove first
1169
1157
  if (this.Fan?.Service) {
1170
1158
  this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2) as Service;
1171
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Fan Service`);
1159
+ this.warnLog('Removing Leftover Fan Service');
1172
1160
  accessory.removeService(this.Fan.Service);
1173
1161
  }
1174
1162
  }
@@ -1177,7 +1165,7 @@ export class Bot extends deviceBase {
1177
1165
  // If windowService still present, then remove first
1178
1166
  if (this.Window?.Service) {
1179
1167
  this.Window.Service = this.accessory.getService(this.hap.Service.Window) as Service;
1180
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Service`);
1168
+ await this.warnLog('Removing Leftover Window Service');
1181
1169
  accessory.removeService(this.Window.Service);
1182
1170
  }
1183
1171
  }
@@ -1186,7 +1174,7 @@ export class Bot extends deviceBase {
1186
1174
  // If windowCoveringService still present, then remove first
1187
1175
  if (this.WindowCovering?.Service) {
1188
1176
  this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
1189
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
1177
+ await this.warnLog('Removing Leftover Window Covering Service');
1190
1178
  accessory.removeService(this.WindowCovering.Service);
1191
1179
  }
1192
1180
  }
@@ -1195,7 +1183,7 @@ export class Bot extends deviceBase {
1195
1183
  // If statefulProgrammableSwitchService still present, then remove first
1196
1184
  if (this.StatefulProgrammableSwitch?.Service) {
1197
1185
  this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
1198
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
1186
+ await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
1199
1187
  accessory.removeService(this.StatefulProgrammableSwitch.Service);
1200
1188
  }
1201
1189
  }
@@ -1204,7 +1192,7 @@ export class Bot extends deviceBase {
1204
1192
  // If switchService still present, then remove first
1205
1193
  if (this.Switch?.Service) {
1206
1194
  this.Switch.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
1207
- this.warnLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leftover Switch Service`);
1195
+ await this.warnLog('Removing Leftover Switch Service');
1208
1196
  accessory.removeService(this.Switch.Service);
1209
1197
  }
1210
1198
  }
@@ -1283,33 +1271,33 @@ export class Bot extends deviceBase {
1283
1271
  //Bot Device Type
1284
1272
  if (!device.bot?.deviceType && this.accessory.context.deviceType) {
1285
1273
  this.botDeviceType = this.accessory.context.deviceType;
1286
- 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.`);
1287
1275
  } else if (device.bot?.deviceType) {
1288
1276
  this.accessory.context.deviceType = device.bot.deviceType;
1289
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Accessory Cache: ${this.accessory.context.deviceType}`);
1277
+ await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
1290
1278
  this.botDeviceType = this.accessory.context.deviceType;
1291
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Type: ${this.botDeviceType}`);
1279
+ await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
1292
1280
  } else {
1293
1281
  this.botDeviceType = 'outlet';
1294
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
1295
- 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}`);
1296
1284
  }
1297
1285
  // Bot Mode
1298
1286
  if (!device.bot?.mode) {
1299
1287
  this.botMode = 'switch';
1300
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
1301
- 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.`);
1302
1290
  } else if (device.bot?.mode === 'switch') {
1303
1291
  this.botMode = 'switch';
1304
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1292
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1305
1293
  } else if (device.bot?.mode === 'press') {
1306
1294
  this.botMode = 'press';
1307
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1295
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1308
1296
  } else if (device.bot?.mode === 'multipress') {
1309
1297
  this.botMode = 'multipress';
1310
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`);
1298
+ await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1311
1299
  } else {
1312
- throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
1300
+ throw new Error(`Bot Mode: ${this.botMode}`);
1313
1301
  }
1314
1302
 
1315
1303
  // Bot Double Press
@@ -1323,10 +1311,10 @@ export class Bot extends deviceBase {
1323
1311
  // Bot Press PushRate
1324
1312
  if (device?.bot?.pushRatePress) {
1325
1313
  this.pushRatePress = device?.bot?.pushRatePress;
1326
- 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}`);
1327
1315
  } else {
1328
1316
  this.pushRatePress = 15;
1329
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Bot pushRatePress: ${this.pushRatePress}`);
1317
+ await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
1330
1318
  }
1331
1319
 
1332
1320
  // Bot Allow Push
@@ -1335,23 +1323,22 @@ export class Bot extends deviceBase {
1335
1323
  } else {
1336
1324
  this.allowPush = false;
1337
1325
  }
1338
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1326
+ await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
1339
1327
  // Bot Multi Press Count
1340
1328
  this.multiPressCount = 0;
1341
1329
  }
1342
1330
 
1343
1331
  async BLEPushConnection() {
1344
1332
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1345
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
1333
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
1346
1334
  await this.openAPIpushChanges();
1347
1335
  }
1348
1336
  }
1349
1337
 
1350
1338
  async BLERefreshConnection(switchbot: any): Promise<void> {
1351
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
1352
- + ` ${JSON.stringify(switchbot)}`);
1339
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
1353
1340
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1354
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
1341
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
1355
1342
  await this.openAPIRefreshStatus();
1356
1343
  }
1357
1344
  }