@switchbot/homebridge-switchbot 1.7.0 → 1.7.1-beta.11

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 (97) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/config.schema.json +101 -33
  3. package/dist/devices/bots.d.ts +9 -5
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +144 -77
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +9 -4
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +40 -37
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +10 -2
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +92 -51
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +10 -3
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +52 -34
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +8 -2
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +28 -35
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +14 -12
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +63 -103
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +10 -3
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +114 -68
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +3 -1
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +8 -1
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +1 -0
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +6 -0
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +1 -0
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +6 -0
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +1 -0
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +6 -0
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +1 -0
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +6 -0
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +1 -0
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +6 -0
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +1 -0
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +6 -0
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +1 -0
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +6 -0
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +1 -0
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +6 -0
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +1 -0
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +6 -0
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/dist/platform.d.ts +2 -1
  72. package/dist/platform.d.ts.map +1 -1
  73. package/dist/platform.js +14 -1
  74. package/dist/platform.js.map +1 -1
  75. package/dist/settings.d.ts +14 -0
  76. package/dist/settings.d.ts.map +1 -1
  77. package/dist/settings.js.map +1 -1
  78. package/package.json +71 -71
  79. package/src/devices/bots.ts +140 -74
  80. package/src/devices/colorbulb.ts +46 -40
  81. package/src/devices/contact.ts +99 -55
  82. package/src/devices/curtains.ts +60 -36
  83. package/src/devices/humidifiers.ts +36 -36
  84. package/src/devices/meters.ts +79 -113
  85. package/src/devices/motion.ts +125 -74
  86. package/src/devices/plugs.ts +11 -2
  87. package/src/irdevices/airconditioners.ts +7 -0
  88. package/src/irdevices/airpurifiers.ts +7 -0
  89. package/src/irdevices/cameras.ts +7 -0
  90. package/src/irdevices/fans.ts +7 -0
  91. package/src/irdevices/lights.ts +7 -0
  92. package/src/irdevices/others.ts +7 -0
  93. package/src/irdevices/tvs.ts +7 -0
  94. package/src/irdevices/vacuumcleaners.ts +7 -0
  95. package/src/irdevices/waterheaters.ts +7 -0
  96. package/src/platform.ts +14 -1
  97. package/src/settings.ts +15 -0
@@ -15,10 +15,11 @@ class Bot {
15
15
  this.accessory = accessory;
16
16
  this.device = device;
17
17
  // default placeholders
18
- this.logs();
19
- this.scan();
20
- this.refreshRate();
18
+ this.logs(device);
19
+ this.scan(device);
20
+ this.refreshRate(device);
21
21
  this.PressOrSwitch();
22
+ this.config(device);
22
23
  if (this.On === undefined) {
23
24
  this.On = false;
24
25
  this.accessory.context.On = this.On;
@@ -35,9 +36,6 @@ class Bot {
35
36
  }
36
37
  this.BatteryLevel = 100;
37
38
  this.StatusLowBattery = 0;
38
- // Bot Config
39
- this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},`
40
- + ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`);
41
39
  // this is subject we use to track when we need to POST changes to the SwitchBot API
42
40
  this.doBotUpdate = new rxjs_1.Subject();
43
41
  this.botUpdateInProgress = false;
@@ -60,6 +58,7 @@ class Bot {
60
58
  this.removeWindowService(accessory);
61
59
  this.removeGarageDoorService(accessory);
62
60
  this.removeWindowCoveringService(accessory);
61
+ this.removeStatefulProgrammableSwitchService(accessory);
63
62
  // Add switchService
64
63
  (this.switchService =
65
64
  accessory.getService(this.platform.Service.Switch) ||
@@ -77,6 +76,7 @@ class Bot {
77
76
  this.removeSwitchService(accessory);
78
77
  this.removeWindowService(accessory);
79
78
  this.removeWindowCoveringService(accessory);
79
+ this.removeStatefulProgrammableSwitchService(accessory);
80
80
  // Add switchService
81
81
  (this.garageDoorService =
82
82
  accessory.getService(this.platform.Service.GarageDoorOpener) ||
@@ -95,6 +95,7 @@ class Bot {
95
95
  this.removeWindowService(accessory);
96
96
  this.removeGarageDoorService(accessory);
97
97
  this.removeWindowCoveringService(accessory);
98
+ this.removeStatefulProgrammableSwitchService(accessory);
98
99
  // Add switchService
99
100
  (this.doorService =
100
101
  accessory.getService(this.platform.Service.Door) ||
@@ -119,6 +120,7 @@ class Bot {
119
120
  this.removeSwitchService(accessory);
120
121
  this.removeGarageDoorService(accessory);
121
122
  this.removeWindowCoveringService(accessory);
123
+ this.removeStatefulProgrammableSwitchService(accessory);
122
124
  // Add switchService
123
125
  (this.windowService =
124
126
  accessory.getService(this.platform.Service.Window) ||
@@ -143,6 +145,7 @@ class Bot {
143
145
  this.removeSwitchService(accessory);
144
146
  this.removeWindowService(accessory);
145
147
  this.removeGarageDoorService(accessory);
148
+ this.removeStatefulProgrammableSwitchService(accessory);
146
149
  // Add switchService
147
150
  (this.windowCoveringService =
148
151
  accessory.getService(this.platform.Service.WindowCovering) ||
@@ -167,6 +170,7 @@ class Bot {
167
170
  this.removeWindowService(accessory);
168
171
  this.removeGarageDoorService(accessory);
169
172
  this.removeWindowCoveringService(accessory);
173
+ this.removeStatefulProgrammableSwitchService(accessory);
170
174
  // Add switchService
171
175
  (this.lockService =
172
176
  accessory.getService(this.platform.Service.LockMechanism) ||
@@ -184,6 +188,7 @@ class Bot {
184
188
  this.removeWindowService(accessory);
185
189
  this.removeGarageDoorService(accessory);
186
190
  this.removeWindowCoveringService(accessory);
191
+ this.removeStatefulProgrammableSwitchService(accessory);
187
192
  // Add switchService
188
193
  (this.faucetService =
189
194
  accessory.getService(this.platform.Service.Faucet) ||
@@ -201,6 +206,7 @@ class Bot {
201
206
  this.removeWindowService(accessory);
202
207
  this.removeGarageDoorService(accessory);
203
208
  this.removeWindowCoveringService(accessory);
209
+ this.removeStatefulProgrammableSwitchService(accessory);
204
210
  // Add switchService
205
211
  (this.fanService =
206
212
  accessory.getService(this.platform.Service.Fan) ||
@@ -209,6 +215,25 @@ class Bot {
209
215
  this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
210
216
  this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
211
217
  }
218
+ else if (device.bot?.deviceType === 'stateful') {
219
+ this.removeFanService(accessory);
220
+ this.removeLockService(accessory);
221
+ this.removeDoorService(accessory);
222
+ this.removeFaucetService(accessory);
223
+ this.removeOutletService(accessory);
224
+ this.removeSwitchService(accessory);
225
+ this.removeWindowService(accessory);
226
+ this.removeGarageDoorService(accessory);
227
+ this.removeWindowCoveringService(accessory);
228
+ // Add switchService
229
+ (this.statefulProgrammableSwitchService =
230
+ accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
231
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), `${accessory.displayName} Stateful Programmable Switch`;
232
+ this.infoLog(`Bot: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
233
+ this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
234
+ this.statefulProgrammableSwitchService.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
235
+ .onSet(this.handleOnSet.bind(this));
236
+ }
212
237
  else {
213
238
  this.removeFanService(accessory);
214
239
  this.removeLockService(accessory);
@@ -218,6 +243,7 @@ class Bot {
218
243
  this.removeWindowService(accessory);
219
244
  this.removeGarageDoorService(accessory);
220
245
  this.removeWindowCoveringService(accessory);
246
+ this.removeStatefulProgrammableSwitchService(accessory);
221
247
  // Add outletService
222
248
  (this.outletService =
223
249
  accessory.getService(this.platform.Service.Outlet) ||
@@ -226,12 +252,22 @@ class Bot {
226
252
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
227
253
  this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
228
254
  }
229
- if (device.ble) {
255
+ // Battery Service
256
+ if (!device.ble) {
257
+ this.debugLog(`Bot: ${accessory.displayName} Removing Battery Service`);
258
+ this.batteryService = this.accessory.getService(this.platform.Service.Battery);
259
+ accessory.removeService(this.batteryService);
260
+ }
261
+ else if (device.ble && !this.batteryService) {
262
+ this.debugLog(`Bot: ${accessory.displayName} Add Battery Service`);
230
263
  (this.batteryService =
231
- accessory.getService(this.platform.Service.Battery) ||
232
- accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
264
+ this.accessory.getService(this.platform.Service.Battery) ||
265
+ this.accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
233
266
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
234
267
  }
268
+ else {
269
+ this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
270
+ }
235
271
  // Retrieve initial values and updateHomekit
236
272
  this.updateHomeKitCharacteristics();
237
273
  // Start an update interval
@@ -332,6 +368,14 @@ class Bot {
332
368
  }
333
369
  accessory.removeService(this.windowCoveringService);
334
370
  }
371
+ removeStatefulProgrammableSwitchService(accessory) {
372
+ // If statefulProgrammableSwitchService still pressent, then remove first
373
+ this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
374
+ if (this.statefulProgrammableSwitchService) {
375
+ this.warnLog(`Bot: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
376
+ }
377
+ accessory.removeService(this.statefulProgrammableSwitchService);
378
+ }
335
379
  removeSwitchService(accessory) {
336
380
  // If switchService still pressent, then remove first
337
381
  this.switchService = this.accessory.getService(this.platform.Service.Switch);
@@ -340,53 +384,54 @@ class Bot {
340
384
  }
341
385
  accessory.removeService(this.switchService);
342
386
  }
343
- refreshRate() {
344
- if (this.device.refreshRate) {
345
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
346
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
347
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
387
+ scan(device) {
388
+ if (device.scanDuration) {
389
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
390
+ if (device.ble) {
391
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
348
392
  }
349
393
  }
350
- else if (this.platform.config.options.refreshRate) {
351
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
352
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
353
- this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
394
+ else {
395
+ this.scanDuration = this.accessory.context.scanDuration = 1;
396
+ if (this.device.ble) {
397
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
354
398
  }
355
399
  }
356
400
  }
357
- scan() {
358
- if (this.device.scanDuration) {
359
- this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
360
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
361
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
362
- }
401
+ config(device) {
402
+ if (device.bot !== undefined) {
403
+ device.bot['ble'] = device.ble;
404
+ device.bot['logging'] = this.deviceLogging;
405
+ device.bot['refreshRate'] = this.deviceRefreshRate;
406
+ this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(device.bot)}`);
363
407
  }
364
- else {
365
- this.scanDuration = this.accessory.context.scanDuration = 1;
366
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
367
- this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
368
- }
408
+ }
409
+ refreshRate(device) {
410
+ if (device.refreshRate) {
411
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
412
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
413
+ }
414
+ else if (this.platform.config.options.refreshRate) {
415
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
416
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
369
417
  }
370
418
  }
371
- logs() {
419
+ logs(device) {
372
420
  if (this.platform.debugMode) {
373
- this.deviceLogging = this.accessory.context.logging = 'debug';
374
- this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
421
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
422
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
375
423
  }
376
- else if (this.device.logging) {
377
- this.deviceLogging = this.accessory.context.logging = this.device.logging;
378
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
379
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
380
- }
424
+ else if (device.logging) {
425
+ this.deviceLogging = this.accessory.context.logging = device.logging;
426
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
381
427
  }
382
428
  else if (this.platform.config.options?.logging) {
383
429
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
384
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
385
- this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
386
- }
430
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
387
431
  }
388
432
  else {
389
433
  this.deviceLogging = this.accessory.context.logging = 'standard';
434
+ this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
390
435
  }
391
436
  }
392
437
  PressOrSwitch() {
@@ -411,11 +456,11 @@ class Bot {
411
456
  * Parse the device status from the SwitchBot api
412
457
  */
413
458
  async parseStatus() {
414
- if (this.device.ble) {
415
- await this.BLEparseStatus();
459
+ if (this.SwitchToOpenAPI || !this.device.ble) {
460
+ await this.openAPIparseStatus();
416
461
  }
417
462
  else {
418
- await this.openAPIparseStatus();
463
+ await this.BLEparseStatus();
419
464
  }
420
465
  }
421
466
  async BLEparseStatus() {
@@ -448,6 +493,9 @@ class Bot {
448
493
  this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
449
494
  }
450
495
  async openAPIparseStatus() {
496
+ if (this.device.ble) {
497
+ this.SwitchToOpenAPI = false;
498
+ }
451
499
  if (this.platform.config.credentials?.openToken) {
452
500
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
453
501
  if (this.botMode === 'press') {
@@ -456,15 +504,19 @@ class Bot {
456
504
  this.accessory.context.On = this.OnCached;
457
505
  }
458
506
  else {
459
- if (this.deviceStatus.body.power === 'on') {
460
- this.On = true;
461
- this.OnCached = this.On;
462
- this.accessory.context.On = this.OnCached;
463
- }
464
- else {
507
+ /*if (this.power === 'on') {
508
+ this.On = true;
509
+ this.OnCached = this.On;
510
+ this.accessory.context.On = this.OnCached;
511
+ } else {
512
+ this.On = false;
513
+ this.OnCached = this.On;
514
+ this.accessory.context.On = this.OnCached;
515
+ }*/
516
+ this.OnCached = this.On;
517
+ this.accessory.context.On = this.OnCached;
518
+ if (this.On === undefined) {
465
519
  this.On = false;
466
- this.OnCached = this.On;
467
- this.accessory.context.On = this.OnCached;
468
520
  }
469
521
  }
470
522
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
@@ -481,34 +533,12 @@ class Bot {
481
533
  await this.openAPIRefreshStatus();
482
534
  }
483
535
  }
484
- async connectBLE() {
485
- let switchbot;
486
- try {
487
- // eslint-disable-next-line @typescript-eslint/no-var-requires
488
- const Switchbot = require('node-switchbot');
489
- switchbot = new Switchbot();
490
- // Convert to BLE Address
491
- this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
492
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
493
- }
494
- catch (e) {
495
- switchbot = false;
496
- this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
497
- if (this.deviceLogging === 'debug') {
498
- this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
499
- + ` Error Message: ${JSON.stringify(e.message)}`);
500
- }
501
- if (this.platform.debugMode) {
502
- this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
503
- + ` Error: ${JSON.stringify(e)}`);
504
- }
505
- }
506
- return switchbot;
507
- }
508
536
  async BLERefreshStatus() {
509
537
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
538
+ const switchbot = await this.platform.connectBLE();
510
539
  // Convert to BLE Address
511
- const switchbot = await this.connectBLE();
540
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
541
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
512
542
  // Start to monitor advertisement packets
513
543
  if (switchbot === false) {
514
544
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
@@ -548,6 +578,7 @@ class Bot {
548
578
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
549
579
  if (this.platform.config.credentials?.openToken) {
550
580
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
581
+ this.SwitchToOpenAPI = true;
551
582
  await this.openAPIRefreshStatus();
552
583
  }
553
584
  }
@@ -563,6 +594,7 @@ class Bot {
563
594
  }
564
595
  if (this.platform.config.credentials?.openToken) {
565
596
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
597
+ this.SwitchToOpenAPI = true;
566
598
  await this.openAPIRefreshStatus();
567
599
  }
568
600
  this.apiError(e);
@@ -574,6 +606,7 @@ class Bot {
574
606
  try {
575
607
  this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
576
608
  this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
609
+ this.power = this.deviceStatus.body.power;
577
610
  this.parseStatus();
578
611
  this.updateHomeKitCharacteristics();
579
612
  }
@@ -616,7 +649,10 @@ class Bot {
616
649
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
617
650
  if (this.On !== this.OnCached) {
618
651
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
619
- const switchbot = await this.connectBLE();
652
+ const switchbot = await this.platform.connectBLE();
653
+ // Convert to BLE Address
654
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
655
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
620
656
  //if (switchbot !== false) {
621
657
  if (this.botMode === 'press') {
622
658
  this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
@@ -886,6 +922,24 @@ class Bot {
886
922
  }
887
923
  this.debugLog(`Bot: ${this.accessory.displayName} Fan On: ${this.On}`);
888
924
  }
925
+ else if (this.device.bot?.deviceType === 'stateful') {
926
+ if (this.On === undefined) {
927
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
928
+ }
929
+ else {
930
+ if (this.On) {
931
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
932
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
933
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
934
+ }
935
+ else {
936
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
937
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
938
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
939
+ }
940
+ }
941
+ this.debugLog(`Bot: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
942
+ }
889
943
  else if (this.device.bot?.deviceType === 'switch') {
890
944
  if (this.On === undefined) {
891
945
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
@@ -952,6 +1006,10 @@ class Bot {
952
1006
  else if (this.device.bot?.deviceType === 'fan') {
953
1007
  this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
954
1008
  }
1009
+ else if (this.device.bot?.deviceType === 'stateful') {
1010
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
1011
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
1012
+ }
955
1013
  else if (this.device.bot?.deviceType === 'switch') {
956
1014
  this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
957
1015
  }
@@ -1047,6 +1105,15 @@ class Bot {
1047
1105
  this.On = true;
1048
1106
  }
1049
1107
  }
1108
+ else if (this.device.bot?.deviceType === 'stateful') {
1109
+ this.debugLog(`Bot: ${this.accessory.displayName} ProgrammableSwitchOutputState: ${value}`);
1110
+ if (value === 0) {
1111
+ this.On = false;
1112
+ }
1113
+ else {
1114
+ this.On = true;
1115
+ }
1116
+ }
1050
1117
  else {
1051
1118
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${value}`);
1052
1119
  this.On = value;