@switchbot/homebridge-switchbot 2.2.0-beta.1 → 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 +2 -1
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +16 -12
  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 +3 -0
  24. package/dist/device/meter.d.ts.map +1 -1
  25. package/dist/device/meter.js +13 -9
  26. package/dist/device/meter.js.map +1 -1
  27. package/dist/device/meterplus.d.ts +3 -0
  28. package/dist/device/meterplus.d.ts.map +1 -1
  29. package/dist/device/meterplus.js +13 -9
  30. package/dist/device/meterplus.js.map +1 -1
  31. package/dist/device/motion.d.ts +2 -1
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +20 -15
  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 +17 -12
  50. package/src/device/curtain.ts +18 -11
  51. package/src/device/humidifier.ts +13 -8
  52. package/src/device/meter.ts +13 -8
  53. package/src/device/meterplus.ts +13 -8
  54. package/src/device/motion.ts +21 -15
  55. package/src/device/plug.ts +13 -8
  56. package/src/device/striplight.ts +13 -8
  57. package/src/settings.ts +14 -2
@@ -38,12 +38,12 @@ export class Motion {
38
38
  address!: ad['address'];
39
39
  battery!: serviceData['battery'];
40
40
  movement!: serviceData['movement'];
41
+ lightLevel!: serviceData['lightLevel'];
41
42
  is_light!: any;//serviceData['is_light'];
42
43
  tested!: any;
43
44
  led!: any;
44
45
  iot!: any;
45
46
  sense_distance!: any;
46
- light_intensity!: any;
47
47
 
48
48
  // Config
49
49
  set_minLux!: number;
@@ -169,15 +169,16 @@ export class Motion {
169
169
  if (!this.device.motion?.hide_lightsensor) {
170
170
  this.set_minLux = this.minLux();
171
171
  this.set_maxLux = this.maxLux();
172
- switch (this.is_light) {
173
- case true:
172
+ switch (this.lightLevel) {
173
+ case 'dark':
174
+ case 1:
174
175
  this.CurrentAmbientLightLevel = this.set_minLux;
175
176
  break;
176
177
  default:
177
178
  this.CurrentAmbientLightLevel = this.set_maxLux;
178
179
  }
179
180
  this.debugLog(
180
- `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.is_light},` +
181
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
181
182
  ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
182
183
  );
183
184
  }
@@ -254,7 +255,7 @@ export class Motion {
254
255
  })
255
256
  .then(async () => {
256
257
  // Set an event hander
257
- switchbot.onadvertisement = (ad: any) => {
258
+ switchbot.onadvertisement = async (ad: any) => {
258
259
  this.address = ad.address;
259
260
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
260
261
  + ` BLE Address Found: ${this.address}`);
@@ -265,34 +266,29 @@ export class Motion {
265
266
  this.led = ad.serviceData.led;
266
267
  this.iot = ad.serviceData.led;
267
268
  this.sense_distance = ad.serviceData.sense_distance;
268
- this.light_intensity = ad.serviceData.light_intensity;
269
+ this.lightLevel = ad.serviceData.lightLevel;
269
270
  this.is_light = ad.serviceData.is_light;
270
271
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
271
272
  this.debugLog(
272
273
  `${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, is_light: ` +
273
- `${ad.serviceData.is_light}, battery: ${ad.serviceData.battery}`,
274
+ `${ad.serviceData.is_light}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
274
275
  );
275
276
 
276
277
  if (this.serviceData) {
277
278
  this.connected = true;
278
279
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
280
+ await this.stopScanning(switchbot);
279
281
  } else {
280
282
  this.connected = false;
281
283
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
282
284
  }
283
285
  };
284
286
  // Wait 10 seconds
285
- return await switchbot.wait(this.scanDuration * 1000);
287
+ return await switchbot.wait(this.scanDuration * 2000);
286
288
  })
287
289
  .then(async () => {
288
290
  // Stop to monitor
289
- switchbot.stopScan();
290
- if (this.connected) {
291
- this.BLEparseStatus();
292
- this.updateHomeKitCharacteristics();
293
- } else {
294
- await this.BLERefreshConnection(switchbot);
295
- }
291
+ await this.stopScanning(switchbot);
296
292
  })
297
293
  .catch(async (e: any) => {
298
294
  this.apiError(e);
@@ -398,6 +394,16 @@ export class Motion {
398
394
  }
399
395
  }
400
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
+
401
407
  async getCustomBLEAddress(switchbot: any) {
402
408
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
403
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?