@switchbot/homebridge-switchbot 1.6.2-beta.1 → 1.6.4-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -199,12 +199,12 @@ export class Meter {
199
199
  if (this.device.scanDuration) {
200
200
  this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
201
201
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
202
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
202
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
203
203
  }
204
204
  } else {
205
205
  this.scanDuration = this.accessory.context.scanDuration = 1;
206
206
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
207
- this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
207
+ this.warnLog(`Meter: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
208
208
  }
209
209
  }
210
210
  }
@@ -306,77 +306,85 @@ export class Meter {
306
306
  private connectBLE() {
307
307
  // Convert to BLE Address
308
308
  this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
309
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
309
+ this.debugLog(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
310
310
  const switchbot = this.platform.connectBLE();
311
311
  return switchbot;
312
312
  }
313
313
 
314
314
 
315
- private BLErefreshStatus() {
315
+ private async BLErefreshStatus() {
316
316
  this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
317
317
  // eslint-disable-next-line @typescript-eslint/no-var-requires
318
318
  const switchbot = this.connectBLE();
319
319
  // Start to monitor advertisement packets
320
- switchbot.startScan({
321
- model: 'T',
322
- id: this.device.bleMac,
323
- }).then(() => {
324
- // Set an event hander
325
- switchbot.onadvertisement = (ad: ad) => {
326
- this.serviceData = ad.serviceData;
327
- this.temperature = ad.serviceData.temperature!.c;
328
- this.humidity = ad.serviceData.humidity;
329
- this.battery = ad.serviceData.battery;
330
- this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
331
- this.debugLog(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
332
- + `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, `
333
- + `battery: ${ad.serviceData.battery}`);
334
-
335
- if (this.serviceData) {
336
- this.connected = true;
337
- this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
320
+ if (switchbot !== false) {
321
+ switchbot.startScan({
322
+ model: 'T',
323
+ id: this.device.bleMac,
324
+ }).then(() => {
325
+ // Set an event hander
326
+ switchbot.onadvertisement = (ad: ad) => {
327
+ this.serviceData = ad.serviceData;
328
+ this.temperature = ad.serviceData.temperature!.c;
329
+ this.humidity = ad.serviceData.humidity;
330
+ this.battery = ad.serviceData.battery;
331
+ this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
332
+ this.debugLog(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
333
+ + `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, `
334
+ + `battery: ${ad.serviceData.battery}`);
335
+
336
+ if (this.serviceData) {
337
+ this.connected = true;
338
+ this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
339
+ } else {
340
+ this.connected = false;
341
+ this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
342
+ }
343
+ };
344
+ // Wait 10 seconds
345
+ return switchbot.wait(this.scanDuration * 1000);
346
+ }).then(async () => {
347
+ // Stop to monitor
348
+ switchbot.stopScan();
349
+ if (this.connected) {
350
+ this.CurrentTemperatureCached = this.temperature;
351
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
352
+ this.CurrentRelativeHumidityCached = this.humidity!;
353
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidityCached;
354
+ this.BatteryLevelCached = this.battery!;
355
+ this.accessory.context.BatteryLevel = this.BatteryLevelCached;
356
+ this.parseStatus();
357
+ this.updateHomeKitCharacteristics();
338
358
  } else {
339
- this.connected = false;
340
- this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
359
+ await this.BLEconnection();
360
+ }
361
+ }).catch(async (e: any) => {
362
+ this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
363
+ if (this.deviceLogging === 'debug') {
364
+ this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
365
+ + ` Error Message: ${JSON.stringify(e.message)}`);
366
+ }
367
+ if (this.platform.debugMode) {
368
+ this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
369
+ + ` Error: ${JSON.stringify(e)}`);
341
370
  }
342
- };
343
- // Wait 10 seconds
344
- return switchbot.wait(this.scanDuration * 1000);
345
- }).then(async () => {
346
- // Stop to monitor
347
- switchbot.stopScan();
348
- if (this.connected) {
349
- this.CurrentTemperatureCached = this.temperature;
350
- this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
351
- this.CurrentRelativeHumidityCached = this.humidity!;
352
- this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidityCached;
353
- this.BatteryLevelCached = this.battery!;
354
- this.accessory.context.BatteryLevel = this.BatteryLevelCached;
355
- this.parseStatus();
356
- this.updateHomeKitCharacteristics();
357
- } else {
358
- this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
359
371
  if (this.platform.config.credentials?.openToken) {
360
372
  this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
361
373
  this.openAPIRefreshStatus();
362
374
  }
363
- }
364
- }).catch(async (e: any) => {
365
- this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
366
- if (this.deviceLogging === 'debug') {
367
- this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
368
- + ` Error Message: ${JSON.stringify(e.message)}`);
369
- }
370
- if (this.platform.debugMode) {
371
- this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
372
- + ` Error: ${JSON.stringify(e)}`);
373
- }
374
- if (this.platform.config.credentials?.openToken) {
375
- this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
376
- this.openAPIRefreshStatus();
377
- }
378
- this.apiError(e);
379
- });
375
+ this.apiError(e);
376
+ });
377
+ } else {
378
+ await this.BLEconnection();
379
+ }
380
+ }
381
+
382
+ private async BLEconnection() {
383
+ this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
384
+ if (this.platform.config.credentials?.openToken) {
385
+ this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
386
+ await this.openAPIRefreshStatus();
387
+ }
380
388
  }
381
389
 
382
390
  private async openAPIRefreshStatus() {
@@ -130,12 +130,12 @@ export class Motion {
130
130
  if (this.device.scanDuration) {
131
131
  this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
132
132
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
133
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
133
+ this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
134
134
  }
135
135
  } else {
136
136
  this.scanDuration = this.accessory.context.scanDuration = 1;
137
137
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
138
- this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
138
+ this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
139
139
  }
140
140
  }
141
141
  }
@@ -229,7 +229,7 @@ export class Motion {
229
229
  private connectBLE() {
230
230
  // Convert to BLE Address
231
231
  this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
232
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
232
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
233
233
  const switchbot = this.platform.connectBLE();
234
234
  return switchbot;
235
235
  }
@@ -239,59 +239,67 @@ export class Motion {
239
239
  // eslint-disable-next-line @typescript-eslint/no-var-requires
240
240
  const switchbot = this.connectBLE();
241
241
  // Start to monitor advertisement packets
242
- switchbot.startScan({
243
- model: 's',
244
- id: this.device.bleMac,
245
- }).then(() => {
246
- // Set an event hander
247
- switchbot.onadvertisement = (ad: any) => {
248
- this.serviceData = ad.serviceData;
249
- this.movement = ad.serviceData.movement;
250
- this.battery = ad.serviceData.battery;
251
- this.lightLevel = ad.serviceData.lightLevel;
252
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
253
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: `
254
- + `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
255
-
256
- if (this.serviceData) {
257
- this.connected = true;
258
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
242
+ if (switchbot !== false) {
243
+ switchbot.startScan({
244
+ model: 's',
245
+ id: this.device.bleMac,
246
+ }).then(() => {
247
+ // Set an event hander
248
+ switchbot.onadvertisement = (ad: any) => {
249
+ this.serviceData = ad.serviceData;
250
+ this.movement = ad.serviceData.movement;
251
+ this.battery = ad.serviceData.battery;
252
+ this.lightLevel = ad.serviceData.lightLevel;
253
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
254
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: `
255
+ + `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
256
+
257
+ if (this.serviceData) {
258
+ this.connected = true;
259
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
260
+ } else {
261
+ this.connected = false;
262
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
263
+ }
264
+ };
265
+ // Wait 10 seconds
266
+ return switchbot.wait(this.scanDuration * 1000);
267
+ }).then(async () => {
268
+ // Stop to monitor
269
+ switchbot.stopScan();
270
+ if (this.connected) {
271
+ this.parseStatus();
272
+ this.updateHomeKitCharacteristics();
259
273
  } else {
260
- this.connected = false;
261
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
274
+ await this.BLEconnection();
275
+ }
276
+ }).catch(async (e: any) => {
277
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
278
+ if (this.deviceLogging === 'debug') {
279
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
280
+ + ` Error Message: ${JSON.stringify(e.message)}`);
281
+ }
282
+ if (this.platform.debugMode) {
283
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
284
+ + ` Error: ${JSON.stringify(e)}`);
262
285
  }
263
- };
264
- // Wait 10 seconds
265
- return switchbot.wait(this.scanDuration * 1000);
266
- }).then(async () => {
267
- // Stop to monitor
268
- switchbot.stopScan();
269
- if (this.connected) {
270
- this.parseStatus();
271
- this.updateHomeKitCharacteristics();
272
- } else {
273
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
274
286
  if (this.platform.config.credentials?.openToken) {
275
287
  this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
276
288
  await this.openAPIRefreshStatus();
277
289
  }
278
- }
279
- }).catch(async (e: any) => {
280
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
281
- if (this.deviceLogging === 'debug') {
282
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
283
- + ` Error Message: ${JSON.stringify(e.message)}`);
284
- }
285
- if (this.platform.debugMode) {
286
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
287
- + ` Error: ${JSON.stringify(e)}`);
288
- }
289
- if (this.platform.config.credentials?.openToken) {
290
- this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
291
- await this.openAPIRefreshStatus();
292
- }
293
- this.apiError(e);
294
- });
290
+ this.apiError(e);
291
+ });
292
+ } else {
293
+ await this.BLEconnection();
294
+ }
295
+ }
296
+
297
+ private async BLEconnection() {
298
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
299
+ if (this.platform.config.credentials?.openToken) {
300
+ this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
301
+ await this.openAPIRefreshStatus();
302
+ }
295
303
  }
296
304
 
297
305
  private async openAPIRefreshStatus() {
@@ -134,12 +134,12 @@ export class Plug {
134
134
  if (this.device.scanDuration) {
135
135
  this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
136
136
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
137
- this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
137
+ this.warnLog(`Plug: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
138
138
  }
139
139
  } else {
140
140
  this.scanDuration = this.accessory.context.scanDuration = 1;
141
141
  if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
142
- this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
142
+ this.warnLog(`Plug: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
143
143
  }
144
144
  }
145
145
  }