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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/device/blindtilt.d.ts +3 -1
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +38 -24
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -0
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +30 -24
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +1 -0
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +30 -24
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +1 -0
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +30 -24
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +1 -0
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +30 -24
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +2 -0
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +51 -39
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/fan.d.ts +1 -0
  26. package/dist/device/fan.d.ts.map +1 -1
  27. package/dist/device/fan.js +30 -24
  28. package/dist/device/fan.js.map +1 -1
  29. package/dist/device/hub.d.ts +1 -0
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +30 -24
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts +1 -0
  34. package/dist/device/humidifier.d.ts.map +1 -1
  35. package/dist/device/humidifier.js +30 -24
  36. package/dist/device/humidifier.js.map +1 -1
  37. package/dist/device/iosensor.d.ts +1 -0
  38. package/dist/device/iosensor.d.ts.map +1 -1
  39. package/dist/device/iosensor.js +30 -24
  40. package/dist/device/iosensor.js.map +1 -1
  41. package/dist/device/lightstrip.d.ts +1 -0
  42. package/dist/device/lightstrip.d.ts.map +1 -1
  43. package/dist/device/lightstrip.js +30 -24
  44. package/dist/device/lightstrip.js.map +1 -1
  45. package/dist/device/lock.d.ts +1 -0
  46. package/dist/device/lock.d.ts.map +1 -1
  47. package/dist/device/lock.js +31 -25
  48. package/dist/device/lock.js.map +1 -1
  49. package/dist/device/meter.d.ts +1 -0
  50. package/dist/device/meter.d.ts.map +1 -1
  51. package/dist/device/meter.js +30 -24
  52. package/dist/device/meter.js.map +1 -1
  53. package/dist/device/meterplus.d.ts +1 -0
  54. package/dist/device/meterplus.d.ts.map +1 -1
  55. package/dist/device/meterplus.js +30 -24
  56. package/dist/device/meterplus.js.map +1 -1
  57. package/dist/device/motion.d.ts +1 -0
  58. package/dist/device/motion.d.ts.map +1 -1
  59. package/dist/device/motion.js +30 -24
  60. package/dist/device/motion.js.map +1 -1
  61. package/dist/device/plug.d.ts +1 -0
  62. package/dist/device/plug.d.ts.map +1 -1
  63. package/dist/device/plug.js +31 -25
  64. package/dist/device/plug.js.map +1 -1
  65. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  66. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  67. package/dist/device/robotvacuumcleaner.js +30 -24
  68. package/dist/device/robotvacuumcleaner.js.map +1 -1
  69. package/dist/device/waterdetector.d.ts +1 -0
  70. package/dist/device/waterdetector.d.ts.map +1 -1
  71. package/dist/device/waterdetector.js +30 -24
  72. package/dist/device/waterdetector.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/device/blindtilt.ts +39 -23
  75. package/src/device/bot.ts +30 -22
  76. package/src/device/ceilinglight.ts +31 -23
  77. package/src/device/colorbulb.ts +30 -22
  78. package/src/device/contact.ts +30 -22
  79. package/src/device/curtain.ts +50 -36
  80. package/src/device/fan.ts +30 -22
  81. package/src/device/hub.ts +30 -22
  82. package/src/device/humidifier.ts +30 -22
  83. package/src/device/iosensor.ts +30 -22
  84. package/src/device/lightstrip.ts +30 -22
  85. package/src/device/lock.ts +31 -23
  86. package/src/device/meter.ts +30 -22
  87. package/src/device/meterplus.ts +30 -22
  88. package/src/device/motion.ts +30 -22
  89. package/src/device/plug.ts +31 -23
  90. package/src/device/robotvacuumcleaner.ts +30 -22
  91. package/src/device/waterdetector.ts +30 -22
@@ -164,10 +164,14 @@ export class CeilingLight extends deviceBase {
164
164
  this.debugLog('Retrieve initial values and update Homekit');
165
165
  this.refreshStatus();
166
166
 
167
- //regisiter webhook event handler
167
+ //regisiter webhook event handler if enabled
168
168
  this.debugLog('Registering Webhook Event Handler');
169
169
  this.registerWebhook();
170
170
 
171
+ //regisiter platform BLE event handler if enabled
172
+ this.debugLog('Registering Platform BLE Event Handler');
173
+ this.registerPlatformBLE();
174
+
171
175
  // Start an update interval
172
176
  interval(this.deviceRefreshRate * 1000)
173
177
  .pipe(skipWhile(() => this.ceilingLightUpdateInProgress))
@@ -275,7 +279,7 @@ export class CeilingLight extends deviceBase {
275
279
  async refreshStatus(): Promise<void> {
276
280
  if (!this.device.enableCloudService && this.OpenAPI) {
277
281
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
278
- } else if (this.BLE || this.config.options?.BLE) {
282
+ } else if (this.BLE) {
279
283
  await this.BLERefreshStatus();
280
284
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
281
285
  await this.openAPIRefreshStatus();
@@ -287,11 +291,34 @@ export class CeilingLight extends deviceBase {
287
291
 
288
292
  async BLERefreshStatus(): Promise<void> {
289
293
  await this.debugLog('BLERefreshStatus');
294
+ const switchbot = await this.switchbotBLE();
295
+ if (switchbot === undefined) {
296
+ await this.BLERefreshConnection(switchbot);
297
+ } else {
298
+ (async () => {
299
+ // Start to monitor advertisement packets
300
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData;
301
+ // Update HomeKit
302
+ if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
303
+ && serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
304
+ this.serviceData = serviceData;
305
+ await this.BLEparseStatus();
306
+ await this.updateHomeKitCharacteristics();
307
+ } else {
308
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
309
+ await this.BLERefreshConnection(switchbot);
310
+ }
311
+ })();
312
+ }
313
+ }
314
+
315
+ async registerPlatformBLE(): Promise<void> {
316
+ await this.debugLog('registerPlatformBLE');
290
317
  if (this.config.options?.BLE) {
291
318
  await this.debugLog('is listening to Platform BLE.');
292
319
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
293
320
  await this.debugLog(`bleMac: ${this.device.bleMac}`);
294
- this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData) => {
321
+ this.platform.bleEventHandler[this.device.bleMac] = async (context: ceilingLightServiceData | ceilingLightProServiceData) => {
295
322
  try {
296
323
  await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
297
324
  this.serviceData = context;
@@ -302,26 +329,7 @@ export class CeilingLight extends deviceBase {
302
329
  }
303
330
  };
304
331
  } else {
305
- await this.debugLog('is using Device BLE Scanning.');
306
- const switchbot = await this.switchbotBLE();
307
- if (switchbot === undefined) {
308
- await this.BLERefreshConnection(switchbot);
309
- } else {
310
- (async () => {
311
- // Start to monitor advertisement packets
312
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as ceilingLightServiceData;
313
- // Update HomeKit
314
- if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
315
- && serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
316
- this.serviceData = serviceData;
317
- await this.BLEparseStatus();
318
- await this.updateHomeKitCharacteristics();
319
- } else {
320
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
321
- await this.BLERefreshConnection(switchbot);
322
- }
323
- })();
324
- }
332
+ await this.debugLog('is not listening to Platform BLE');
325
333
  }
326
334
  }
327
335
 
@@ -160,10 +160,14 @@ export class ColorBulb extends deviceBase {
160
160
  this.debugLog('Retrieve initial values and update Homekit');
161
161
  this.refreshStatus();
162
162
 
163
- //regisiter webhook event handler
163
+ //regisiter webhook event handler if enabled
164
164
  this.debugLog('Registering Webhook Event Handler');
165
165
  this.registerWebhook();
166
166
 
167
+ //regisiter platform BLE event handler if enabled
168
+ this.debugLog('Registering Platform BLE Event Handler');
169
+ this.registerPlatformBLE();
170
+
167
171
  // Start an update interval
168
172
  interval(this.deviceRefreshRate * 1000)
169
173
  .pipe(skipWhile(() => this.colorBulbUpdateInProgress))
@@ -296,7 +300,7 @@ export class ColorBulb extends deviceBase {
296
300
  async refreshStatus(): Promise<void> {
297
301
  if (!this.device.enableCloudService && this.OpenAPI) {
298
302
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
299
- } else if (this.BLE || this.config.options?.BLE) {
303
+ } else if (this.BLE) {
300
304
  await this.BLERefreshStatus();
301
305
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
302
306
  await this.openAPIRefreshStatus();
@@ -308,6 +312,29 @@ export class ColorBulb extends deviceBase {
308
312
 
309
313
  async BLERefreshStatus(): Promise<void> {
310
314
  await this.debugLog('BLERefreshStatus');
315
+ const switchbot = await this.switchbotBLE();
316
+ if (switchbot === undefined) {
317
+ await this.BLERefreshConnection(switchbot);
318
+ } else {
319
+ // Start to monitor advertisement packets
320
+ (async () => {
321
+ // Start to monitor advertisement packets
322
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData;
323
+ // Update HomeKit
324
+ if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
325
+ this.serviceData = serviceData;
326
+ await this.BLEparseStatus();
327
+ await this.updateHomeKitCharacteristics();
328
+ } else {
329
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
330
+ await this.BLERefreshConnection(switchbot);
331
+ }
332
+ })();
333
+ }
334
+ }
335
+
336
+ async registerPlatformBLE(): Promise<void> {
337
+ await this.debugLog('registerPlatformBLE');
311
338
  if (this.config.options?.BLE) {
312
339
  await this.debugLog('is listening to Platform BLE.');
313
340
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -323,26 +350,7 @@ export class ColorBulb extends deviceBase {
323
350
  }
324
351
  };
325
352
  } else {
326
- await this.debugLog('is using Device BLE Scanning.');
327
- const switchbot = await this.switchbotBLE();
328
- if (switchbot === undefined) {
329
- await this.BLERefreshConnection(switchbot);
330
- } else {
331
- // Start to monitor advertisement packets
332
- (async () => {
333
- // Start to monitor advertisement packets
334
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData;
335
- // Update HomeKit
336
- if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
337
- this.serviceData = serviceData;
338
- await this.BLEparseStatus();
339
- await this.updateHomeKitCharacteristics();
340
- } else {
341
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
342
- await this.BLERefreshConnection(switchbot);
343
- }
344
- })();
345
- }
353
+ await this.debugLog('is not listening to Platform BLE');
346
354
  }
347
355
  }
348
356
 
@@ -172,10 +172,14 @@ export class Contact extends deviceBase {
172
172
  this.debugLog('Retrieve initial values and update Homekit');
173
173
  this.refreshStatus();
174
174
 
175
- //regisiter webhook event handler
175
+ //regisiter webhook event handler if enabled
176
176
  this.debugLog('Registering Webhook Event Handler');
177
177
  this.registerWebhook();
178
178
 
179
+ //regisiter platform BLE event handler if enabled
180
+ this.debugLog('Registering Platform BLE Event Handler');
181
+ this.registerPlatformBLE();
182
+
179
183
  // Start an update interval
180
184
  interval(this.deviceRefreshRate * 1000)
181
185
  .pipe(skipWhile(() => this.contactUpdateInProgress))
@@ -284,7 +288,7 @@ export class Contact extends deviceBase {
284
288
  async refreshStatus(): Promise<void> {
285
289
  if (!this.device.enableCloudService && this.OpenAPI) {
286
290
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
287
- } else if (this.BLE || this.config.options?.BLE) {
291
+ } else if (this.BLE) {
288
292
  await this.BLERefreshStatus();
289
293
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
290
294
  await this.openAPIRefreshStatus();
@@ -296,6 +300,29 @@ export class Contact extends deviceBase {
296
300
 
297
301
  async BLERefreshStatus(): Promise<void> {
298
302
  await this.debugLog('BLERefreshStatus');
303
+ const switchbot = await this.switchbotBLE();
304
+ if (switchbot === undefined) {
305
+ await this.BLERefreshConnection(switchbot);
306
+ } else {
307
+ // Start to monitor advertisement packets
308
+ (async () => {
309
+ // Start to monitor advertisement packets
310
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as contactSensorServiceData;
311
+ // Update HomeKit
312
+ if (serviceData.model === SwitchBotBLEModel.ContactSensor && serviceData.modelName === SwitchBotBLEModelName.ContactSensor) {
313
+ this.serviceData = serviceData;
314
+ await this.BLEparseStatus();
315
+ await this.updateHomeKitCharacteristics();
316
+ } else {
317
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
318
+ await this.BLERefreshConnection(switchbot);
319
+ }
320
+ })();
321
+ }
322
+ }
323
+
324
+ async registerPlatformBLE(): Promise<void> {
325
+ await this.debugLog('registerPlatformBLE');
299
326
  if (this.config.options?.BLE) {
300
327
  await this.debugLog('is listening to Platform BLE.');
301
328
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -311,26 +338,7 @@ export class Contact extends deviceBase {
311
338
  }
312
339
  };
313
340
  } else {
314
- await this.debugLog('is using Device BLE Scanning.');
315
- const switchbot = await this.switchbotBLE();
316
- if (switchbot === undefined) {
317
- await this.BLERefreshConnection(switchbot);
318
- } else {
319
- // Start to monitor advertisement packets
320
- (async () => {
321
- // Start to monitor advertisement packets
322
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as contactSensorServiceData;
323
- // Update HomeKit
324
- if (serviceData.model === SwitchBotBLEModel.ContactSensor && serviceData.modelName === SwitchBotBLEModelName.ContactSensor) {
325
- this.serviceData = serviceData;
326
- await this.BLEparseStatus();
327
- await this.updateHomeKitCharacteristics();
328
- } else {
329
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
330
- await this.BLERefreshConnection(switchbot);
331
- }
332
- })();
333
- }
341
+ await this.debugLog('is not listening to Platform BLE');
334
342
  }
335
343
  }
336
344
 
@@ -54,6 +54,7 @@ export class Curtain extends deviceBase {
54
54
  setNewTargetTimer!: NodeJS.Timeout;
55
55
 
56
56
  // Updates
57
+ curtainMoving!: boolean;
57
58
  curtainUpdateInProgress!: boolean;
58
59
  doCurtainUpdate!: Subject<void>;
59
60
 
@@ -68,6 +69,7 @@ export class Curtain extends deviceBase {
68
69
 
69
70
  // this is subject we use to track when we need to POST changes to the SwitchBot API
70
71
  this.doCurtainUpdate = new Subject();
72
+ this.curtainMoving = false;
71
73
  this.curtainUpdateInProgress = false;
72
74
  this.setNewTarget = false;
73
75
 
@@ -189,10 +191,14 @@ export class Curtain extends deviceBase {
189
191
  this.debugLog('Retrieve initial values and update Homekit');
190
192
  this.refreshStatus();
191
193
 
192
- //regisiter webhook event handler
194
+ //regisiter webhook event handler if enabled
193
195
  this.debugLog('Registering Webhook Event Handler');
194
196
  this.registerWebhook();
195
197
 
198
+ //regisiter platform BLE event handler if enabled
199
+ this.debugLog('Registering Platform BLE Event Handler');
200
+ this.registerPlatformBLE();
201
+
196
202
  // History
197
203
  this.history();
198
204
 
@@ -205,7 +211,7 @@ export class Curtain extends deviceBase {
205
211
 
206
212
  // update slide progress
207
213
  interval(this.deviceUpdateRate * 1000)
208
- //.pipe(skipWhile(() => this.curtainUpdateInProgress))
214
+ .pipe(skipWhile(() => !this.curtainMoving))
209
215
  .subscribe(async () => {
210
216
  if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
211
217
  return;
@@ -340,6 +346,7 @@ export class Curtain extends deviceBase {
340
346
  await this.infoLog('Checking Status ...');
341
347
  }
342
348
  if (this.setNewTarget && this.deviceStatus.moving) {
349
+ this.curtainMoving = true;
343
350
  await this.setMinMax();
344
351
  if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
345
352
  await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
@@ -358,6 +365,7 @@ export class Curtain extends deviceBase {
358
365
  await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
359
366
  }
360
367
  } else {
368
+ this.curtainMoving = false;
361
369
  await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
362
370
  this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
363
371
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
@@ -425,7 +433,7 @@ export class Curtain extends deviceBase {
425
433
  async refreshStatus(): Promise<void> {
426
434
  if (!this.device.enableCloudService && this.OpenAPI) {
427
435
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
428
- } else if (this.BLE || this.config.options?.BLE) {
436
+ } else if (this.BLE) {
429
437
  await this.BLERefreshStatus();
430
438
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
431
439
  await this.openAPIRefreshStatus();
@@ -437,42 +445,25 @@ export class Curtain extends deviceBase {
437
445
 
438
446
  async BLERefreshStatus(): Promise<void> {
439
447
  await this.debugLog('BLERefreshStatus');
440
- if (this.config.options?.BLE) {
441
- await this.debugLog('is listening to Platform BLE.');
442
- this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
443
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
444
- this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
445
- try {
446
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
447
- this.serviceData = context;
448
- await this.BLEparseStatus();
449
- await this.updateHomeKitCharacteristics();
450
- } catch (e: any) {
451
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
452
- }
453
- };
448
+ const switchbot = await this.switchbotBLE();
449
+ if (switchbot === undefined) {
450
+ await this.BLERefreshConnection(switchbot);
454
451
  } else {
455
- await this.debugLog('is using Device BLE Scanning.');
456
- const switchbot = await this.switchbotBLE();
457
- if (switchbot === undefined) {
458
- await this.BLERefreshConnection(switchbot);
459
- } else {
452
+ // Start to monitor advertisement packets
453
+ (async () => {
460
454
  // Start to monitor advertisement packets
461
- (async () => {
462
- // Start to monitor advertisement packets
463
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as curtainServiceData | curtain3ServiceData;
464
- // Update HomeKit
465
- if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
455
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as curtainServiceData | curtain3ServiceData;
456
+ // Update HomeKit
457
+ if ((serviceData.model === SwitchBotBLEModel.Curtain || SwitchBotBLEModel.Curtain3)
466
458
  && (serviceData.modelName === SwitchBotBLEModelName.Curtain || SwitchBotBLEModelName.Curtain3)) {
467
- this.serviceData = serviceData;
468
- await this.BLEparseStatus();
469
- await this.updateHomeKitCharacteristics();
470
- } else {
471
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
472
- await this.BLERefreshConnection(switchbot);
473
- }
474
- })();
475
- }
459
+ this.serviceData = serviceData;
460
+ await this.BLEparseStatus();
461
+ await this.updateHomeKitCharacteristics();
462
+ } else {
463
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
464
+ await this.BLERefreshConnection(switchbot);
465
+ }
466
+ })();
476
467
  }
477
468
  }
478
469
 
@@ -515,6 +506,27 @@ export class Curtain extends deviceBase {
515
506
  }
516
507
  }
517
508
 
509
+ async registerPlatformBLE(): Promise<void> {
510
+ await this.debugLog('registerPlatformBLE');
511
+ if (this.config.options?.BLE) {
512
+ await this.debugLog('is listening to Platform BLE.');
513
+ this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
514
+ await this.debugLog(`bleMac: ${this.device.bleMac}`);
515
+ this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
516
+ try {
517
+ await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
518
+ this.serviceData = context;
519
+ await this.BLEparseStatus();
520
+ await this.updateHomeKitCharacteristics();
521
+ } catch (e: any) {
522
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
523
+ }
524
+ };
525
+ } else {
526
+ await this.debugLog('is not listening to Platform BLE');
527
+ }
528
+ }
529
+
518
530
  /**
519
531
  * Pushes the requested changes to the SwitchBot API
520
532
  */
@@ -761,6 +773,7 @@ export class Curtain extends deviceBase {
761
773
  await this.setMinMax();
762
774
  await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
763
775
  if (this.setNewTarget) {
776
+ this.curtainMoving = true;
764
777
  this.infoLog('Checking Status ...');
765
778
  await this.setMinMax();
766
779
  if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
@@ -780,6 +793,7 @@ export class Curtain extends deviceBase {
780
793
  await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
781
794
  }
782
795
  } else {
796
+ this.curtainMoving = false;
783
797
  await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
784
798
  this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
785
799
  this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
package/src/device/fan.ts CHANGED
@@ -164,10 +164,14 @@ export class Fan extends deviceBase {
164
164
  this.debugLog('Retrieve initial values and update Homekit');
165
165
  this.refreshStatus();
166
166
 
167
- //regisiter webhook event handler
167
+ //regisiter webhook event handler if enabled
168
168
  this.debugLog('Registering Webhook Event Handler');
169
169
  this.registerWebhook();
170
170
 
171
+ //regisiter platform BLE event handler if enabled
172
+ this.debugLog('Registering Platform BLE Event Handler');
173
+ this.registerPlatformBLE();
174
+
171
175
  // Start an update interval
172
176
  interval(this.deviceRefreshRate * 1000)
173
177
  .pipe(skipWhile(() => this.fanUpdateInProgress))
@@ -311,7 +315,7 @@ export class Fan extends deviceBase {
311
315
  async refreshStatus(): Promise<void> {
312
316
  if (!this.device.enableCloudService && this.OpenAPI) {
313
317
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
314
- } else if (this.BLE || this.config.options?.BLE) {
318
+ } else if (this.BLE) {
315
319
  await this.BLERefreshStatus();
316
320
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
317
321
  await this.openAPIRefreshStatus();
@@ -323,6 +327,29 @@ export class Fan extends deviceBase {
323
327
 
324
328
  async BLERefreshStatus(): Promise<void> {
325
329
  await this.debugLog('BLERefreshStatus');
330
+ const switchbot = await this.switchbotBLE();
331
+ if (switchbot === undefined) {
332
+ await this.BLERefreshConnection(switchbot);
333
+ } else {
334
+ // Start to monitor advertisement packets
335
+ (async () => {
336
+ // Start to monitor advertisement packets
337
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as batteryCirculatorFanServiceData;
338
+ // Update HomeKit
339
+ if (serviceData.model === SwitchBotBLEModel.Unknown && SwitchBotBLEModelName.Unknown) {
340
+ this.serviceData = serviceData;
341
+ await this.BLEparseStatus();
342
+ await this.updateHomeKitCharacteristics();
343
+ } else {
344
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
345
+ await this.BLERefreshConnection(switchbot);
346
+ }
347
+ })();
348
+ }
349
+ }
350
+
351
+ async registerPlatformBLE(): Promise<void> {
352
+ await this.debugLog('registerPlatformBLE');
326
353
  if (this.config.options?.BLE) {
327
354
  await this.debugLog('is listening to Platform BLE.');
328
355
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -338,26 +365,7 @@ export class Fan extends deviceBase {
338
365
  }
339
366
  };
340
367
  } else {
341
- await this.debugLog('is using Device BLE Scanning.');
342
- const switchbot = await this.switchbotBLE();
343
- if (switchbot === undefined) {
344
- await this.BLERefreshConnection(switchbot);
345
- } else {
346
- // Start to monitor advertisement packets
347
- (async () => {
348
- // Start to monitor advertisement packets
349
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as batteryCirculatorFanServiceData;
350
- // Update HomeKit
351
- if (serviceData.model === SwitchBotBLEModel.Unknown && SwitchBotBLEModelName.Unknown) {
352
- this.serviceData = serviceData;
353
- await this.BLEparseStatus();
354
- await this.updateHomeKitCharacteristics();
355
- } else {
356
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
357
- await this.BLERefreshConnection(switchbot);
358
- }
359
- })();
360
- }
368
+ await this.debugLog('is not listening to Platform BLE');
361
369
  }
362
370
  }
363
371
 
package/src/device/hub.ts CHANGED
@@ -154,10 +154,14 @@ export class Hub extends deviceBase {
154
154
  this.debugLog('Retrieve initial values and update Homekit');
155
155
  this.refreshStatus();
156
156
 
157
- //regisiter webhook event handler
157
+ //regisiter webhook event handler if enabled
158
158
  this.debugLog('Registering Webhook Event Handler');
159
159
  this.registerWebhook();
160
160
 
161
+ //regisiter platform BLE event handler if enabled
162
+ this.debugLog('Registering Platform BLE Event Handler');
163
+ this.registerPlatformBLE();
164
+
161
165
  // Start an update interval
162
166
  interval(this.deviceRefreshRate * 1000)
163
167
  .pipe(skipWhile(() => this.hubUpdateInProgress))
@@ -278,7 +282,7 @@ export class Hub extends deviceBase {
278
282
  async refreshStatus(): Promise<void> {
279
283
  if (!this.device.enableCloudService && this.OpenAPI) {
280
284
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
281
- } else if (this.BLE || this.config.options?.BLE) {
285
+ } else if (this.BLE) {
282
286
  await this.BLERefreshStatus();
283
287
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
284
288
  await this.openAPIRefreshStatus();
@@ -290,6 +294,29 @@ export class Hub extends deviceBase {
290
294
 
291
295
  async BLERefreshStatus(): Promise<void> {
292
296
  await this.debugLog('BLERefreshStatus');
297
+ const switchbot = await this.switchbotBLE();
298
+ if (switchbot === undefined) {
299
+ await this.BLERefreshConnection(switchbot);
300
+ } else {
301
+ // Start to monitor advertisement packets
302
+ (async () => {
303
+ // Start to monitor advertisement packets
304
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as hub2ServiceData;
305
+ // Update HomeKit
306
+ if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
307
+ this.serviceData = serviceData;
308
+ await this.BLEparseStatus();
309
+ await this.updateHomeKitCharacteristics();
310
+ } else {
311
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
312
+ await this.BLERefreshConnection(switchbot);
313
+ }
314
+ })();
315
+ }
316
+ }
317
+
318
+ async registerPlatformBLE(): Promise<void> {
319
+ await this.debugLog('registerPlatformBLE');
293
320
  if (this.config.options?.BLE) {
294
321
  await this.debugLog('is listening to Platform BLE.');
295
322
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -305,26 +332,7 @@ export class Hub extends deviceBase {
305
332
  }
306
333
  };
307
334
  } else {
308
- await this.debugLog('is using Device BLE Scanning.');
309
- const switchbot = await this.switchbotBLE();
310
- if (switchbot === undefined) {
311
- await this.BLERefreshConnection(switchbot);
312
- } else {
313
- // Start to monitor advertisement packets
314
- (async () => {
315
- // Start to monitor advertisement packets
316
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as hub2ServiceData;
317
- // Update HomeKit
318
- if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
319
- this.serviceData = serviceData;
320
- await this.BLEparseStatus();
321
- await this.updateHomeKitCharacteristics();
322
- } else {
323
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
324
- await this.BLERefreshConnection(switchbot);
325
- }
326
- })();
327
- }
335
+ await this.debugLog('is not listening to Platform BLE');
328
336
  }
329
337
  }
330
338
 
@@ -154,10 +154,14 @@ export class Humidifier extends deviceBase {
154
154
  this.debugLog('Retrieve initial values and update Homekit');
155
155
  this.refreshStatus();
156
156
 
157
- //regisiter webhook event handler
157
+ //regisiter webhook event handler if enabled
158
158
  this.debugLog('Registering Webhook Event Handler');
159
159
  this.registerWebhook();
160
160
 
161
+ //regisiter platform BLE event handler if enabled
162
+ this.debugLog('Registering Platform BLE Event Handler');
163
+ this.registerPlatformBLE();
164
+
161
165
  // Start an update interval
162
166
  interval(this.deviceRefreshRate * 1000)
163
167
  .pipe(skipWhile(() => this.humidifierUpdateInProgress))
@@ -318,7 +322,7 @@ export class Humidifier extends deviceBase {
318
322
  async refreshStatus(): Promise<void> {
319
323
  if (!this.device.enableCloudService && this.OpenAPI) {
320
324
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
321
- } else if (this.BLE || this.config.options?.BLE) {
325
+ } else if (this.BLE) {
322
326
  await this.BLERefreshStatus();
323
327
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
324
328
  await this.openAPIRefreshStatus();
@@ -330,6 +334,29 @@ export class Humidifier extends deviceBase {
330
334
 
331
335
  async BLERefreshStatus(): Promise<void> {
332
336
  await this.debugLog('BLERefreshStatus');
337
+ const switchbot = await this.switchbotBLE();
338
+ if (switchbot === undefined) {
339
+ await this.BLERefreshConnection(switchbot);
340
+ } else {
341
+ // Start to monitor advertisement packets
342
+ (async () => {
343
+ // Start to monitor advertisement packets
344
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData;
345
+ // Update HomeKit
346
+ if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
347
+ this.serviceData = serviceData;
348
+ await this.BLEparseStatus();
349
+ await this.updateHomeKitCharacteristics();
350
+ } else {
351
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
352
+ await this.BLERefreshConnection(switchbot);
353
+ }
354
+ })();
355
+ }
356
+ }
357
+
358
+ async registerPlatformBLE(): Promise<void> {
359
+ await this.debugLog('registerPlatformBLE');
333
360
  if (this.config.options?.BLE) {
334
361
  await this.debugLog('is listening to Platform BLE.');
335
362
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -345,26 +372,7 @@ export class Humidifier extends deviceBase {
345
372
  }
346
373
  };
347
374
  } else {
348
- await this.debugLog('is using Device BLE Scanning.');
349
- const switchbot = await this.switchbotBLE();
350
- if (switchbot === undefined) {
351
- await this.BLERefreshConnection(switchbot);
352
- } else {
353
- // Start to monitor advertisement packets
354
- (async () => {
355
- // Start to monitor advertisement packets
356
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as humidifierServiceData;
357
- // Update HomeKit
358
- if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
359
- this.serviceData = serviceData;
360
- await this.BLEparseStatus();
361
- await this.updateHomeKitCharacteristics();
362
- } else {
363
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
364
- await this.BLERefreshConnection(switchbot);
365
- }
366
- })();
367
- }
375
+ await this.debugLog('is not listening to Platform BLE');
368
376
  }
369
377
  }
370
378