@switchbot/homebridge-switchbot 3.7.1-beta.1 → 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 (99) 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/device.d.ts.map +1 -1
  26. package/dist/device/device.js +247 -394
  27. package/dist/device/device.js.map +1 -1
  28. package/dist/device/fan.d.ts +1 -0
  29. package/dist/device/fan.d.ts.map +1 -1
  30. package/dist/device/fan.js +30 -24
  31. package/dist/device/fan.js.map +1 -1
  32. package/dist/device/hub.d.ts +1 -0
  33. package/dist/device/hub.d.ts.map +1 -1
  34. package/dist/device/hub.js +30 -24
  35. package/dist/device/hub.js.map +1 -1
  36. package/dist/device/humidifier.d.ts +1 -0
  37. package/dist/device/humidifier.d.ts.map +1 -1
  38. package/dist/device/humidifier.js +30 -24
  39. package/dist/device/humidifier.js.map +1 -1
  40. package/dist/device/iosensor.d.ts +1 -0
  41. package/dist/device/iosensor.d.ts.map +1 -1
  42. package/dist/device/iosensor.js +30 -24
  43. package/dist/device/iosensor.js.map +1 -1
  44. package/dist/device/lightstrip.d.ts +1 -0
  45. package/dist/device/lightstrip.d.ts.map +1 -1
  46. package/dist/device/lightstrip.js +30 -24
  47. package/dist/device/lightstrip.js.map +1 -1
  48. package/dist/device/lock.d.ts +1 -0
  49. package/dist/device/lock.d.ts.map +1 -1
  50. package/dist/device/lock.js +31 -25
  51. package/dist/device/lock.js.map +1 -1
  52. package/dist/device/meter.d.ts +1 -0
  53. package/dist/device/meter.d.ts.map +1 -1
  54. package/dist/device/meter.js +30 -24
  55. package/dist/device/meter.js.map +1 -1
  56. package/dist/device/meterplus.d.ts +1 -0
  57. package/dist/device/meterplus.d.ts.map +1 -1
  58. package/dist/device/meterplus.js +30 -24
  59. package/dist/device/meterplus.js.map +1 -1
  60. package/dist/device/motion.d.ts +1 -0
  61. package/dist/device/motion.d.ts.map +1 -1
  62. package/dist/device/motion.js +30 -24
  63. package/dist/device/motion.js.map +1 -1
  64. package/dist/device/plug.d.ts +1 -0
  65. package/dist/device/plug.d.ts.map +1 -1
  66. package/dist/device/plug.js +31 -25
  67. package/dist/device/plug.js.map +1 -1
  68. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  69. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  70. package/dist/device/robotvacuumcleaner.js +30 -24
  71. package/dist/device/robotvacuumcleaner.js.map +1 -1
  72. package/dist/device/waterdetector.d.ts +1 -0
  73. package/dist/device/waterdetector.d.ts.map +1 -1
  74. package/dist/device/waterdetector.js +30 -24
  75. package/dist/device/waterdetector.js.map +1 -1
  76. package/dist/irdevice/irdevice.d.ts.map +1 -1
  77. package/dist/irdevice/irdevice.js +30 -133
  78. package/dist/irdevice/irdevice.js.map +1 -1
  79. package/package.json +3 -3
  80. package/src/device/blindtilt.ts +39 -23
  81. package/src/device/bot.ts +30 -22
  82. package/src/device/ceilinglight.ts +31 -23
  83. package/src/device/colorbulb.ts +30 -22
  84. package/src/device/contact.ts +30 -22
  85. package/src/device/curtain.ts +50 -36
  86. package/src/device/device.ts +283 -395
  87. package/src/device/fan.ts +30 -22
  88. package/src/device/hub.ts +30 -22
  89. package/src/device/humidifier.ts +30 -22
  90. package/src/device/iosensor.ts +30 -22
  91. package/src/device/lightstrip.ts +30 -22
  92. package/src/device/lock.ts +31 -23
  93. package/src/device/meter.ts +30 -22
  94. package/src/device/meterplus.ts +30 -22
  95. package/src/device/motion.ts +30 -22
  96. package/src/device/plug.ts +31 -23
  97. package/src/device/robotvacuumcleaner.ts +30 -22
  98. package/src/device/waterdetector.ts +30 -22
  99. package/src/irdevice/irdevice.ts +54 -134
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
 
@@ -158,10 +158,14 @@ export class IOSensor extends deviceBase {
158
158
  this.debugLog('Retrieve initial values and update Homekit');
159
159
  this.refreshStatus();
160
160
 
161
- //regisiter webhook event handler
161
+ //regisiter webhook event handler if enabled
162
162
  this.debugLog('Registering Webhook Event Handler');
163
163
  this.registerWebhook();
164
164
 
165
+ //regisiter platform BLE event handler if enabled
166
+ this.debugLog('Registering Platform BLE Event Handler');
167
+ this.registerPlatformBLE();
168
+
165
169
  // Start an update interval
166
170
  interval(this.deviceRefreshRate * 1000)
167
171
  .pipe(skipWhile(() => this.ioSensorUpdateInProgress))
@@ -271,7 +275,7 @@ export class IOSensor extends deviceBase {
271
275
  async refreshStatus(): Promise<void> {
272
276
  if (!this.device.enableCloudService && this.OpenAPI) {
273
277
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
274
- } else if (this.BLE || this.config.options?.BLE) {
278
+ } else if (this.BLE) {
275
279
  await this.BLERefreshStatus();
276
280
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
277
281
  await this.openAPIRefreshStatus();
@@ -283,6 +287,29 @@ export class IOSensor extends deviceBase {
283
287
 
284
288
  async BLERefreshStatus(): Promise<void> {
285
289
  await this.debugLog('BLERefreshStatus');
290
+ const switchbot = await this.switchbotBLE();
291
+ if (switchbot === undefined) {
292
+ await this.BLERefreshConnection(switchbot);
293
+ } else {
294
+ // Start to monitor advertisement packets
295
+ (async () => {
296
+ // Start to monitor advertisement packets
297
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData;
298
+ // Update HomeKit
299
+ if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
300
+ this.serviceData = serviceData;
301
+ await this.BLEparseStatus();
302
+ await this.updateHomeKitCharacteristics();
303
+ } else {
304
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
305
+ await this.BLERefreshConnection(switchbot);
306
+ }
307
+ })();
308
+ }
309
+ }
310
+
311
+ async registerPlatformBLE(): Promise<void> {
312
+ await this.debugLog('registerPlatformBLE');
286
313
  if (this.config.options?.BLE) {
287
314
  await this.debugLog('is listening to Platform BLE.');
288
315
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -298,26 +325,7 @@ export class IOSensor extends deviceBase {
298
325
  }
299
326
  };
300
327
  } else {
301
- await this.debugLog('is using Device BLE Scanning.');
302
- const switchbot = await this.switchbotBLE();
303
- if (switchbot === undefined) {
304
- await this.BLERefreshConnection(switchbot);
305
- } else {
306
- // Start to monitor advertisement packets
307
- (async () => {
308
- // Start to monitor advertisement packets
309
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as outdoorMeterServiceData;
310
- // Update HomeKit
311
- if (serviceData.model === SwitchBotBLEModel.OutdoorMeter && serviceData.modelName === SwitchBotBLEModelName.OutdoorMeter) {
312
- this.serviceData = serviceData;
313
- await this.BLEparseStatus();
314
- await this.updateHomeKitCharacteristics();
315
- } else {
316
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
317
- await this.BLERefreshConnection(switchbot);
318
- }
319
- })();
320
- }
328
+ await this.debugLog('is not listening to Platform BLE');
321
329
  }
322
330
  }
323
331
 
@@ -164,10 +164,14 @@ export class StripLight 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.stripLightUpdateInProgress))
@@ -304,7 +308,7 @@ export class StripLight extends deviceBase {
304
308
  async refreshStatus(): Promise<void> {
305
309
  if (!this.device.enableCloudService && this.OpenAPI) {
306
310
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
307
- } else if (this.BLE || this.config.options?.BLE) {
311
+ } else if (this.BLE) {
308
312
  await this.BLERefreshStatus();
309
313
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
310
314
  await this.openAPIRefreshStatus();
@@ -316,6 +320,29 @@ export class StripLight extends deviceBase {
316
320
 
317
321
  async BLERefreshStatus(): Promise<void> {
318
322
  await this.debugLog('BLERefreshStatus');
323
+ const switchbot = await this.switchbotBLE();
324
+ if (switchbot === undefined) {
325
+ await this.BLERefreshConnection(switchbot);
326
+ } else {
327
+ // Start to monitor advertisement packets
328
+ (async () => {
329
+ // Start to monitor advertisement packets
330
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
331
+ // Update HomeKit
332
+ if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
333
+ this.serviceData = serviceData;
334
+ await this.BLEparseStatus();
335
+ await this.updateHomeKitCharacteristics();
336
+ } else {
337
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
338
+ await this.BLERefreshConnection(switchbot);
339
+ }
340
+ })();
341
+ }
342
+ }
343
+
344
+ async registerPlatformBLE(): Promise<void> {
345
+ await this.debugLog('registerPlatformBLE');
319
346
  if (this.config.options?.BLE) {
320
347
  await this.debugLog('is listening to Platform BLE.');
321
348
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -331,26 +358,7 @@ export class StripLight extends deviceBase {
331
358
  }
332
359
  };
333
360
  } else {
334
- await this.debugLog('is using Device BLE Scanning.');
335
- const switchbot = await this.switchbotBLE();
336
- if (switchbot === undefined) {
337
- await this.BLERefreshConnection(switchbot);
338
- } else {
339
- // Start to monitor advertisement packets
340
- (async () => {
341
- // Start to monitor advertisement packets
342
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as stripLightServiceData;
343
- // Update HomeKit
344
- if (serviceData.model === SwitchBotBLEModel.StripLight && serviceData.modelName === SwitchBotBLEModelName.StripLight) {
345
- this.serviceData = serviceData;
346
- await this.BLEparseStatus();
347
- await this.updateHomeKitCharacteristics();
348
- } else {
349
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
350
- await this.BLERefreshConnection(switchbot);
351
- }
352
- })();
353
- }
361
+ await this.debugLog('is not listening to Platform BLE');
354
362
  }
355
363
  }
356
364
 
@@ -168,10 +168,14 @@ export class Lock extends deviceBase {
168
168
  this.debugLog('Retrieve initial values and update Homekit');
169
169
  this.refreshStatus();
170
170
 
171
- //regisiter webhook event handler
171
+ //regisiter webhook event handler if enabled
172
172
  this.debugLog('Registering Webhook Event Handler');
173
173
  this.registerWebhook();
174
174
 
175
+ //regisiter platform BLE event handler if enabled
176
+ this.debugLog('Registering Platform BLE Event Handler');
177
+ this.registerPlatformBLE();
178
+
175
179
  // Start an update interval
176
180
  interval(this.deviceRefreshRate * 1000)
177
181
  .pipe(skipWhile(() => this.lockUpdateInProgress))
@@ -297,7 +301,7 @@ export class Lock extends deviceBase {
297
301
  async refreshStatus(): Promise<void> {
298
302
  if (!this.device.enableCloudService && this.OpenAPI) {
299
303
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
300
- } else if (this.BLE || this.config.options?.BLE) {
304
+ } else if (this.BLE) {
301
305
  await this.BLERefreshStatus();
302
306
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
303
307
  await this.openAPIRefreshStatus();
@@ -309,6 +313,30 @@ export class Lock extends deviceBase {
309
313
 
310
314
  async BLERefreshStatus(): Promise<void> {
311
315
  await this.debugLog('BLERefreshStatus');
316
+ const switchbot = await this.switchbotBLE();
317
+ if (switchbot === undefined) {
318
+ await this.BLERefreshConnection(switchbot);
319
+ } else {
320
+ // Start to monitor advertisement packets
321
+ (async () => {
322
+ // Start to monitor advertisement packets
323
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as lockServiceData | lockProServiceData;
324
+ // Update HomeKit
325
+ if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
326
+ && (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
327
+ this.serviceData = serviceData;
328
+ await this.BLEparseStatus();
329
+ await this.updateHomeKitCharacteristics();
330
+ } else {
331
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
332
+ await this.BLERefreshConnection(switchbot);
333
+ }
334
+ })();
335
+ }
336
+ }
337
+
338
+ async registerPlatformBLE(): Promise<void> {
339
+ await this.debugLog('registerPlatformBLE');
312
340
  if (this.config.options?.BLE) {
313
341
  await this.debugLog('is listening to Platform BLE.');
314
342
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -324,27 +352,7 @@ export class Lock extends deviceBase {
324
352
  }
325
353
  };
326
354
  } else {
327
- await this.debugLog('is using Device BLE Scanning.');
328
- const switchbot = await this.switchbotBLE();
329
- if (switchbot === undefined) {
330
- await this.BLERefreshConnection(switchbot);
331
- } else {
332
- // Start to monitor advertisement packets
333
- (async () => {
334
- // Start to monitor advertisement packets
335
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as lockServiceData | lockProServiceData;
336
- // Update HomeKit
337
- if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
338
- && (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
339
- this.serviceData = serviceData;
340
- await this.BLEparseStatus();
341
- await this.updateHomeKitCharacteristics();
342
- } else {
343
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
344
- await this.BLERefreshConnection(switchbot);
345
- }
346
- })();
347
- }
355
+ await this.debugLog('is not listening to Platform BLE');
348
356
  }
349
357
  }
350
358
 
@@ -151,10 +151,14 @@ export class Meter extends deviceBase {
151
151
  this.debugLog('Retrieve initial values and update Homekit');
152
152
  this.refreshStatus();
153
153
 
154
- //regisiter webhook event handler
154
+ //regisiter webhook event handler if enabled
155
155
  this.debugLog('Registering Webhook Event Handler');
156
156
  this.registerWebhook();
157
157
 
158
+ //regisiter platform BLE event handler if enabled
159
+ this.debugLog('Registering Platform BLE Event Handler');
160
+ this.registerPlatformBLE();
161
+
158
162
  // Start an update interval
159
163
  interval(this.deviceRefreshRate * 1000)
160
164
  .pipe(skipWhile(() => this.meterUpdateInProgress))
@@ -265,7 +269,7 @@ export class Meter extends deviceBase {
265
269
  async refreshStatus(): Promise<void> {
266
270
  if (!this.device.enableCloudService && this.OpenAPI) {
267
271
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
268
- } else if (this.BLE || this.config.options?.BLE) {
272
+ } else if (this.BLE) {
269
273
  await this.BLERefreshStatus();
270
274
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
271
275
  await this.openAPIRefreshStatus();
@@ -277,6 +281,29 @@ export class Meter extends deviceBase {
277
281
 
278
282
  async BLERefreshStatus(): Promise<void> {
279
283
  await this.debugLog('BLERefreshStatus');
284
+ const switchbot = await this.switchbotBLE();
285
+ if (switchbot === undefined) {
286
+ await this.BLERefreshConnection(switchbot);
287
+ } else {
288
+ // Start to monitor advertisement packets
289
+ (async () => {
290
+ // Start to monitor advertisement packets
291
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData;
292
+ // Update HomeKit
293
+ if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
294
+ this.serviceData = serviceData;
295
+ await this.BLEparseStatus();
296
+ await this.updateHomeKitCharacteristics();
297
+ } else {
298
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
299
+ await this.BLERefreshConnection(switchbot);
300
+ }
301
+ })();
302
+ }
303
+ }
304
+
305
+ async registerPlatformBLE(): Promise<void> {
306
+ await this.debugLog('registerPlatformBLE');
280
307
  if (this.config.options?.BLE) {
281
308
  await this.debugLog('is listening to Platform BLE.');
282
309
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -292,26 +319,7 @@ export class Meter extends deviceBase {
292
319
  }
293
320
  };
294
321
  } else {
295
- await this.debugLog('is using Device BLE Scanning.');
296
- const switchbot = await this.switchbotBLE();
297
- if (switchbot === undefined) {
298
- await this.BLERefreshConnection(switchbot);
299
- } else {
300
- // Start to monitor advertisement packets
301
- (async () => {
302
- // Start to monitor advertisement packets
303
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData;
304
- // Update HomeKit
305
- if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
306
- this.serviceData = serviceData;
307
- await this.BLEparseStatus();
308
- await this.updateHomeKitCharacteristics();
309
- } else {
310
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
311
- await this.BLERefreshConnection(switchbot);
312
- }
313
- })();
314
- }
322
+ await this.debugLog('is not listening to Platform BLE');
315
323
  }
316
324
  }
317
325
 
@@ -156,10 +156,14 @@ export class MeterPlus extends deviceBase {
156
156
  this.debugLog('Retrieve initial values and update Homekit');
157
157
  this.refreshStatus();
158
158
 
159
- //regisiter webhook event handler
159
+ //regisiter webhook event handler if enabled
160
160
  this.debugLog('Registering Webhook Event Handler');
161
161
  this.registerWebhook();
162
162
 
163
+ //regisiter platform BLE event handler if enabled
164
+ this.debugLog('Registering Platform BLE Event Handler');
165
+ this.registerPlatformBLE();
166
+
163
167
  // Start an update interval
164
168
  interval(this.deviceRefreshRate * 1000)
165
169
  .pipe(skipWhile(() => this.meterUpdateInProgress))
@@ -266,7 +270,7 @@ export class MeterPlus extends deviceBase {
266
270
  async refreshStatus(): Promise<void> {
267
271
  if (!this.device.enableCloudService && this.OpenAPI) {
268
272
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
269
- } else if (this.BLE || this.config.options?.BLE) {
273
+ } else if (this.BLE) {
270
274
  await this.BLERefreshStatus();
271
275
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
272
276
  await this.openAPIRefreshStatus();
@@ -278,6 +282,29 @@ export class MeterPlus extends deviceBase {
278
282
 
279
283
  async BLERefreshStatus(): Promise<void> {
280
284
  await this.debugLog('BLERefreshStatus');
285
+ const switchbot = await this.switchbotBLE();
286
+ if (switchbot === undefined) {
287
+ await this.BLERefreshConnection(switchbot);
288
+ } else {
289
+ // Start to monitor advertisement packets
290
+ (async () => {
291
+ // Start to monitor advertisement packets
292
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterPlusServiceData;
293
+ // Update HomeKit
294
+ if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
295
+ this.serviceData = serviceData;
296
+ await this.BLEparseStatus();
297
+ await this.updateHomeKitCharacteristics();
298
+ } else {
299
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
300
+ await this.BLERefreshConnection(switchbot);
301
+ }
302
+ })();
303
+ }
304
+ }
305
+
306
+ async registerPlatformBLE(): Promise<void> {
307
+ await this.debugLog('registerPlatformBLE');
281
308
  if (this.config.options?.BLE) {
282
309
  await this.debugLog('is listening to Platform BLE.');
283
310
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -293,26 +320,7 @@ export class MeterPlus extends deviceBase {
293
320
  }
294
321
  };
295
322
  } else {
296
- await this.debugLog('is using Device BLE Scanning.');
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 meterPlusServiceData;
305
- // Update HomeKit
306
- if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
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
- }
323
+ await this.debugLog('is not listening to Platform BLE');
316
324
  }
317
325
  }
318
326