@switchbot/homebridge-switchbot 2.0.0-beta.21 → 2.0.0-beta.23

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 (62) hide show
  1. package/config.schema.json +4 -4
  2. package/dist/device/bot.d.ts +2 -2
  3. package/dist/device/bot.d.ts.map +1 -1
  4. package/dist/device/bot.js +19 -15
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts +2 -2
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +18 -18
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts +1 -2
  11. package/dist/device/contact.d.ts.map +1 -1
  12. package/dist/device/contact.js +11 -13
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.d.ts +2 -2
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +19 -21
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/humidifier.d.ts +2 -2
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +18 -17
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +3 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +39 -10
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +1 -2
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +11 -13
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +1 -2
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +9 -11
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +1 -2
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +11 -13
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +2 -2
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +18 -17
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +4 -2
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +84 -76
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/platform.d.ts +2 -3
  47. package/dist/platform.d.ts.map +1 -1
  48. package/dist/platform.js +68 -70
  49. package/dist/platform.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/device/bot.ts +20 -16
  52. package/src/device/colorbulb.ts +19 -19
  53. package/src/device/contact.ts +11 -14
  54. package/src/device/curtain.ts +20 -22
  55. package/src/device/humidifier.ts +19 -18
  56. package/src/device/lock.ts +42 -10
  57. package/src/device/meter.ts +11 -14
  58. package/src/device/meterplus.ts +9 -12
  59. package/src/device/motion.ts +11 -14
  60. package/src/device/plug.ts +19 -18
  61. package/src/device/striplight.ts +45 -32
  62. package/src/platform.ts +68 -71
@@ -24,7 +24,6 @@ export class Plug {
24
24
  connected?: boolean;
25
25
  switchbot!: switchbot;
26
26
  address!: ad['address'];
27
- SwitchToOpenAPI?: boolean;
28
27
  serviceData!: serviceData;
29
28
  state: serviceData['state'];
30
29
  delay: serviceData['delay'];
@@ -44,8 +43,8 @@ export class Plug {
44
43
  doPlugUpdate!: Subject<void>;
45
44
 
46
45
  // Connection
47
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
48
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
46
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
47
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
49
48
 
50
49
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
51
50
  // default placeholders
@@ -126,10 +125,9 @@ export class Plug {
126
125
  * Parse the device status from the SwitchBot api
127
126
  */
128
127
  async parseStatus(): Promise<void> {
129
- if (this.BLE && !this.SwitchToOpenAPI) {
128
+ if (this.BLE) {
130
129
  await this.BLEparseStatus();
131
130
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
132
- this.SwitchToOpenAPI = false;
133
131
  await this.openAPIparseStatus();
134
132
  } else {
135
133
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -233,20 +231,20 @@ export class Plug {
233
231
  // Stop to monitor
234
232
  switchbot.stopScan();
235
233
  if (this.connected) {
236
- this.parseStatus();
234
+ this.BLEparseStatus();
237
235
  this.updateHomeKitCharacteristics();
238
236
  } else {
239
- await this.BLEconnection(switchbot);
237
+ await this.BLERefreshConnection(switchbot);
240
238
  }
241
239
  })
242
240
  .catch(async (e: any) => {
243
241
  this.apiError(e);
244
242
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
245
243
  + ` Connection, Error Message: ${superStringify(e.message)}`);
246
- await this.BLEconnection(switchbot);
244
+ await this.BLERefreshConnection(switchbot);
247
245
  });
248
246
  } else {
249
- await this.BLEconnection(switchbot);
247
+ await this.BLERefreshConnection(switchbot);
250
248
  }
251
249
  }
252
250
 
@@ -285,7 +283,7 @@ export class Plug {
285
283
  this.deviceStatus = JSON.parse(rawData);
286
284
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
287
285
  this.power = this.deviceStatus.body.power;
288
- this.parseStatus();
286
+ this.openAPIparseStatus();
289
287
  this.updateHomeKitCharacteristics();
290
288
  } catch (e: any) {
291
289
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -357,10 +355,7 @@ export class Plug {
357
355
  this.apiError(e);
358
356
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
359
357
  + ` Connection, Error Message: ${superStringify(e.message)}`);
360
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
361
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
362
- await this.openAPIpushChanges();
363
- }
358
+ await this.BLEPushConnection();
364
359
  });
365
360
  } else {
366
361
  this.debugLog(
@@ -483,11 +478,17 @@ export class Plug {
483
478
  }
484
479
  }
485
480
 
486
- async BLEconnection(switchbot: any): Promise<void> {
481
+ async BLEPushConnection() {
482
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
483
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
484
+ await this.openAPIpushChanges();
485
+ }
486
+ }
487
+
488
+ async BLERefreshConnection(switchbot: any): Promise<void> {
487
489
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
488
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
489
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
490
- this.SwitchToOpenAPI = true;
490
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
491
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
491
492
  await this.openAPIRefreshStatus();
492
493
  }
493
494
  }
@@ -7,7 +7,7 @@ import superStringify from 'super-stringify';
7
7
  import { SwitchBotPlatform } from '../platform';
8
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
9
9
  import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
10
- import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath, ad, serviceData } from '../settings';
10
+ import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath, ad, serviceData, m2hs } from '../settings';
11
11
 
12
12
  /**
13
13
  * Platform Accessory
@@ -35,7 +35,6 @@ export class StripLight {
35
35
  connected?: boolean;
36
36
  switchbot!: switchbot;
37
37
  address!: ad['address'];
38
- SwitchToOpenAPI?: boolean;
39
38
  serviceData!: serviceData;
40
39
  state: serviceData['state'];
41
40
  delay: serviceData['delay'];
@@ -61,8 +60,8 @@ export class StripLight {
61
60
  doStripLightUpdate!: Subject<void>;
62
61
 
63
62
  // Connection
64
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
65
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
63
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
64
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
66
65
 
67
66
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
68
67
  // default placeholders
@@ -94,12 +93,12 @@ export class StripLight {
94
93
  `${accessory.displayName} ${device.deviceType}`;
95
94
 
96
95
 
97
- /*if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
96
+ if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
98
97
  this.accessory.removeService(this.lightBulbService);
99
98
  this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
100
99
  this.accessory.context.adaptiveLighting = false;
101
100
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
102
- }*/
101
+ }
103
102
 
104
103
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
105
104
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -126,6 +125,19 @@ export class StripLight {
126
125
  })
127
126
  .onSet(this.BrightnessSet.bind(this));
128
127
 
128
+ // handle ColorTemperature events using the ColorTemperature characteristic
129
+ this.lightBulbService
130
+ .getCharacteristic(this.platform.Characteristic.ColorTemperature)
131
+ .setProps({
132
+ minValue: 140,
133
+ maxValue: 500,
134
+ validValueRanges: [140, 500],
135
+ })
136
+ .onGet(() => {
137
+ return this.ColorTemperature!;
138
+ })
139
+ .onSet(this.ColorTemperatureSet.bind(this));
140
+
129
141
  // handle Hue events using the Hue characteristic
130
142
  this.lightBulbService
131
143
  .getCharacteristic(this.platform.Characteristic.Hue)
@@ -152,7 +164,7 @@ export class StripLight {
152
164
  })
153
165
  .onSet(this.SaturationSet.bind(this));
154
166
 
155
- /*this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
167
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
156
168
  if (this.adaptiveLightingShift !== -1) {
157
169
  this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
158
170
  customTemperatureAdjustment: this.adaptiveLightingShift,
@@ -163,7 +175,7 @@ export class StripLight {
163
175
  `${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
164
176
  ` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
165
177
  );
166
- }*/
178
+ }
167
179
 
168
180
  // Update Homekit
169
181
  this.updateHomeKitCharacteristics();
@@ -207,10 +219,9 @@ export class StripLight {
207
219
  * Parse the device status from the SwitchBot api
208
220
  */
209
221
  async parseStatus(): Promise<void> {
210
- /*if (this.BLE && !this.SwitchToOpenAPI) {
222
+ /*if (this.BLE) {
211
223
  await this.BLEparseStatus();
212
224
  } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
213
- this.SwitchToOpenAPI = false;
214
225
  await this.openAPIparseStatus();
215
226
  } else {
216
227
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -340,20 +351,20 @@ export class StripLight {
340
351
  // Stop to monitor
341
352
  switchbot.stopScan();
342
353
  if (this.connected) {
343
- this.parseStatus();
354
+ this.BLEparseStatus();
344
355
  this.updateHomeKitCharacteristics();
345
356
  } else {
346
- await this.BLEconnection(switchbot);
357
+ await this.BLERefreshConnection(switchbot);
347
358
  }
348
359
  })
349
360
  .catch(async (e: any) => {
350
361
  this.apiError(e);
351
362
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
352
363
  + ` Connection, Error Message: ${superStringify(e.message)}`);
353
- await this.BLEconnection(switchbot);
364
+ await this.BLERefreshConnection(switchbot);
354
365
  });
355
366
  } else {
356
- await this.BLEconnection(switchbot);
367
+ await this.BLERefreshConnection(switchbot);
357
368
  }
358
369
  }
359
370
 
@@ -394,7 +405,7 @@ export class StripLight {
394
405
  this.power = this.deviceStatus.body.power;
395
406
  this.color = this.deviceStatus.body.color;
396
407
  this.brightness = this.deviceStatus.body.brightness;
397
- this.parseStatus();
408
+ this.openAPIparseStatus();
398
409
  this.updateHomeKitCharacteristics();
399
410
  } catch (e: any) {
400
411
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -466,10 +477,7 @@ export class StripLight {
466
477
  this.apiError(e);
467
478
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
468
479
  + ` Connection, Error Message: ${superStringify(e.message)}`);
469
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
470
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
471
- await this.openAPIpushChanges();
472
- }
480
+ await this.BLEPushConnection();
473
481
  });
474
482
  } else {
475
483
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
@@ -694,7 +702,7 @@ export class StripLight {
694
702
  /**
695
703
  * Handle requests to set the value of the "ColorTemperature" characteristic
696
704
  */
697
- /*async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
705
+ async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
698
706
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
699
707
 
700
708
  // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
@@ -713,8 +721,8 @@ export class StripLight {
713
721
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
714
722
 
715
723
  this.ColorTemperature = value;
716
- this.doColorBulbUpdate.next();
717
- }*/
724
+ this.doStripLightUpdate.next();
725
+ }
718
726
 
719
727
  /**
720
728
  * Handle requests to set the value of the "Hue" characteristic
@@ -755,14 +763,13 @@ export class StripLight {
755
763
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
756
764
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
757
765
  }
758
- /*
759
766
  if (this.ColorTemperature === undefined) {
760
767
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
761
768
  } else {
762
769
  this.accessory.context.ColorTemperature = this.ColorTemperature;
763
770
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
764
771
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
765
- }*/
772
+ }
766
773
  if (this.Hue === undefined) {
767
774
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
768
775
  } else {
@@ -798,11 +805,17 @@ export class StripLight {
798
805
  }
799
806
  }
800
807
 
801
- async BLEconnection(switchbot: any): Promise<void> {
808
+ async BLEPushConnection() {
809
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
810
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
811
+ await this.openAPIpushChanges();
812
+ }
813
+ }
814
+
815
+ async BLERefreshConnection(switchbot: any): Promise<void> {
802
816
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
803
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
804
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
805
- this.SwitchToOpenAPI = true;
817
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
818
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
806
819
  await this.openAPIRefreshStatus();
807
820
  }
808
821
  }
@@ -851,7 +864,7 @@ export class StripLight {
851
864
  return this.set_minStep;
852
865
  }
853
866
 
854
- /*async adaptiveLighting(device: device & devicesConfig): Promise<void> {
867
+ async adaptiveLighting(device: device & devicesConfig): Promise<void> {
855
868
  if (device.colorbulb?.adaptiveLightingShift) {
856
869
  this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
857
870
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
@@ -859,7 +872,7 @@ export class StripLight {
859
872
  this.adaptiveLightingShift = 0;
860
873
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
861
874
  }
862
- }*/
875
+ }
863
876
 
864
877
  async scan(device: device & devicesConfig): Promise<void> {
865
878
  if (device.scanDuration) {
@@ -964,11 +977,11 @@ export class StripLight {
964
977
  } else {
965
978
  this.Saturation = this.accessory.context.Saturation;
966
979
  }
967
- /*if (this.ColorTemperature === undefined) {
980
+ if (this.ColorTemperature === undefined) {
968
981
  this.ColorTemperature = 140;
969
982
  } else {
970
983
  this.ColorTemperature = this.accessory.context.ColorTemperature;
971
- }*/
984
+ }
972
985
  this.minKelvin = 2000;
973
986
  this.maxKelvin = 9000;
974
987
  }