@switchbot/homebridge-switchbot 2.2.0-beta.0 → 2.2.0-beta.2

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 (57) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/config.schema.json +0 -2
  3. package/dist/device/bot.d.ts +1 -0
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +13 -9
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +11 -1
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +173 -23
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +6 -1
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +23 -16
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +2 -0
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +17 -11
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +3 -0
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +13 -9
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/meter.d.ts +6 -1
  24. package/dist/device/meter.d.ts.map +1 -1
  25. package/dist/device/meter.js +17 -11
  26. package/dist/device/meter.js.map +1 -1
  27. package/dist/device/meterplus.d.ts +6 -1
  28. package/dist/device/meterplus.d.ts.map +1 -1
  29. package/dist/device/meterplus.js +17 -11
  30. package/dist/device/meterplus.js.map +1 -1
  31. package/dist/device/motion.d.ts +6 -0
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +21 -12
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +3 -0
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +13 -9
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/device/striplight.d.ts +3 -0
  40. package/dist/device/striplight.d.ts.map +1 -1
  41. package/dist/device/striplight.js +13 -9
  42. package/dist/device/striplight.js.map +1 -1
  43. package/dist/settings.d.ts +7 -1
  44. package/dist/settings.d.ts.map +1 -1
  45. package/dist/settings.js.map +1 -1
  46. package/package.json +4 -4
  47. package/src/device/bot.ts +13 -8
  48. package/src/device/colorbulb.ts +190 -25
  49. package/src/device/contact.ts +28 -16
  50. package/src/device/curtain.ts +18 -11
  51. package/src/device/humidifier.ts +13 -8
  52. package/src/device/meter.ts +20 -11
  53. package/src/device/meterplus.ts +20 -11
  54. package/src/device/motion.ts +26 -11
  55. package/src/device/plug.ts +13 -8
  56. package/src/device/striplight.ts +13 -8
  57. package/src/settings.ts +14 -2
@@ -40,7 +40,9 @@ export class MeterPlus {
40
40
  switchbot!: switchbot;
41
41
  serviceData!: serviceData;
42
42
  address!: ad['address'];
43
- temperature!: temperature['c'];
43
+ temperature!: serviceData['temperature'];
44
+ celsius!: temperature['c'];
45
+ fahrenheit!: temperature['f'];
44
46
  battery!: serviceData['battery'];
45
47
  humidity!: serviceData['humidity'];
46
48
 
@@ -209,7 +211,7 @@ export class MeterPlus {
209
211
 
210
212
  // Current Temperature
211
213
  if (!this.device.meter?.hide_temperature) {
212
- this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
214
+ this.celsius < 0 ? 0 : this.celsius > 100 ? 100 : this.temperature;
213
215
  this.CurrentTemperature = this.temperature;
214
216
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
215
217
  }
@@ -266,7 +268,7 @@ export class MeterPlus {
266
268
  })
267
269
  .then(() => {
268
270
  // Set an event hander
269
- switchbot.onadvertisement = (ad: ad) => {
271
+ switchbot.onadvertisement = async (ad: ad) => {
270
272
  this.address = ad.address;
271
273
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
272
274
  + ` BLE Address Found: ${this.address}`);
@@ -275,7 +277,9 @@ export class MeterPlus {
275
277
  this.humidity = ad.serviceData.humidity;
276
278
  }
277
279
  this.serviceData = ad.serviceData;
278
- this.temperature = ad.serviceData.temperature!.c;
280
+ this.temperature = ad.serviceData.temperature;
281
+ this.celsius = ad.serviceData.temperature!.c;
282
+ this.fahrenheit = ad.serviceData.temperature!.f;
279
283
  this.battery = ad.serviceData.battery;
280
284
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
281
285
  this.debugLog(
@@ -287,6 +291,7 @@ export class MeterPlus {
287
291
  if (this.serviceData) {
288
292
  this.connected = true;
289
293
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
294
+ await this.stopScanning(switchbot);
290
295
  } else {
291
296
  this.connected = false;
292
297
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -297,13 +302,7 @@ export class MeterPlus {
297
302
  })
298
303
  .then(async () => {
299
304
  // Stop to monitor
300
- switchbot.stopScan();
301
- if (this.connected) {
302
- this.parseStatus();
303
- this.updateHomeKitCharacteristics();
304
- } else {
305
- await this.BLERefreshConnection(switchbot);
306
- }
305
+ await this.stopScanning(switchbot);
307
306
  })
308
307
  .catch(async (e: any) => {
309
308
  this.apiError(e);
@@ -488,6 +487,16 @@ export class MeterPlus {
488
487
  : null;
489
488
  }
490
489
 
490
+ async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
491
+ switchbot.stopScan();
492
+ if (this.connected) {
493
+ this.BLEparseStatus();
494
+ this.updateHomeKitCharacteristics();
495
+ } else {
496
+ await this.BLERefreshConnection(switchbot);
497
+ }
498
+ }
499
+
491
500
  async getCustomBLEAddress(switchbot: any) {
492
501
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
493
502
  (async () => {
@@ -39,6 +39,11 @@ export class Motion {
39
39
  battery!: serviceData['battery'];
40
40
  movement!: serviceData['movement'];
41
41
  lightLevel!: serviceData['lightLevel'];
42
+ is_light!: any;//serviceData['is_light'];
43
+ tested!: any;
44
+ led!: any;
45
+ iot!: any;
46
+ sense_distance!: any;
42
47
 
43
48
  // Config
44
49
  set_minLux!: number;
@@ -250,40 +255,40 @@ export class Motion {
250
255
  })
251
256
  .then(async () => {
252
257
  // Set an event hander
253
- switchbot.onadvertisement = (ad: any) => {
258
+ switchbot.onadvertisement = async (ad: any) => {
254
259
  this.address = ad.address;
255
260
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
256
261
  + ` BLE Address Found: ${this.address}`);
257
262
  this.serviceData = ad.serviceData;
258
263
  this.movement = ad.serviceData.movement;
264
+ this.tested = ad.serviceData.tested;
259
265
  this.battery = ad.serviceData.battery;
266
+ this.led = ad.serviceData.led;
267
+ this.iot = ad.serviceData.led;
268
+ this.sense_distance = ad.serviceData.sense_distance;
260
269
  this.lightLevel = ad.serviceData.lightLevel;
270
+ this.is_light = ad.serviceData.is_light;
261
271
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
262
272
  this.debugLog(
263
- `${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: ` +
264
- `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
273
+ `${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, is_light: ` +
274
+ `${ad.serviceData.is_light}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
265
275
  );
266
276
 
267
277
  if (this.serviceData) {
268
278
  this.connected = true;
269
279
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
280
+ await this.stopScanning(switchbot);
270
281
  } else {
271
282
  this.connected = false;
272
283
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
273
284
  }
274
285
  };
275
286
  // Wait 10 seconds
276
- return await switchbot.wait(this.scanDuration * 1000);
287
+ return await switchbot.wait(this.scanDuration * 2000);
277
288
  })
278
289
  .then(async () => {
279
290
  // Stop to monitor
280
- switchbot.stopScan();
281
- if (this.connected) {
282
- this.BLEparseStatus();
283
- this.updateHomeKitCharacteristics();
284
- } else {
285
- await this.BLERefreshConnection(switchbot);
286
- }
291
+ await this.stopScanning(switchbot);
287
292
  })
288
293
  .catch(async (e: any) => {
289
294
  this.apiError(e);
@@ -389,6 +394,16 @@ export class Motion {
389
394
  }
390
395
  }
391
396
 
397
+ async stopScanning(switchbot: any) {
398
+ switchbot.stopScan();
399
+ if (this.connected) {
400
+ this.BLEparseStatus();
401
+ this.updateHomeKitCharacteristics();
402
+ } else {
403
+ await this.BLERefreshConnection(switchbot);
404
+ }
405
+ }
406
+
392
407
  async getCustomBLEAddress(switchbot: any) {
393
408
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
394
409
  (async () => {
@@ -199,7 +199,7 @@ export class Plug {
199
199
  })
200
200
  .then(() => {
201
201
  // Set an event hander
202
- switchbot.onadvertisement = (ad: any) => {
202
+ switchbot.onadvertisement = async (ad: any) => {
203
203
  this.address = ad.address;
204
204
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
205
205
  + ` BLE Address Found: ${this.address}`);
@@ -221,6 +221,7 @@ export class Plug {
221
221
  if (this.serviceData) {
222
222
  this.connected = true;
223
223
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
224
+ await this.stopScanning(switchbot);
224
225
  } else {
225
226
  this.connected = false;
226
227
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -231,13 +232,7 @@ export class Plug {
231
232
  })
232
233
  .then(async () => {
233
234
  // Stop to monitor
234
- switchbot.stopScan();
235
- if (this.connected) {
236
- this.BLEparseStatus();
237
- this.updateHomeKitCharacteristics();
238
- } else {
239
- await this.BLERefreshConnection(switchbot);
240
- }
235
+ await this.stopScanning(switchbot);
241
236
  })
242
237
  .catch(async (e: any) => {
243
238
  this.apiError(e);
@@ -463,6 +458,16 @@ export class Plug {
463
458
  }
464
459
  }
465
460
 
461
+ async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
462
+ switchbot.stopScan();
463
+ if (this.connected) {
464
+ this.BLEparseStatus();
465
+ this.updateHomeKitCharacteristics();
466
+ } else {
467
+ await this.BLERefreshConnection(switchbot);
468
+ }
469
+ }
470
+
466
471
  BLEmodel(): 'g' | 'j' {
467
472
  if (this.device.deviceType === 'Plug Mini (US)') {
468
473
  return 'g';
@@ -311,7 +311,7 @@ export class StripLight {
311
311
  })
312
312
  .then(() => {
313
313
  // Set an event hander
314
- switchbot.onadvertisement = (ad: any) => {
314
+ switchbot.onadvertisement = async (ad: any) => {
315
315
  this.address = ad.address;
316
316
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
317
317
  + ` BLE Address Found: ${this.address}`);
@@ -334,6 +334,7 @@ export class StripLight {
334
334
  if (this.serviceData) {
335
335
  this.connected = true;
336
336
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
337
+ await this.stopScanning(switchbot);
337
338
  } else {
338
339
  this.connected = false;
339
340
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -344,13 +345,7 @@ export class StripLight {
344
345
  })
345
346
  .then(async () => {
346
347
  // Stop to monitor
347
- switchbot.stopScan();
348
- if (this.connected) {
349
- this.BLEparseStatus();
350
- this.updateHomeKitCharacteristics();
351
- } else {
352
- await this.BLERefreshConnection(switchbot);
353
- }
348
+ await this.stopScanning(switchbot);
354
349
  })
355
350
  .catch(async (e: any) => {
356
351
  this.apiError(e);
@@ -814,6 +809,16 @@ export class StripLight {
814
809
  }
815
810
  }
816
811
 
812
+ async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
813
+ switchbot.stopScan();
814
+ if (this.connected) {
815
+ this.BLEparseStatus();
816
+ this.updateHomeKitCharacteristics();
817
+ } else {
818
+ await this.BLERefreshConnection(switchbot);
819
+ }
820
+ }
821
+
817
822
  async getCustomBLEAddress(switchbot: any) {
818
823
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
819
824
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
package/src/settings.ts CHANGED
@@ -314,8 +314,18 @@ export type serviceData = {
314
314
  modelName: string;
315
315
  //Mode for Bot either Press or Switch
316
316
  mode?: boolean;
317
- //Bot State
318
- state?: string;
317
+ //Bot/ColorBulb State
318
+ state?: string | boolean;
319
+ //ColorBulb Power
320
+ power?: boolean;
321
+ //ColorBulb R
322
+ red?: number;
323
+ //ColorBulb G
324
+ green?: number;
325
+ //ColorBulb B
326
+ blue?: number;
327
+ //ColorBulb Color temperature
328
+ color_temperature?: number;
319
329
  //Battery percentage left on Bot, Meter, Motion, Contact, PlugMini, and Curtain
320
330
  battery?: number;
321
331
  //Humidifier's humidity level percentage
@@ -343,6 +353,8 @@ export type serviceData = {
343
353
  calibration?: boolean;
344
354
  //Current Curtain Positon %
345
355
  position?: number;
356
+ //Is Curtain Moving?
357
+ inMotion?: boolean;
346
358
  //PlugMini - Is there a delay?
347
359
  delay?: boolean;
348
360
  //PlugMini - Is there a Timer?