@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-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.
Files changed (122) hide show
  1. package/.eslintrc +14 -45
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +2 -4
  12. package/.vscode/settings.json +14 -2
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +17 -0
  17. package/dist/devices/bots.d.ts +35 -32
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +168 -210
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +35 -35
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +83 -108
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +27 -25
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +110 -131
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +29 -27
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +147 -182
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +31 -31
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +154 -181
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +29 -28
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +98 -120
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +24 -23
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +97 -113
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +16 -16
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +48 -71
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +3 -22
  52. package/dist/index.js.map +1 -1
  53. package/dist/irdevices/airconditioners.d.ts +7 -4
  54. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  55. package/dist/irdevices/airconditioners.js +72 -93
  56. package/dist/irdevices/airconditioners.js.map +1 -1
  57. package/dist/irdevices/airpurifiers.d.ts +3 -3
  58. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  59. package/dist/irdevices/airpurifiers.js +32 -51
  60. package/dist/irdevices/airpurifiers.js.map +1 -1
  61. package/dist/irdevices/cameras.d.ts +3 -3
  62. package/dist/irdevices/cameras.d.ts.map +1 -1
  63. package/dist/irdevices/cameras.js +19 -26
  64. package/dist/irdevices/cameras.js.map +1 -1
  65. package/dist/irdevices/fans.d.ts +3 -3
  66. package/dist/irdevices/fans.d.ts.map +1 -1
  67. package/dist/irdevices/fans.js +35 -44
  68. package/dist/irdevices/fans.js.map +1 -1
  69. package/dist/irdevices/lights.d.ts +3 -3
  70. package/dist/irdevices/lights.d.ts.map +1 -1
  71. package/dist/irdevices/lights.js +25 -32
  72. package/dist/irdevices/lights.js.map +1 -1
  73. package/dist/irdevices/others.d.ts +3 -3
  74. package/dist/irdevices/others.d.ts.map +1 -1
  75. package/dist/irdevices/others.js +21 -29
  76. package/dist/irdevices/others.js.map +1 -1
  77. package/dist/irdevices/tvs.d.ts +3 -3
  78. package/dist/irdevices/tvs.d.ts.map +1 -1
  79. package/dist/irdevices/tvs.js +66 -89
  80. package/dist/irdevices/tvs.js.map +1 -1
  81. package/dist/irdevices/vacuumcleaners.d.ts +3 -3
  82. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  83. package/dist/irdevices/vacuumcleaners.js +18 -24
  84. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  85. package/dist/irdevices/waterheaters.d.ts +3 -3
  86. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  87. package/dist/irdevices/waterheaters.js +19 -26
  88. package/dist/irdevices/waterheaters.js.map +1 -1
  89. package/dist/platform.d.ts +10 -10
  90. package/dist/platform.d.ts.map +1 -1
  91. package/dist/platform.js +163 -233
  92. package/dist/platform.js.map +1 -1
  93. package/dist/settings.d.ts +3 -1
  94. package/dist/settings.d.ts.map +1 -1
  95. package/dist/settings.js +4 -4
  96. package/dist/settings.js.map +1 -1
  97. package/homebridge-ui/public/index.html +231 -245
  98. package/homebridge-ui/server.js +2 -4
  99. package/nodemon.json +2 -4
  100. package/package.json +17 -12
  101. package/src/devices/bots.ts +411 -854
  102. package/src/devices/colorbulb.ts +187 -408
  103. package/src/devices/contact.ts +210 -376
  104. package/src/devices/curtains.ts +288 -563
  105. package/src/devices/humidifiers.ts +291 -537
  106. package/src/devices/meters.ts +189 -331
  107. package/src/devices/motion.ts +188 -322
  108. package/src/devices/plugs.ts +88 -160
  109. package/src/index.ts +5 -5
  110. package/src/irdevices/airconditioners.ts +139 -318
  111. package/src/irdevices/airpurifiers.ts +71 -170
  112. package/src/irdevices/cameras.ts +44 -103
  113. package/src/irdevices/fans.ts +70 -165
  114. package/src/irdevices/lights.ts +49 -104
  115. package/src/irdevices/others.ts +55 -131
  116. package/src/irdevices/tvs.ts +114 -247
  117. package/src/irdevices/vacuumcleaners.ts +44 -104
  118. package/src/irdevices/waterheaters.ts +49 -121
  119. package/src/platform.ts +341 -753
  120. package/src/settings.ts +8 -11
  121. package/tsconfig.json +5 -14
  122. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
@@ -1,28 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  exports.Curtain = void 0;
23
- const rxjs = __importStar(require("rxjs"));
24
- const operators = __importStar(require("rxjs/operators"));
25
- const settings = __importStar(require("../settings"));
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const settings_1 = require("../settings");
26
7
  class Curtain {
27
8
  constructor(platform, accessory, device) {
28
9
  this.platform = platform;
@@ -38,7 +19,7 @@ class Curtain {
38
19
  this.TargetPosition = 0;
39
20
  this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
40
21
  // this is subject we use to track when we need to POST changes to the SwitchBot API
41
- this.doCurtainUpdate = new rxjs.Subject();
22
+ this.doCurtainUpdate = new rxjs_1.Subject();
42
23
  this.curtainUpdateInProgress = false;
43
24
  this.setNewTarget = false;
44
25
  // Retrieve initial values and updateHomekit
@@ -46,14 +27,12 @@ class Curtain {
46
27
  // set accessory information
47
28
  accessory
48
29
  .getService(this.platform.Service.AccessoryInformation)
49
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
50
- .setCharacteristic(this.platform.Characteristic.Model, "SWITCHBOT-CURTAIN-W0701600")
30
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
31
+ .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-CURTAIN-W0701600')
51
32
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
52
33
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
53
34
  // you can create multiple services for each accessory
54
- (this.service =
55
- accessory.getService(this.platform.Service.WindowCovering) ||
56
- accessory.addService(this.platform.Service.WindowCovering)),
35
+ (this.service = accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
57
36
  `${device.deviceName} ${device.deviceType}`;
58
37
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
59
38
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -92,8 +71,7 @@ class Curtain {
92
71
  else if (!this.lightSensorService) {
93
72
  this.debugLog(`Curtain: ${accessory.displayName} Add Light Sensor Service`);
94
73
  (this.lightSensorService =
95
- this.accessory.getService(this.platform.Service.LightSensor) ||
96
- this.accessory.addService(this.platform.Service.LightSensor)),
74
+ this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
97
75
  `${accessory.displayName} Light Sensor`;
98
76
  this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
99
77
  }
@@ -108,9 +86,7 @@ class Curtain {
108
86
  }
109
87
  else if (device.ble && !this.batteryService) {
110
88
  this.debugLog(`Curtain: ${accessory.displayName} Add Battery Service`);
111
- (this.batteryService =
112
- this.accessory.getService(this.platform.Service.Battery) ||
113
- this.accessory.addService(this.platform.Service.Battery)),
89
+ (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
114
90
  `${accessory.displayName} Battery`;
115
91
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
116
92
  }
@@ -120,19 +96,16 @@ class Curtain {
120
96
  // Update Homekit
121
97
  this.updateHomeKitCharacteristics();
122
98
  // Start an update interval
123
- rxjs
124
- .interval(this.deviceRefreshRate * 1000)
125
- .pipe(operators.skipWhile(() => this.curtainUpdateInProgress))
99
+ (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
100
+ .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
126
101
  .subscribe(() => {
127
102
  this.refreshStatus();
128
103
  });
129
104
  // update slide progress
130
- rxjs
131
- .interval(this.updateRate * 1000)
132
- .pipe(operators.skipWhile(() => this.curtainUpdateInProgress))
105
+ (0, rxjs_1.interval)(this.updateRate * 1000)
106
+ .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
133
107
  .subscribe(() => {
134
- if (this.PositionState ===
135
- this.platform.Characteristic.PositionState.STOPPED) {
108
+ if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
136
109
  return;
137
110
  }
138
111
  this.debugLog(`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
@@ -141,18 +114,20 @@ class Curtain {
141
114
  // Watch for Curtain change events
142
115
  // We put in a debounce of 100ms so we don't make duplicate calls
143
116
  this.doCurtainUpdate
144
- .pipe(operators.tap(() => {
117
+ .pipe((0, operators_1.tap)(() => {
145
118
  this.curtainUpdateInProgress = true;
146
- }), operators.debounceTime(this.platform.config.options.pushRate * 1000))
119
+ }), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
147
120
  .subscribe(async () => {
148
121
  try {
149
122
  await this.pushChanges();
150
123
  }
151
124
  catch (e) {
152
125
  this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges`);
153
- if (this.deviceLogging.includes("debug")) {
154
- this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,` +
155
- ` Error Message: ${JSON.stringify(e.message)}`);
126
+ if (this.deviceLogging === 'debug') {
127
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
128
+ }
129
+ if (this.platform.debugMode) {
130
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
156
131
  }
157
132
  this.apiError(e);
158
133
  }
@@ -183,13 +158,11 @@ class Curtain {
183
158
  this.setMinMax();
184
159
  if (this.TargetPosition > this.CurrentPosition) {
185
160
  this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
186
- this.PositionState =
187
- this.platform.Characteristic.PositionState.INCREASING;
161
+ this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
188
162
  }
189
163
  else if (this.TargetPosition < this.CurrentPosition) {
190
164
  this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
191
- this.PositionState =
192
- this.platform.Characteristic.PositionState.DECREASING;
165
+ this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
193
166
  }
194
167
  else {
195
168
  this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
@@ -218,44 +191,36 @@ class Curtain {
218
191
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
219
192
  break;
220
193
  case 2:
221
- this.CurrentAmbientLightLevel =
222
- (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
194
+ this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
223
195
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
224
196
  ` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`);
225
197
  break;
226
198
  case 3:
227
- this.CurrentAmbientLightLevel =
228
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
199
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
229
200
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
230
201
  break;
231
202
  case 4:
232
- this.CurrentAmbientLightLevel =
233
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
203
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
234
204
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
235
205
  break;
236
206
  case 5:
237
- this.CurrentAmbientLightLevel =
238
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
207
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
239
208
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
240
209
  break;
241
210
  case 6:
242
- this.CurrentAmbientLightLevel =
243
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
211
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
244
212
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
245
213
  break;
246
214
  case 7:
247
- this.CurrentAmbientLightLevel =
248
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
215
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
249
216
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
250
217
  break;
251
218
  case 8:
252
- this.CurrentAmbientLightLevel =
253
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
219
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
254
220
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
255
221
  break;
256
222
  case 9:
257
- this.CurrentAmbientLightLevel =
258
- ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
223
+ this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
259
224
  this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel}`);
260
225
  break;
261
226
  case 10:
@@ -263,18 +228,15 @@ class Curtain {
263
228
  this.CurrentAmbientLightLevel = this.set_maxLux;
264
229
  this.debugLog();
265
230
  }
266
- this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
267
- ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
231
+ this.debugLog(`Curtain: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
268
232
  }
269
233
  // Battery
270
234
  this.BatteryLevel = Number(this.battery);
271
235
  if (this.BatteryLevel < 10) {
272
- this.StatusLowBattery =
273
- this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
236
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
274
237
  }
275
238
  else {
276
- this.StatusLowBattery =
277
- this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
239
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
278
240
  }
279
241
  this.debugLog(`Curtain: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
280
242
  }
@@ -295,18 +257,15 @@ class Curtain {
295
257
  this.setMinMax();
296
258
  if (this.TargetPosition > this.CurrentPosition) {
297
259
  this.debugLog(`Curtain: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
298
- this.PositionState =
299
- this.platform.Characteristic.PositionState.INCREASING;
260
+ this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
300
261
  }
301
262
  else if (this.TargetPosition < this.CurrentPosition) {
302
263
  this.debugLog(`Curtain: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
303
- this.PositionState =
304
- this.platform.Characteristic.PositionState.DECREASING;
264
+ this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
305
265
  }
306
266
  else {
307
267
  this.debugLog(`Curtain: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
308
- this.PositionState =
309
- this.platform.Characteristic.PositionState.STOPPED;
268
+ this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
310
269
  }
311
270
  }
312
271
  else {
@@ -314,8 +273,7 @@ class Curtain {
314
273
  if (!this.setNewTarget) {
315
274
  /*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/
316
275
  this.TargetPosition = this.CurrentPosition;
317
- this.PositionState =
318
- this.platform.Characteristic.PositionState.STOPPED;
276
+ this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
319
277
  this.debugLog(`Curtain: ${this.accessory.displayName} Stopped`);
320
278
  }
321
279
  }
@@ -326,10 +284,10 @@ class Curtain {
326
284
  this.set_maxLux = this.maxLux();
327
285
  // Brightness
328
286
  switch (this.brightness) {
329
- case "dim":
287
+ case 'dim':
330
288
  this.CurrentAmbientLightLevel = this.set_minLux;
331
289
  break;
332
- case "bright":
290
+ case 'bright':
333
291
  default:
334
292
  this.CurrentAmbientLightLevel = this.set_maxLux;
335
293
  }
@@ -351,74 +309,88 @@ class Curtain {
351
309
  // Convert to BLE Address
352
310
  this.device.bleMac = this.device
353
311
  .deviceId.match(/.{1,2}/g)
354
- .join(":")
312
+ .join(':')
355
313
  .toLowerCase();
356
314
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
357
- try {
358
- await switchbot.discover({
359
- model: "c",
360
- quick: false,
361
- });
362
- // Start to monitor advertisement packets
363
- await switchbot.startScan({
364
- model: "c",
315
+ // Start to monitor advertisement packets
316
+ if (switchbot !== false) {
317
+ switchbot
318
+ .startScan({
319
+ model: 'c',
365
320
  id: this.device.bleMac,
366
- });
367
- // Set an event hander
368
- switchbot.onadvertisement = (ad) => {
369
- this.serviceData = ad.serviceData;
370
- this.calibration = ad.serviceData.calibration;
371
- this.battery = ad.serviceData.battery;
372
- this.position = ad.serviceData.position;
373
- this.lightLevel = ad.serviceData.lightLevel;
374
- this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
375
- this.debugLog(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
376
- `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
377
- if (this.serviceData) {
378
- this.connected = true;
379
- this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
321
+ })
322
+ .then(() => {
323
+ // Set an event hander
324
+ switchbot.onadvertisement = (ad) => {
325
+ this.serviceData = ad.serviceData;
326
+ this.calibration = ad.serviceData.calibration;
327
+ this.battery = ad.serviceData.battery;
328
+ this.position = ad.serviceData.position;
329
+ this.lightLevel = ad.serviceData.lightLevel;
330
+ this.debugLog(`Curtain: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
331
+ this.debugLog(`Curtain: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
332
+ `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
333
+ if (this.serviceData) {
334
+ this.connected = true;
335
+ this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
336
+ }
337
+ else {
338
+ this.connected = false;
339
+ this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
340
+ }
341
+ };
342
+ // Wait 2 seconds
343
+ return switchbot.wait(this.scanDuration * 1000);
344
+ })
345
+ .then(async () => {
346
+ // Stop to monitor
347
+ switchbot.stopScan();
348
+ if (this.connected) {
349
+ this.parseStatus();
350
+ this.updateHomeKitCharacteristics();
380
351
  }
381
352
  else {
382
- this.connected = false;
383
- this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`);
353
+ this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
354
+ if (this.platform.config.credentials?.openToken) {
355
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
356
+ this.SwitchToOpenAPI = true;
357
+ await this.openAPIRefreshStatus();
358
+ }
359
+ }
360
+ })
361
+ .catch(async (e) => {
362
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
363
+ if (this.deviceLogging === 'debug') {
364
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
365
+ }
366
+ if (this.platform.debugMode) {
367
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
384
368
  }
385
- };
386
- // Wait 10 seconds
387
- await switchbot.wait(this.scanDuration * 1000);
388
- // Stop to monitor
389
- switchbot.stopScan();
390
- if (this.connected) {
391
- this.parseStatus();
392
- this.updateHomeKitCharacteristics();
393
- }
394
- else {
395
- this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
396
369
  if (this.platform.config.credentials?.openToken) {
397
370
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
398
371
  this.SwitchToOpenAPI = true;
399
372
  await this.openAPIRefreshStatus();
400
373
  }
401
- }
374
+ this.apiError(e);
375
+ });
402
376
  }
403
- catch (e) {
404
- this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
405
- if (this.deviceLogging.includes("debug")) {
406
- this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
407
- ` Error Message: ${JSON.stringify(e.message)}`);
408
- }
409
- if (this.platform.config.credentials?.openToken) {
410
- this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
411
- this.SwitchToOpenAPI = true;
412
- await this.openAPIRefreshStatus();
413
- }
414
- this.apiError(e);
377
+ else {
378
+ await this.BLEconnection(switchbot);
379
+ }
380
+ }
381
+ async BLEconnection(switchbot) {
382
+ this.errorLog(`Curtain: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
383
+ if (this.platform.config.credentials?.openToken) {
384
+ this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
385
+ this.SwitchToOpenAPI = true;
386
+ await this.openAPIRefreshStatus();
415
387
  }
416
388
  }
417
389
  async openAPIRefreshStatus() {
418
390
  if (this.platform.config.credentials?.openToken) {
419
391
  this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI refreshStatus`);
420
392
  try {
421
- this.deviceStatus = (await this.platform.axios.get(`${settings.DeviceURL}/${this.device.deviceId}/status`)).data;
393
+ this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
422
394
  this.debugLog(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
423
395
  this.slidePosition = this.deviceStatus.body.slidePosition;
424
396
  this.moving = this.deviceStatus.body.moving;
@@ -428,9 +400,11 @@ class Curtain {
428
400
  }
429
401
  catch (e) {
430
402
  this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
431
- if (this.deviceLogging.includes("debug")) {
432
- this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
433
- ` Error Message: ${JSON.stringify(e.message)}`);
403
+ if (this.deviceLogging === 'debug') {
404
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
405
+ }
406
+ if (this.platform.debugMode) {
407
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
434
408
  }
435
409
  this.apiError(e);
436
410
  }
@@ -443,10 +417,9 @@ class Curtain {
443
417
  else {
444
418
  await this.openAPIpushChanges();
445
419
  }
446
- rxjs
447
- .interval(5000)
448
- .pipe(operators.skipWhile(() => this.curtainUpdateInProgress))
449
- .pipe(operators.take(1))
420
+ (0, rxjs_1.interval)(5000)
421
+ .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
422
+ .pipe((0, operators_1.take)(1))
450
423
  .subscribe(() => {
451
424
  this.refreshStatus();
452
425
  });
@@ -458,12 +431,12 @@ class Curtain {
458
431
  // Convert to BLE Address
459
432
  this.device.bleMac = this.device
460
433
  .deviceId.match(/.{1,2}/g)
461
- .join(":")
434
+ .join(':')
462
435
  .toLowerCase();
463
436
  this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
464
437
  if (switchbot !== false) {
465
438
  switchbot
466
- .discover({ model: "c", quick: true, id: this.device.bleMac })
439
+ .discover({ model: 'c', quick: true, id: this.device.bleMac })
467
440
  .then((device_list) => {
468
441
  this.infoLog(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
469
442
  return device_list[0].runToPos(100 - Number(this.TargetPosition));
@@ -473,9 +446,11 @@ class Curtain {
473
446
  })
474
447
  .catch(async (e) => {
475
448
  this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
476
- if (this.deviceLogging.includes("debug")) {
477
- this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
478
- ` Error Message: ${JSON.stringify(e.message)}`);
449
+ if (this.deviceLogging === 'debug') {
450
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
451
+ }
452
+ if (this.platform.debugMode) {
453
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
479
454
  }
480
455
  if (this.platform.config.credentials?.openToken) {
481
456
  this.warnLog(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -505,14 +480,14 @@ class Curtain {
505
480
  this.debugLog(`Pushing ${this.TargetPosition}`);
506
481
  const adjustedTargetPosition = 100 - Number(this.TargetPosition);
507
482
  const payload = {
508
- commandType: "command",
509
- command: "setPosition",
483
+ commandType: 'command',
484
+ command: 'setPosition',
510
485
  parameter: `0,ff,${adjustedTargetPosition}`,
511
486
  };
512
487
  this.infoLog(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
513
488
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
514
489
  // Make the API request
515
- const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
490
+ const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
516
491
  this.debugLog(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
517
492
  this.statusCode(push);
518
493
  }
@@ -523,9 +498,11 @@ class Curtain {
523
498
  }
524
499
  catch (e) {
525
500
  this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
526
- if (this.deviceLogging.includes("debug")) {
527
- this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
528
- ` Error Message: ${JSON.stringify(e.message)}`);
501
+ if (this.deviceLogging === 'debug') {
502
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
503
+ }
504
+ if (this.platform.debugMode) {
505
+ this.errorLog(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
529
506
  }
530
507
  this.apiError(e);
531
508
  }
@@ -533,8 +510,7 @@ class Curtain {
533
510
  }
534
511
  updateHomeKitCharacteristics() {
535
512
  this.setMinMax();
536
- if (this.CurrentPosition === undefined ||
537
- Number.isNaN(this.CurrentPosition)) {
513
+ if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
538
514
  this.debugLog(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`);
539
515
  }
540
516
  else {
@@ -547,8 +523,7 @@ class Curtain {
547
523
  else {
548
524
  this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
549
525
  }
550
- if (this.TargetPosition === undefined ||
551
- Number.isNaN(this.TargetPosition)) {
526
+ if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
552
527
  this.debugLog(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`);
553
528
  }
554
529
  else {
@@ -556,14 +531,12 @@ class Curtain {
556
531
  this.debugLog(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
557
532
  }
558
533
  if (!this.device.curtain?.hide_lightsensor) {
559
- if (this.CurrentAmbientLightLevel === undefined ||
560
- Number.isNaN(this.CurrentAmbientLightLevel)) {
534
+ if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
561
535
  this.debugLog(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
562
536
  }
563
537
  else {
564
538
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
565
- this.debugLog(`Curtain: ${this.accessory.displayName}` +
566
- ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
539
+ this.debugLog(`Curtain: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
567
540
  }
568
541
  }
569
542
  if (this.device.ble) {
@@ -632,14 +605,12 @@ class Curtain {
632
605
  this.TargetPosition = value;
633
606
  this.setMinMax();
634
607
  if (value > this.CurrentPosition) {
635
- this.PositionState =
636
- this.platform.Characteristic.PositionState.INCREASING;
608
+ this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
637
609
  this.setNewTarget = true;
638
610
  this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
639
611
  }
640
612
  else if (value < this.CurrentPosition) {
641
- this.PositionState =
642
- this.platform.Characteristic.PositionState.DECREASING;
613
+ this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
643
614
  this.setNewTarget = true;
644
615
  this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
645
616
  }
@@ -649,9 +620,7 @@ class Curtain {
649
620
  this.debugLog(`Curtain: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
650
621
  }
651
622
  this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
652
- this.service
653
- .getCharacteristic(this.platform.Characteristic.PositionState)
654
- .updateValue(this.PositionState);
623
+ this.service.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
655
624
  /**
656
625
  * If Curtain movement time is short, the moving flag from backend is always false.
657
626
  * The minimum time depends on the network control latency.
@@ -683,16 +652,16 @@ class Curtain {
683
652
  config = device.curtain;
684
653
  }
685
654
  if (device.ble) {
686
- config["ble"] = device.ble;
655
+ config['ble'] = device.ble;
687
656
  }
688
657
  if (device.logging !== undefined) {
689
- config["logging"] = device.logging;
658
+ config['logging'] = device.logging;
690
659
  }
691
660
  if (device.refreshRate !== undefined) {
692
- config["refreshRate"] = device.refreshRate;
661
+ config['refreshRate'] = device.refreshRate;
693
662
  }
694
663
  if (device.scanDuration !== undefined) {
695
- config["scanDuration"] = device.scanDuration;
664
+ config['scanDuration'] = device.scanDuration;
696
665
  }
697
666
  if (Object.entries(config).length !== 0) {
698
667
  this.warnLog(`Curtain: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
@@ -701,13 +670,11 @@ class Curtain {
701
670
  refreshRate(device) {
702
671
  // refreshRate
703
672
  if (device.refreshRate) {
704
- this.deviceRefreshRate = this.accessory.context.refreshRate =
705
- device.refreshRate;
673
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
706
674
  this.debugLog(`Curtain: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
707
675
  }
708
676
  else if (this.platform.config.options.refreshRate) {
709
- this.deviceRefreshRate = this.accessory.context.refreshRate =
710
- this.platform.config.options.refreshRate;
677
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
711
678
  this.debugLog(`Curtain: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
712
679
  }
713
680
  // updateRate
@@ -722,8 +689,7 @@ class Curtain {
722
689
  }
723
690
  scan(device) {
724
691
  if (device.scanDuration) {
725
- this.scanDuration = this.accessory.context.scanDuration =
726
- device.scanDuration;
692
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
727
693
  if (device.ble) {
728
694
  this.debugLog(`Curtain: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
729
695
  }
@@ -737,7 +703,7 @@ class Curtain {
737
703
  }
738
704
  logs(device) {
739
705
  if (this.platform.debugMode) {
740
- this.deviceLogging = this.accessory.context.logging = "debugMode";
706
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
741
707
  this.debugLog(`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
742
708
  }
743
709
  else if (device.logging) {
@@ -745,12 +711,11 @@ class Curtain {
745
711
  this.debugLog(`Curtain: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
746
712
  }
747
713
  else if (this.platform.config.options?.logging) {
748
- this.deviceLogging = this.accessory.context.logging =
749
- this.platform.config.options?.logging;
714
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
750
715
  this.debugLog(`Curtain: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
751
716
  }
752
717
  else {
753
- this.deviceLogging = this.accessory.context.logging = "standard";
718
+ this.deviceLogging = this.accessory.context.logging = 'standard';
754
719
  this.debugLog(`Curtain: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
755
720
  }
756
721
  }
@@ -801,8 +766,8 @@ class Curtain {
801
766
  }
802
767
  debugLog(...log) {
803
768
  if (this.enablingDeviceLogging()) {
804
- if (this.deviceLogging === "debug") {
805
- this.platform.log.info("[DEBUG]", String(...log));
769
+ if (this.deviceLogging === 'debug') {
770
+ this.platform.log.info('[DEBUG]', String(...log));
806
771
  }
807
772
  else {
808
773
  this.platform.log.debug(String(...log));
@@ -810,7 +775,7 @@ class Curtain {
810
775
  }
811
776
  }
812
777
  enablingDeviceLogging() {
813
- return (this.deviceLogging.includes("debug") || this.deviceLogging === "standard");
778
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
814
779
  }
815
780
  }
816
781
  exports.Curtain = Curtain;