@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
@@ -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
 
@@ -141,10 +141,14 @@ export class Motion extends deviceBase {
141
141
  this.debugLog('Retrieve initial values and update Homekit');
142
142
  this.refreshStatus();
143
143
 
144
- //regisiter webhook event handler
144
+ //regisiter webhook event handler if enabled
145
145
  this.debugLog('Registering Webhook Event Handler');
146
146
  this.registerWebhook();
147
147
 
148
+ //regisiter platform BLE event handler if enabled
149
+ this.debugLog('Registering Platform BLE Event Handler');
150
+ this.registerPlatformBLE();
151
+
148
152
  // Start an update interval
149
153
  interval(this.deviceRefreshRate * 1000)
150
154
  .pipe(skipWhile(() => this.motionUbpdateInProgress))
@@ -236,7 +240,7 @@ export class Motion extends deviceBase {
236
240
  async refreshStatus(): Promise<void> {
237
241
  if (!this.device.enableCloudService && this.OpenAPI) {
238
242
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
239
- } else if (this.BLE || this.config.options?.BLE) {
243
+ } else if (this.BLE) {
240
244
  await this.BLERefreshStatus();
241
245
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
242
246
  await this.openAPIRefreshStatus();
@@ -248,6 +252,29 @@ export class Motion extends deviceBase {
248
252
 
249
253
  async BLERefreshStatus(): Promise<void> {
250
254
  await this.debugLog('BLERefreshStatus');
255
+ const switchbot = await this.switchbotBLE();
256
+ if (switchbot === undefined) {
257
+ await this.BLERefreshConnection(switchbot);
258
+ } else {
259
+ // Start to monitor advertisement packets
260
+ (async () => {
261
+ // Start to monitor advertisement packets
262
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
263
+ // Update HomeKit
264
+ if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
265
+ this.serviceData = serviceData;
266
+ await this.BLEparseStatus();
267
+ await this.updateHomeKitCharacteristics();
268
+ } else {
269
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
270
+ await this.BLERefreshConnection(switchbot);
271
+ }
272
+ })();
273
+ }
274
+ }
275
+
276
+ async registerPlatformBLE(): Promise<void> {
277
+ await this.debugLog('registerPlatformBLE');
251
278
  if (this.config.options?.BLE) {
252
279
  await this.debugLog('is listening to Platform BLE.');
253
280
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -263,26 +290,7 @@ export class Motion extends deviceBase {
263
290
  }
264
291
  };
265
292
  } else {
266
- await this.debugLog('is using Device BLE Scanning.');
267
- const switchbot = await this.switchbotBLE();
268
- if (switchbot === undefined) {
269
- await this.BLERefreshConnection(switchbot);
270
- } else {
271
- // Start to monitor advertisement packets
272
- (async () => {
273
- // Start to monitor advertisement packets
274
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as motionSensorServiceData;
275
- // Update HomeKit
276
- if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
277
- this.serviceData = serviceData;
278
- await this.BLEparseStatus();
279
- await this.updateHomeKitCharacteristics();
280
- } else {
281
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
282
- await this.BLERefreshConnection(switchbot);
283
- }
284
- })();
285
- }
293
+ await this.debugLog('is not listening to Platform BLE');
286
294
  }
287
295
  }
288
296
 
@@ -69,10 +69,14 @@ export class Plug extends deviceBase {
69
69
  this.debugLog('Retrieve initial values and update Homekit');
70
70
  this.refreshStatus();
71
71
 
72
- //regisiter webhook event handler
72
+ //regisiter webhook event handler if enabled
73
73
  this.debugLog('Registering Webhook Event Handler');
74
74
  this.registerWebhook();
75
75
 
76
+ //regisiter platform BLE event handler if enabled
77
+ this.debugLog('Registering Platform BLE Event Handler');
78
+ this.registerPlatformBLE();
79
+
76
80
  // Start an update interval
77
81
  interval(this.deviceRefreshRate * 1000)
78
82
  .pipe(skipWhile(() => this.plugUpdateInProgress))
@@ -148,7 +152,7 @@ export class Plug extends deviceBase {
148
152
  async refreshStatus(): Promise<void> {
149
153
  if (!this.device.enableCloudService && this.OpenAPI) {
150
154
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
151
- } else if (this.BLE || this.config.options?.BLE) {
155
+ } else if (this.BLE) {
152
156
  await this.BLERefreshStatus();
153
157
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
154
158
  await this.openAPIRefreshStatus();
@@ -160,6 +164,30 @@ export class Plug extends deviceBase {
160
164
 
161
165
  async BLERefreshStatus(): Promise<void> {
162
166
  await this.debugLog('BLERefreshStatus');
167
+ const switchbot = await this.switchbotBLE();
168
+ if (switchbot === undefined) {
169
+ await this.BLERefreshConnection(switchbot);
170
+ } else {
171
+ // Start to monitor advertisement packets
172
+ (async () => {
173
+ // Start to monitor advertisement packets
174
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
175
+ // Update HomeKit
176
+ if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
177
+ && serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
178
+ this.serviceData = serviceData;
179
+ await this.BLEparseStatus();
180
+ await this.updateHomeKitCharacteristics();
181
+ } else {
182
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
183
+ await this.BLERefreshConnection(switchbot);
184
+ }
185
+ })();
186
+ }
187
+ }
188
+
189
+ async registerPlatformBLE(): Promise<void> {
190
+ await this.debugLog('registerPlatformBLE');
163
191
  if (this.config.options?.BLE) {
164
192
  await this.debugLog('is listening to Platform BLE.');
165
193
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -175,27 +203,7 @@ export class Plug extends deviceBase {
175
203
  }
176
204
  };
177
205
  } else {
178
- await this.debugLog('is using Device BLE Scanning.');
179
- const switchbot = await this.switchbotBLE();
180
- if (switchbot === undefined) {
181
- await this.BLERefreshConnection(switchbot);
182
- } else {
183
- // Start to monitor advertisement packets
184
- (async () => {
185
- // Start to monitor advertisement packets
186
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as plugMiniUSServiceData | plugMiniJPServiceData;
187
- // Update HomeKit
188
- if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
189
- && serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
190
- this.serviceData = serviceData;
191
- await this.BLEparseStatus();
192
- await this.updateHomeKitCharacteristics();
193
- } else {
194
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
195
- await this.BLERefreshConnection(switchbot);
196
- }
197
- })();
198
- }
206
+ await this.debugLog('is not listening to Platform BLE');
199
207
  }
200
208
  }
201
209
 
@@ -130,10 +130,14 @@ export class RobotVacuumCleaner extends deviceBase {
130
130
  this.debugLog('Retrieve initial values and update Homekit');
131
131
  this.refreshStatus();
132
132
 
133
- //regisiter webhook event handler
133
+ //regisiter webhook event handler if enabled
134
134
  this.debugLog('Registering Webhook Event Handler');
135
135
  this.registerWebhook();
136
136
 
137
+ //regisiter platform BLE event handler if enabled
138
+ this.debugLog('Registering Platform BLE Event Handler');
139
+ this.registerPlatformBLE();
140
+
137
141
  // Start an update interval
138
142
  interval(this.deviceRefreshRate * 1000)
139
143
  .pipe(skipWhile(() => this.robotVacuumCleanerUpdateInProgress))
@@ -249,7 +253,7 @@ export class RobotVacuumCleaner extends deviceBase {
249
253
  async refreshStatus(): Promise<void> {
250
254
  if (!this.device.enableCloudService && this.OpenAPI) {
251
255
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
252
- } else if (this.BLE || this.config.options?.BLE) {
256
+ } else if (this.BLE) {
253
257
  await this.BLERefreshStatus();
254
258
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
255
259
  await this.openAPIRefreshStatus();
@@ -261,6 +265,29 @@ export class RobotVacuumCleaner extends deviceBase {
261
265
 
262
266
  async BLERefreshStatus(): Promise<void> {
263
267
  await this.debugLog('BLERefreshStatus');
268
+ const switchbot = await this.switchbotBLE();
269
+ if (switchbot === undefined) {
270
+ await this.BLERefreshConnection(switchbot);
271
+ } else {
272
+ // Start to monitor advertisement packets
273
+ (async () => {
274
+ // Start to monitor advertisement packets
275
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
276
+ // Update HomeKit
277
+ if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
278
+ this.serviceData = serviceData;
279
+ await this.BLEparseStatus();
280
+ await this.updateHomeKitCharacteristics();
281
+ } else {
282
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
283
+ await this.BLERefreshConnection(switchbot);
284
+ }
285
+ })();
286
+ }
287
+ }
288
+
289
+ async registerPlatformBLE(): Promise<void> {
290
+ await this.debugLog('registerPlatformBLE');
264
291
  if (this.config.options?.BLE) {
265
292
  await this.debugLog('is listening to Platform BLE.');
266
293
  this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
@@ -276,26 +303,7 @@ export class RobotVacuumCleaner extends deviceBase {
276
303
  }
277
304
  };
278
305
  } else {
279
- await this.debugLog('is using Device BLE Scanning.');
280
- const switchbot = await this.switchbotBLE();
281
- if (switchbot === undefined) {
282
- await this.BLERefreshConnection(switchbot);
283
- } else {
284
- // Start to monitor advertisement packets
285
- (async () => {
286
- // Start to monitor advertisement packets
287
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
288
- // Update HomeKit
289
- if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
290
- this.serviceData = serviceData;
291
- await this.BLEparseStatus();
292
- await this.updateHomeKitCharacteristics();
293
- } else {
294
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
295
- await this.BLERefreshConnection(switchbot);
296
- }
297
- })();
298
- }
306
+ await this.debugLog('is not listening to Platform BLE');
299
307
  }
300
308
  }
301
309