@switchbot/homebridge-switchbot 1.7.1-beta.1 → 1.7.1-beta.13

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 +9 -2
  2. package/config.schema.json +49 -36
  3. package/dist/devices/bots.d.ts +7 -5
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +72 -66
  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 +50 -37
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +9 -10
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +105 -137
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +11 -4
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +70 -44
  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 +42 -36
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +17 -15
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +99 -133
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +8 -9
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +97 -120
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +6 -4
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +44 -31
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +2 -1
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +19 -12
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +4 -3
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +23 -16
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +2 -1
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +19 -12
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +2 -1
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +19 -12
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +2 -1
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +19 -12
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +3 -2
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +23 -16
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +2 -1
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +19 -12
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +2 -1
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +19 -12
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +2 -1
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +19 -12
  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 +7 -1
  76. package/dist/settings.d.ts.map +1 -1
  77. package/dist/settings.js.map +1 -1
  78. package/package.json +5 -5
  79. package/src/devices/bots.ts +75 -70
  80. package/src/devices/colorbulb.ts +56 -40
  81. package/src/devices/contact.ts +108 -138
  82. package/src/devices/curtains.ts +79 -48
  83. package/src/devices/humidifiers.ts +50 -37
  84. package/src/devices/meters.ts +115 -143
  85. package/src/devices/motion.ts +102 -121
  86. package/src/devices/plugs.ts +47 -32
  87. package/src/irdevices/airconditioners.ts +20 -12
  88. package/src/irdevices/airpurifiers.ts +24 -16
  89. package/src/irdevices/cameras.ts +20 -12
  90. package/src/irdevices/fans.ts +20 -12
  91. package/src/irdevices/lights.ts +20 -12
  92. package/src/irdevices/others.ts +24 -16
  93. package/src/irdevices/tvs.ts +20 -12
  94. package/src/irdevices/vacuumcleaners.ts +20 -12
  95. package/src/irdevices/waterheaters.ts +20 -12
  96. package/src/platform.ts +14 -1
  97. package/src/settings.ts +7 -1
package/CHANGELOG.md CHANGED
@@ -2,17 +2,24 @@
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.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.7.1) (2022-01-00)
5
+ ## [Beta - Version 1.8.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.8.0) (2022-01-XX)
6
6
 
7
7
  ## What's Changed
8
8
  * Added option to display Bot a Stateful Programmable Switch.
9
9
  * This will only Works in 3rd Party Home App, Like [Eve](https://apps.apple.com/us/app/eve-for-homekit/id917695792) or [Home+ 5](https://apps.apple.com/us/app/home-5/id995994352)
10
10
  * Add option to Hide Motion Sensor's Light Sensor.
11
11
  * Add option to Set Motion Sensor's Light Sensor `set_minLux` and `set_maxLux`.
12
+ * Fixed Bug: Where BLE config would show for devices that don't support BLE.
12
13
  * Fixed Bug: Contact Sensors's Motion Sensor and Light Sensor showing undefined values.
13
14
  * Fixed Bug: Motion Sensors's Light Sensor showing undefined values.
15
+ * Fixed Bug: Battery Service wouldn't be removed from Curtain, Contact Sensor, or Motion Sensor when switching from BLE to OpenAPI.
16
+ * Enhancments: Made some improvemnt on the switch from BLE to OpenAPI when BLE connection fails.
17
+ * Enhancments: Made Optional Switchbot Device Settings and Optional IR Device Settings more managable by using Tabs.
18
+ * Change: Changed Curtain `refreshRate` to `updateRate`.
19
+ * You will have to update your config for it to pickup the new `updateRate`.
20
+ * Housekeeping and updated dependencies.
14
21
 
15
- **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.7.0...v1.7.1
22
+ **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.7.0...v1.8.0
16
23
 
17
24
  ## [Version 1.7.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.7.0) (2022-01-05)
18
25
 
@@ -11,8 +11,7 @@
11
11
  "name": {
12
12
  "type": "string",
13
13
  "title": "Name",
14
- "default": "SwitchBot",
15
- "required": true
14
+ "default": "SwitchBot"
16
15
  },
17
16
  "credentials": {
18
17
  "type": "object",
@@ -20,7 +19,6 @@
20
19
  "openToken": {
21
20
  "title": "Token",
22
21
  "type": "string",
23
- "required": true,
24
22
  "x-schema-form": {
25
23
  "type": "password"
26
24
  }
@@ -28,10 +26,13 @@
28
26
  "notice": {
29
27
  "title": "Notice",
30
28
  "type": "string",
31
- "required": true,
32
29
  "default": "Keep your token a secret!"
33
30
  }
34
- }
31
+ },
32
+ "required": [
33
+ "openToken",
34
+ "notice"
35
+ ]
35
36
  },
36
37
  "options": {
37
38
  "type": "object",
@@ -52,7 +53,7 @@
52
53
  "type": "string",
53
54
  "placeholder": "SwitchBot",
54
55
  "condition": {
55
- "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].ble && !model.options.devices[arrayIndices].hide_device);"
56
+ "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId);"
56
57
  }
57
58
  },
58
59
  "hide_device": {
@@ -137,11 +138,11 @@
137
138
  "title": "Enable Bluetooth Low Energy (BLE) Connection",
138
139
  "type": "boolean",
139
140
  "condition": {
140
- "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device);"
141
+ "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device && (model.options.devices[arrayIndices].configDeviceType === 'Humidifier' || model.options.devices[arrayIndices].configDeviceType === 'Meter' || model.options.devices[arrayIndices].configDeviceType === 'Curtain' || model.options.devices[arrayIndices].configDeviceType === 'Bot'));"
141
142
  }
142
143
  },
143
144
  "scanDuration": {
144
- "title": "Scan Duration (Default is 1 Second)",
145
+ "title": "BLE Scan Duration (Default is 1 Second)",
145
146
  "type": "number",
146
147
  "placeholder": 1,
147
148
  "condition": {
@@ -321,8 +322,8 @@
321
322
  "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Curtain' && model.options.devices[arrayIndices].deviceId);"
322
323
  }
323
324
  },
324
- "refreshRate": {
325
- "title": "Curtain Refresh Rate",
325
+ "updateRate": {
326
+ "title": "Curtain Update Rate",
326
327
  "type": "number",
327
328
  "minimum": 1,
328
329
  "placeholder": 5,
@@ -455,7 +456,7 @@
455
456
  "placeholder": 360,
456
457
  "description": "Indicates the number of seconds between polls of SwitchBot API.",
457
458
  "condition": {
458
- "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device);"
459
+ "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType);"
459
460
  }
460
461
  },
461
462
  "logging": {
@@ -482,11 +483,17 @@
482
483
  }
483
484
  ],
484
485
  "condition": {
485
- "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device);"
486
+ "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType);"
486
487
  }
487
488
  }
488
- }
489
- }
489
+ },
490
+ "required": [
491
+ "deviceId",
492
+ "configDeviceType",
493
+ "configDeviceName"
494
+ ]
495
+ },
496
+ "uniqueItems": true
490
497
  },
491
498
  "irdevices": {
492
499
  "type": "array",
@@ -804,11 +811,16 @@
804
811
  }
805
812
  ],
806
813
  "condition": {
807
- "functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId && !model.options.irdevices[arrayIndices].hide_device);"
814
+ "functionBody": "return (model.options && model.options.irdevices && model.options.irdevices[arrayIndices].deviceId && !model.options.irdevices[arrayIndices].hide_device && model.options.irdevices[arrayIndices].configRemoteType);"
808
815
  }
809
816
  }
810
- }
811
- }
817
+ },
818
+ "required": [
819
+ "deviceId",
820
+ "configRemoteType"
821
+ ]
822
+ },
823
+ "uniqueItems": true
812
824
  },
813
825
  "refreshRate": {
814
826
  "title": "Refresh Rate",
@@ -849,7 +861,10 @@
849
861
  }
850
862
  }
851
863
  }
852
- }
864
+ },
865
+ "required": [
866
+ "name"
867
+ ]
853
868
  },
854
869
  "layout": [
855
870
  {
@@ -862,28 +877,27 @@
862
877
  ]
863
878
  },
864
879
  {
865
- "key": "options.devices",
866
- "notitle": false,
867
- "add": "Add Another Device",
868
880
  "type": "fieldset",
869
881
  "title": "Optional SwitchBot Device Settings",
870
882
  "expandable": true,
871
883
  "expanded": false,
872
- "orderable": false,
873
- "buttonText": "Add Device",
874
884
  "items": [
875
885
  {
876
- "type": "div",
877
- "displayFlex": true,
878
- "flex-direction": "column",
886
+ "key": "options.devices",
887
+ "notitle": false,
888
+ "type": "tabarray",
889
+ "title": "{{ value.configDeviceName || value.deviceId || 'New SwitchBot Device' }}",
890
+ "expandable": true,
891
+ "expanded": false,
892
+ "orderable": false,
879
893
  "items": [
880
894
  "options.devices[].configDeviceName",
881
895
  "options.devices[].deviceId",
882
896
  "options.devices[].hide_device",
897
+ "options.devices[].configDeviceType",
883
898
  "options.devices[].offline",
884
899
  "options.devices[].ble",
885
900
  "options.devices[].scanDuration",
886
- "options.devices[].configDeviceType",
887
901
  "options.devices[].bot.mode",
888
902
  "options.devices[].bot.deviceType",
889
903
  "options.devices[].bot.doublePress",
@@ -894,7 +908,7 @@
894
908
  "options.devices[].curtain.set_minStep",
895
909
  "options.devices[].curtain.set_min",
896
910
  "options.devices[].curtain.set_max",
897
- "options.devices[].curtain.refreshRate",
911
+ "options.devices[].curtain.updateRate",
898
912
  "options.devices[].curtain.disable_group",
899
913
  "options.devices[].curtain.hide_lightsensor",
900
914
  "options.devices[].curtain.set_minlux",
@@ -915,20 +929,19 @@
915
929
  ]
916
930
  },
917
931
  {
918
- "key": "options.irdevices",
919
- "notitle": false,
920
- "add": "Add Another IR Device",
921
932
  "type": "fieldset",
922
933
  "title": "Optional IR Device Settings",
923
934
  "expandable": true,
924
935
  "expanded": false,
925
- "orderable": false,
926
- "buttonText": "Add IR Device",
927
936
  "items": [
928
937
  {
929
- "type": "div",
930
- "displayFlex": true,
931
- "flex-direction": "column",
938
+ "key": "options.irdevices",
939
+ "notitle": false,
940
+ "type": "tabarray",
941
+ "title": "{{ value.configDeviceName || value.deviceId || 'New IR Device' }}",
942
+ "expandable": true,
943
+ "expanded": false,
944
+ "orderable": false,
932
945
  "items": [
933
946
  "options.irdevices[].deviceId",
934
947
  "options.irdevices[].hide_device",
@@ -1,7 +1,7 @@
1
1
  import { Subject } from 'rxjs';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { PlatformAccessory, CharacteristicValue } from 'homebridge';
4
- import { device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
4
+ import { device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus } from '../settings';
5
5
  /**
6
6
  * Platform Accessory
7
7
  * An instance of this class is created for each accessory your platform registers
@@ -26,9 +26,11 @@ export declare class Bot {
26
26
  OnCached: CharacteristicValue;
27
27
  BatteryLevel: CharacteristicValue;
28
28
  StatusLowBattery: CharacteristicValue;
29
+ power: deviceStatus['power'];
29
30
  deviceStatus: deviceStatusResponse;
30
31
  connected?: boolean;
31
32
  switchbot: switchbot;
33
+ SwitchToOpenAPI?: boolean;
32
34
  serviceData: serviceData;
33
35
  mode: serviceData['mode'];
34
36
  state: serviceData['state'];
@@ -51,9 +53,10 @@ export declare class Bot {
51
53
  removeWindowCoveringService(accessory: PlatformAccessory): void;
52
54
  removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): void;
53
55
  removeSwitchService(accessory: PlatformAccessory): void;
54
- refreshRate(): void;
55
- scan(): void;
56
- logs(): void;
56
+ config(device: device & devicesConfig): void;
57
+ refreshRate(device: device & devicesConfig): void;
58
+ scan(device: device & devicesConfig): void;
59
+ logs(device: device & devicesConfig): void;
57
60
  PressOrSwitch(): void;
58
61
  /**
59
62
  * Parse the device status from the SwitchBot api
@@ -65,7 +68,6 @@ export declare class Bot {
65
68
  * Asks the SwitchBot API for the latest device information
66
69
  */
67
70
  refreshStatus(): Promise<void>;
68
- connectBLE(): Promise<any>;
69
71
  private BLERefreshStatus;
70
72
  private openAPIRefreshStatus;
71
73
  /**
@@ -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;IA8CZ,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,SAAS;IACV,MAA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,UAAU;IAWlB;;OAEG;IACH,OAAO,CAAC,WAAW;IA6CnB;;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"}
@@ -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;
@@ -254,12 +252,22 @@ class Bot {
254
252
  this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
255
253
  this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
256
254
  }
257
- 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`);
258
263
  (this.batteryService =
259
- accessory.getService(this.platform.Service.Battery) ||
260
- 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`;
261
266
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
262
267
  }
268
+ else {
269
+ this.debugLog(`Bot: ${accessory.displayName} Battery Service Not Added`);
270
+ }
263
271
  // Retrieve initial values and updateHomekit
264
272
  this.updateHomeKitCharacteristics();
265
273
  // Start an update interval
@@ -376,53 +384,64 @@ class Bot {
376
384
  }
377
385
  accessory.removeService(this.switchService);
378
386
  }
379
- refreshRate() {
380
- if (this.device.refreshRate) {
381
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
382
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
383
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
384
- }
387
+ config(device) {
388
+ const config = device.bot;
389
+ if (device.ble !== undefined) {
390
+ config['ble'] = device.ble;
391
+ }
392
+ if (device.logging !== undefined) {
393
+ config['logging'] = device.logging;
394
+ }
395
+ if (device.refreshRate !== undefined) {
396
+ config['refreshRate'] = device.refreshRate;
397
+ }
398
+ if (device.scanDuration !== undefined) {
399
+ config['scanDuration'] = device.scanDuration;
400
+ }
401
+ if (config !== undefined) {
402
+ this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
403
+ }
404
+ }
405
+ refreshRate(device) {
406
+ if (device.refreshRate) {
407
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
408
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
385
409
  }
386
410
  else if (this.platform.config.options.refreshRate) {
387
411
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
388
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
389
- this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
390
- }
412
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
391
413
  }
392
414
  }
393
- scan() {
394
- if (this.device.scanDuration) {
395
- this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
396
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
397
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
415
+ scan(device) {
416
+ if (device.scanDuration) {
417
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
418
+ if (device.ble) {
419
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
398
420
  }
399
421
  }
400
422
  else {
401
423
  this.scanDuration = this.accessory.context.scanDuration = 1;
402
- if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
403
- this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
424
+ if (this.device.ble) {
425
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
404
426
  }
405
427
  }
406
428
  }
407
- logs() {
429
+ logs(device) {
408
430
  if (this.platform.debugMode) {
409
- this.deviceLogging = this.accessory.context.logging = 'debug';
410
- this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
431
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
432
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
411
433
  }
412
- else if (this.device.logging) {
413
- this.deviceLogging = this.accessory.context.logging = this.device.logging;
414
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
415
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
416
- }
434
+ else if (device.logging) {
435
+ this.deviceLogging = this.accessory.context.logging = device.logging;
436
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
417
437
  }
418
438
  else if (this.platform.config.options?.logging) {
419
439
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
420
- if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') {
421
- this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
422
- }
440
+ this.debugLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
423
441
  }
424
442
  else {
425
443
  this.deviceLogging = this.accessory.context.logging = 'standard';
444
+ this.debugLog(`Bot: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
426
445
  }
427
446
  }
428
447
  PressOrSwitch() {
@@ -447,11 +466,11 @@ class Bot {
447
466
  * Parse the device status from the SwitchBot api
448
467
  */
449
468
  async parseStatus() {
450
- if (this.device.ble) {
451
- await this.BLEparseStatus();
469
+ if (this.SwitchToOpenAPI || !this.device.ble) {
470
+ await this.openAPIparseStatus();
452
471
  }
453
472
  else {
454
- await this.openAPIparseStatus();
473
+ await this.BLEparseStatus();
455
474
  }
456
475
  }
457
476
  async BLEparseStatus() {
@@ -484,6 +503,9 @@ class Bot {
484
503
  this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
485
504
  }
486
505
  async openAPIparseStatus() {
506
+ if (this.device.ble) {
507
+ this.SwitchToOpenAPI = false;
508
+ }
487
509
  if (this.platform.config.credentials?.openToken) {
488
510
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
489
511
  if (this.botMode === 'press') {
@@ -492,7 +514,7 @@ class Bot {
492
514
  this.accessory.context.On = this.OnCached;
493
515
  }
494
516
  else {
495
- /*if (this.deviceStatus.body.power === 'on') {
517
+ /*if (this.power === 'on') {
496
518
  this.On = true;
497
519
  this.OnCached = this.On;
498
520
  this.accessory.context.On = this.OnCached;
@@ -521,34 +543,12 @@ class Bot {
521
543
  await this.openAPIRefreshStatus();
522
544
  }
523
545
  }
524
- async connectBLE() {
525
- let switchbot;
526
- try {
527
- // eslint-disable-next-line @typescript-eslint/no-var-requires
528
- const Switchbot = require('node-switchbot');
529
- switchbot = new Switchbot();
530
- // Convert to BLE Address
531
- this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
532
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
533
- }
534
- catch (e) {
535
- switchbot = false;
536
- this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
537
- if (this.deviceLogging === 'debug') {
538
- this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
539
- + ` Error Message: ${JSON.stringify(e.message)}`);
540
- }
541
- if (this.platform.debugMode) {
542
- this.errorLog(`Bot: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
543
- + ` Error: ${JSON.stringify(e)}`);
544
- }
545
- }
546
- return switchbot;
547
- }
548
546
  async BLERefreshStatus() {
549
547
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
548
+ const switchbot = await this.platform.connectBLE();
550
549
  // Convert to BLE Address
551
- const switchbot = await this.connectBLE();
550
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
551
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
552
552
  // Start to monitor advertisement packets
553
553
  if (switchbot === false) {
554
554
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection: ${switchbot}`);
@@ -588,6 +588,7 @@ class Bot {
588
588
  this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
589
589
  if (this.platform.config.credentials?.openToken) {
590
590
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
591
+ this.SwitchToOpenAPI = true;
591
592
  await this.openAPIRefreshStatus();
592
593
  }
593
594
  }
@@ -603,6 +604,7 @@ class Bot {
603
604
  }
604
605
  if (this.platform.config.credentials?.openToken) {
605
606
  this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
607
+ this.SwitchToOpenAPI = true;
606
608
  await this.openAPIRefreshStatus();
607
609
  }
608
610
  this.apiError(e);
@@ -614,6 +616,7 @@ class Bot {
614
616
  try {
615
617
  this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
616
618
  this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
619
+ this.power = this.deviceStatus.body.power;
617
620
  this.parseStatus();
618
621
  this.updateHomeKitCharacteristics();
619
622
  }
@@ -656,7 +659,10 @@ class Bot {
656
659
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
657
660
  if (this.On !== this.OnCached) {
658
661
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
659
- const switchbot = await this.connectBLE();
662
+ const switchbot = await this.platform.connectBLE();
663
+ // Convert to BLE Address
664
+ this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
665
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
660
666
  //if (switchbot !== false) {
661
667
  if (this.botMode === 'press') {
662
668
  this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);