@switchbot/homebridge-switchbot 1.6.2-beta.1 → 1.6.4-beta.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
4
4
 
5
+ ## [Beta - Version 1.7.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.7.0) (2022-01-XX)
6
+
7
+ ## What's Changed
8
+ * Added option to display Bot a Garage Door Opener? [#179](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/179)
9
+
10
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.3...v1.7.0
11
+
12
+ ## [Version 1.6.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.3) (2022-01-03)
13
+
14
+ ## What's Changed
15
+ * Quick Fix for for issue not tested in `v1.6.2`.
16
+
17
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.2...v1.6.3
18
+
19
+ ## [Version 1.6.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.2) (2022-01-03)
20
+
21
+ ## What's Changed
22
+ * Fixed Bug: npm ERR! code 1. [#151](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/151)
23
+ * Made `node-switchbot` an optionalDependencies
24
+ * So If `node-switchbot` doesn't get installed successfully then BLE will not work.
25
+ * Housekeeping and updated dependencies.
26
+
27
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.1...v1.6.2
28
+
5
29
  ## [Version 1.6.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.1) (2022-01-02)
6
30
 
7
31
  ## What's Changed
@@ -182,6 +182,12 @@
182
182
  "outlet"
183
183
  ]
184
184
  },
185
+ {
186
+ "title": "Garage Door",
187
+ "enum": [
188
+ "garagedoor"
189
+ ]
190
+ },
185
191
  {
186
192
  "title": "Switch",
187
193
  "enum": [
@@ -11,8 +11,9 @@ export declare class Bot {
11
11
  private readonly platform;
12
12
  private accessory;
13
13
  device: device & devicesConfig;
14
- private outletService?;
15
14
  private switchService?;
15
+ private garageDoorService?;
16
+ private outletService?;
16
17
  private batteryService?;
17
18
  On: CharacteristicValue;
18
19
  OnCached: CharacteristicValue;
@@ -33,6 +34,9 @@ export declare class Bot {
33
34
  botUpdateInProgress: boolean;
34
35
  doBotUpdate: Subject<void>;
35
36
  constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: device & devicesConfig);
37
+ private removeOutletService;
38
+ private removeGarageDoorService;
39
+ private removeSwitchService;
36
40
  refreshRate(): void;
37
41
  scan(): void;
38
42
  logs(): void;
@@ -49,6 +53,7 @@ export declare class Bot {
49
53
  refreshStatus(): Promise<void>;
50
54
  private connectBLE;
51
55
  private BLERefreshStatus;
56
+ private BLEconnection;
52
57
  private openAPIRefreshStatus;
53
58
  /**
54
59
  * Pushes the requested changes to the SwitchBot API
@@ -1 +1 @@
1
- {"version":3,"file":"bots.d.ts","sourceRoot":"","sources":["../../src/devices/bots.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAW,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAa,MAAM,EAAE,aAAa,EAAE,WAAW,EAAM,SAAS,EAAE,oBAAoB,EAAW,MAAM,aAAa,CAAC;AAE1H;;;;GAIG;AACH,qBAAa,GAAG;IAqCZ,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,SAAS;IACV,MAAM,EAAE,MAAM,GAAG,aAAa;IArCvC,OAAO,CAAC,aAAa,CAAC,CAAU;IAChC,OAAO,CAAC,aAAa,CAAC,CAAU;IAChC,OAAO,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CAAC,SAAS,CAAC,CAAC;IAGjC,OAAO,EAAG,MAAM,CAAC;IACjB,YAAY,EAAG,MAAM,CAAC;IACtB,aAAa,EAAG,MAAM,CAAC;IACvB,iBAAiB,EAAG,MAAM,CAAC;IAG3B,WAAW,EAAG,MAAM,CAAC;IAGrB,mBAAmB,EAAG,OAAO,CAAC;IAC9B,WAAW,EAAG,OAAO,CAAC,IAAI,CAAC,CAAC;gBAGT,QAAQ,EAAE,iBAAiB,EACpC,SAAS,EAAE,iBAAiB,EAC7B,MAAM,EAAE,MAAM,GAAG,aAAa;IAmIvC,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,mBAAmB;IAS3B,WAAW;IAcX,IAAI;IAcJ,IAAI;IAmBJ,aAAa;IAgBb;;OAEG;IACG,WAAW;YAQH,cAAc;YA6Bd,kBAAkB;IAsBhC;;OAEG;IACG,aAAa;IAQnB,OAAO,CAAC,UAAU;YAQJ,gBAAgB;YA6DhB,aAAa;YAQb,oBAAoB;IAuBlC;;;;;;OAMG;IACG,WAAW;YAcH,cAAc;IAgF5B,OAAO,CAAC,SAAS;YAQH,kBAAkB;IAmDhC;;OAEG;IACH,4BAA4B;IAqDrB,QAAQ,CAAC,CAAC,EAAE,GAAG;IAatB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,UAAU;IAWlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;KAEC;IACD,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMrB,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMrB,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMtB,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAUtB,qBAAqB,IAAI,OAAO;CAGjC"}
@@ -52,34 +52,38 @@ class Bot {
52
52
  // get the LightBulb service if it exists, otherwise create a new LightBulb service
53
53
  // you can create multiple services for each accessory
54
54
  if (device.bot?.deviceType === 'switch') {
55
- // If outletService still pressent, then remove first
56
- if (this.outletService) {
57
- this.debugLog(`Bot: ${accessory.displayName} Removing Leftover outletService first`);
58
- }
59
- this.outletService = this.accessory.getService(this.platform.Service.Outlet);
60
- accessory.removeService(this.outletService);
55
+ this.removeOutletService(accessory);
56
+ this.removeGarageDoorService(accessory);
61
57
  // Add switchService
62
58
  (this.switchService =
63
59
  accessory.getService(this.platform.Service.Switch) ||
64
60
  accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Switch`;
65
- if (this.deviceLogging !== 'none') {
66
- this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
67
- }
68
- this.switchService?.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
61
+ this.infoLog(`Bot: ${accessory.displayName} Displaying as Switch`);
62
+ this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
63
+ this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
64
+ }
65
+ else if (device.bot?.deviceType === 'garagedoor') {
66
+ this.removeOutletService(accessory);
67
+ this.removeSwitchService(accessory);
68
+ // Add switchService
69
+ (this.garageDoorService =
70
+ accessory.getService(this.platform.Service.GarageDoorOpener) ||
71
+ accessory.addService(this.platform.Service.GarageDoorOpener)), `${accessory.displayName} Garage Door Opener`;
72
+ this.infoLog(`Bot: ${accessory.displayName} Displaying as Garage Door Opener`);
73
+ this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
74
+ this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.handleOnSet.bind(this));
75
+ this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
69
76
  }
70
77
  else {
71
- // If switchService still pressent, then remove first
72
- if (this.switchService) {
73
- this.debugLog(`Bot: ${accessory.displayName} Removing Leftover switchService first`);
74
- }
75
- this.switchService = this.accessory.getService(this.platform.Service.Switch);
76
- accessory.removeService(this.switchService);
78
+ this.removeSwitchService(accessory);
79
+ this.removeGarageDoorService(accessory);
77
80
  // Add outletService
78
81
  (this.outletService =
79
82
  accessory.getService(this.platform.Service.Outlet) ||
80
83
  accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Outlet`;
81
84
  this.infoLog(`Bot: ${accessory.displayName} Displaying as Outlet`);
82
- this.outletService?.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
85
+ this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
86
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
83
87
  }
84
88
  if (device.ble) {
85
89
  (this.batteryService =
@@ -87,14 +91,6 @@ class Bot {
87
91
  accessory.addService(this.platform.Service.Battery)), `${accessory.displayName} Battery`;
88
92
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
89
93
  }
90
- // each service must implement at-minimum the "required characteristics" for the given service type
91
- // see https://developers.homebridge.io/#/service/Outlet
92
- if (device.bot?.deviceType === 'switch') {
93
- this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
94
- }
95
- else {
96
- this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
97
- }
98
94
  // Retrieve initial values and updateHomekit
99
95
  this.updateHomeKitCharacteristics();
100
96
  // Start an update interval
@@ -131,6 +127,30 @@ class Bot {
131
127
  this.botUpdateInProgress = false;
132
128
  });
133
129
  }
130
+ removeOutletService(accessory) {
131
+ // If outletService still pressent, then remove first
132
+ if (this.outletService) {
133
+ this.debugLog(`Bot: ${accessory.displayName} Removing Leftover outletService first`);
134
+ }
135
+ this.outletService = this.accessory.getService(this.platform.Service.Outlet);
136
+ accessory.removeService(this.outletService);
137
+ }
138
+ removeGarageDoorService(accessory) {
139
+ // If outletService still pressent, then remove first
140
+ if (this.outletService) {
141
+ this.debugLog(`Bot: ${accessory.displayName} Removing Leftover outletService first`);
142
+ }
143
+ this.outletService = this.accessory.getService(this.platform.Service.Outlet);
144
+ accessory.removeService(this.outletService);
145
+ }
146
+ removeSwitchService(accessory) {
147
+ // If switchService still pressent, then remove first
148
+ if (this.switchService) {
149
+ this.debugLog(`Bot: ${accessory.displayName} Removing Leftover switchService first`);
150
+ }
151
+ this.switchService = this.accessory.getService(this.platform.Service.Switch);
152
+ accessory.removeService(this.switchService);
153
+ }
134
154
  refreshRate() {
135
155
  if (this.device.refreshRate) {
136
156
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
@@ -284,61 +304,68 @@ class Bot {
284
304
  // Convert to BLE Address
285
305
  const switchbot = this.connectBLE();
286
306
  // Start to monitor advertisement packets
287
- this.warnLog(`Bot: ${this.accessory.displayName} platform.Switchbot: ${JSON.stringify(switchbot)}`);
288
- switchbot.startScan({
289
- model: 'H',
290
- id: this.device.bleMac,
291
- }).then(() => {
292
- // Set an event hander
293
- switchbot.onadvertisement = (ad) => {
294
- this.serviceData = ad.serviceData;
295
- this.mode = ad.serviceData.mode;
296
- this.state = ad.serviceData.state;
297
- this.battery = ad.serviceData.battery;
298
- this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
299
- this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
300
- + ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
301
- if (this.serviceData) {
302
- this.connected = true;
303
- this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
307
+ if (switchbot !== false) {
308
+ switchbot.startScan({
309
+ model: 'H',
310
+ id: this.device.bleMac,
311
+ }).then(() => {
312
+ // Set an event hander
313
+ switchbot.onadvertisement = (ad) => {
314
+ this.serviceData = ad.serviceData;
315
+ this.mode = ad.serviceData.mode;
316
+ this.state = ad.serviceData.state;
317
+ this.battery = ad.serviceData.battery;
318
+ this.debugLog(`Bot: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
319
+ this.debugLog(`Bot: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
320
+ + ` mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`);
321
+ if (this.serviceData) {
322
+ this.connected = true;
323
+ this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
324
+ }
325
+ else {
326
+ this.connected = false;
327
+ this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
328
+ }
329
+ };
330
+ // Wait 2 seconds
331
+ return switchbot.wait(this.scanDuration * 1000);
332
+ }).then(async () => {
333
+ // Stop to monitor
334
+ switchbot.stopScan();
335
+ if (this.connected) {
336
+ this.parseStatus();
337
+ this.updateHomeKitCharacteristics();
304
338
  }
305
339
  else {
306
- this.connected = false;
307
- this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`);
340
+ await this.BLEconnection();
341
+ }
342
+ }).catch(async (e) => {
343
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
344
+ if (this.deviceLogging === 'debug') {
345
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
346
+ + ` Error Message: ${JSON.stringify(e.message)}`);
347
+ }
348
+ if (this.platform.debugMode) {
349
+ this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
350
+ + ` Error: ${JSON.stringify(e)}`);
308
351
  }
309
- };
310
- // Wait 2 seconds
311
- return switchbot.wait(this.scanDuration * 1000);
312
- }).then(async () => {
313
- // Stop to monitor
314
- switchbot.stopScan();
315
- if (this.connected) {
316
- this.parseStatus();
317
- this.updateHomeKitCharacteristics();
318
- }
319
- else {
320
- this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
321
352
  if (this.platform.config.credentials?.openToken) {
322
353
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
323
354
  await this.openAPIRefreshStatus();
324
355
  }
325
- }
326
- }).catch(async (e) => {
327
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
328
- if (this.deviceLogging === 'debug') {
329
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
330
- + ` Error Message: ${JSON.stringify(e.message)}`);
331
- }
332
- if (this.platform.debugMode) {
333
- this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
334
- + ` Error: ${JSON.stringify(e)}`);
335
- }
336
- if (this.platform.config.credentials?.openToken) {
337
- this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
338
- await this.openAPIRefreshStatus();
339
- }
340
- this.apiError(e);
341
- });
356
+ this.apiError(e);
357
+ });
358
+ }
359
+ else {
360
+ await this.BLEconnection();
361
+ }
362
+ }
363
+ async BLEconnection() {
364
+ this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
365
+ if (this.platform.config.credentials?.openToken) {
366
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
367
+ await this.openAPIRefreshStatus();
368
+ }
342
369
  }
343
370
  async openAPIRefreshStatus() {
344
371
  if (this.platform.config.credentials?.openToken) {
@@ -388,71 +415,80 @@ class Bot {
388
415
  if (this.On !== this.OnCached) {
389
416
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
390
417
  const switchbot = this.connectBLE();
391
- if (this.botMode === 'press') {
392
- this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
393
- switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
394
- .then((device_list) => {
395
- this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
396
- return device_list[0].press({ id: this.device.bleMac });
397
- }).then(() => {
398
- this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
399
- this.On = false;
400
- this.OnCached = this.On;
401
- this.accessory.context.On = this.OnCached;
402
- setTimeout(() => {
403
- if (this.device.bot?.deviceType === 'switch') {
404
- this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
418
+ if (switchbot !== false) {
419
+ if (this.botMode === 'press') {
420
+ this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
421
+ switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac })
422
+ .then((device_list) => {
423
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
424
+ return device_list[0].press({ id: this.device.bleMac });
425
+ }).then(() => {
426
+ this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
427
+ this.On = false;
428
+ this.OnCached = this.On;
429
+ this.accessory.context.On = this.OnCached;
430
+ setTimeout(() => {
431
+ if (this.device.bot?.deviceType === 'switch') {
432
+ this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
433
+ }
434
+ else {
435
+ this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
436
+ }
437
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
438
+ }, 500);
439
+ }).catch(async (e) => {
440
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
441
+ if (this.deviceLogging === 'debug') {
442
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
443
+ + ` Error Message: ${JSON.stringify(e.message)}`);
405
444
  }
406
- else {
407
- this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
445
+ if (this.platform.debugMode) {
446
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
447
+ + ` Error: ${JSON.stringify(e)}`);
408
448
  }
409
- this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
410
- }, 500);
411
- }).catch(async (e) => {
412
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
413
- if (this.deviceLogging === 'debug') {
414
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
415
- + ` Error Message: ${JSON.stringify(e.message)}`);
416
- }
417
- if (this.platform.debugMode) {
418
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
419
- + ` Error: ${JSON.stringify(e)}`);
420
- }
421
- if (this.platform.config.credentials?.openToken) {
422
- this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
423
- await this.openAPIpushChanges();
424
- }
425
- this.apiError(e);
426
- });
427
- }
428
- else if (this.botMode === 'switch') {
429
- this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
430
- switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
431
- this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
432
- return this.turnOnOff(device_list);
433
- }).then(() => {
434
- this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
435
- this.OnCached = this.On;
436
- this.accessory.context.On = this.OnCached;
437
- }).catch(async (e) => {
438
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
439
- if (this.deviceLogging === 'debug') {
440
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
441
- + ` Error Message: ${JSON.stringify(e.message)}`);
442
- }
443
- if (this.platform.debugMode) {
444
- this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
445
- + ` Error: ${JSON.stringify(e)}`);
446
- }
447
- if (this.platform.config.credentials?.openToken) {
448
- this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
449
- await this.openAPIpushChanges();
450
- }
451
- this.apiError(e);
452
- });
449
+ if (this.platform.config.credentials?.openToken) {
450
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
451
+ await this.openAPIpushChanges();
452
+ }
453
+ this.apiError(e);
454
+ });
455
+ }
456
+ else if (this.botMode === 'switch') {
457
+ this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`);
458
+ switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list) => {
459
+ this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
460
+ return this.turnOnOff(device_list);
461
+ }).then(() => {
462
+ this.debugLog(`Bot: ${this.accessory.displayName} Done.`);
463
+ this.OnCached = this.On;
464
+ this.accessory.context.On = this.OnCached;
465
+ }).catch(async (e) => {
466
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
467
+ if (this.deviceLogging === 'debug') {
468
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
469
+ + ` Error Message: ${JSON.stringify(e.message)}`);
470
+ }
471
+ if (this.platform.debugMode) {
472
+ this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
473
+ + ` Error: ${JSON.stringify(e)}`);
474
+ }
475
+ if (this.platform.config.credentials?.openToken) {
476
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
477
+ await this.openAPIpushChanges();
478
+ }
479
+ this.apiError(e);
480
+ });
481
+ }
482
+ else {
483
+ throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
484
+ }
453
485
  }
454
486
  else {
455
- throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
487
+ this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
488
+ if (this.platform.config.credentials?.openToken) {
489
+ this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
490
+ await this.openAPIpushChanges();
491
+ }
456
492
  }
457
493
  }
458
494
  this.OnCached = this.On;
@@ -521,17 +557,41 @@ class Bot {
521
557
  * Updates the status for each of the HomeKit Characteristics
522
558
  */
523
559
  updateHomeKitCharacteristics() {
524
- if (this.On === undefined) {
525
- this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
560
+ if (this.device.bot?.deviceType === 'garagedoor') {
561
+ if (this.On === undefined) {
562
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
563
+ }
564
+ else {
565
+ if (this.On) {
566
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, this.platform.Characteristic.TargetDoorState.OPEN);
567
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, this.platform.Characteristic.CurrentDoorState.OPEN);
568
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
569
+ }
570
+ else {
571
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, this.platform.Characteristic.TargetDoorState.CLOSED);
572
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, this.platform.Characteristic.CurrentDoorState.CLOSED);
573
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
574
+ }
575
+ }
576
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
526
577
  }
527
- else {
528
- if (this.device.bot?.deviceType === 'switch') {
578
+ else if (this.device.bot?.deviceType === 'switch') {
579
+ if (this.On === undefined) {
580
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
581
+ }
582
+ else {
529
583
  this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
584
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
585
+ }
586
+ }
587
+ else {
588
+ if (this.On === undefined) {
589
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
530
590
  }
531
591
  else {
532
592
  this.outletService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
593
+ this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
533
594
  }
534
- this.debugLog(`Bot: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
535
595
  }
536
596
  if (this.device.ble) {
537
597
  if (this.BatteryLevel === undefined) {
@@ -608,8 +668,19 @@ class Bot {
608
668
  * Handle requests to set the "On" characteristic
609
669
  */
610
670
  handleOnSet(value) {
611
- this.debugLog(`Bot: ${this.accessory.displayName} On: ${value}`);
612
- this.On = value;
671
+ if (this.device.bot?.deviceType === 'garagedoor') {
672
+ this.debugLog(`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`);
673
+ if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
674
+ this.On = false;
675
+ }
676
+ else {
677
+ this.On = true;
678
+ }
679
+ }
680
+ else {
681
+ this.debugLog(`Bot: ${this.accessory.displayName} On: ${value}`);
682
+ this.On = value;
683
+ }
613
684
  this.doBotUpdate.next();
614
685
  }
615
686
  /**