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

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 +0 -1
  3. package/dist/device/bot.d.ts.map +1 -1
  4. package/dist/device/bot.js +8 -10
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts +0 -1
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +6 -9
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts +0 -1
  11. package/dist/device/contact.d.ts.map +1 -1
  12. package/dist/device/contact.js +6 -8
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.d.ts +0 -1
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +7 -9
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/humidifier.d.ts +0 -1
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +7 -9
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +1 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +26 -7
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +0 -1
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +6 -8
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +0 -1
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +4 -6
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +0 -1
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +6 -8
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +0 -1
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +7 -9
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +2 -1
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +73 -68
  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 +8 -11
  52. package/src/device/colorbulb.ts +6 -10
  53. package/src/device/contact.ts +6 -9
  54. package/src/device/curtain.ts +7 -10
  55. package/src/device/humidifier.ts +7 -10
  56. package/src/device/lock.ts +27 -7
  57. package/src/device/meter.ts +6 -9
  58. package/src/device/meterplus.ts +4 -7
  59. package/src/device/motion.ts +6 -9
  60. package/src/device/plug.ts +7 -10
  61. package/src/device/striplight.ts +33 -24
  62. package/src/platform.ts +68 -71
@@ -39,7 +39,6 @@ export class Curtain {
39
39
  serviceData!: serviceData;
40
40
  spaceBetweenLevels!: number;
41
41
  address!: ad['address'];
42
- SwitchToOpenAPI?: boolean;
43
42
  calibration: serviceData['calibration'];
44
43
  battery: serviceData['battery'];
45
44
  position: serviceData['position'];
@@ -68,8 +67,8 @@ export class Curtain {
68
67
  doCurtainUpdate!: Subject<void>;
69
68
 
70
69
  // Connection
71
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
72
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
70
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
71
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
73
72
 
74
73
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
75
74
  // default placeholders
@@ -215,10 +214,9 @@ export class Curtain {
215
214
  * Parse the device status from the SwitchBot api
216
215
  */
217
216
  async parseStatus(): Promise<void> {
218
- if (this.BLE && !this.SwitchToOpenAPI) {
217
+ if (this.BLE) {
219
218
  await this.BLEparseStatus();
220
219
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
221
- this.SwitchToOpenAPI = false;
222
220
  await this.openAPIparseStatus();
223
221
  } else {
224
222
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -451,7 +449,7 @@ export class Curtain {
451
449
  // Stop to monitor
452
450
  switchbot.stopScan();
453
451
  if (this.connected) {
454
- this.parseStatus();
452
+ this.BLEparseStatus();
455
453
  this.updateHomeKitCharacteristics();
456
454
  } else {
457
455
  await this.BLEconnection(switchbot);
@@ -504,7 +502,7 @@ export class Curtain {
504
502
  this.slidePosition = this.deviceStatus.body.slidePosition;
505
503
  this.moving = this.deviceStatus.body.moving;
506
504
  this.brightness = this.deviceStatus.body.brightness;
507
- this.parseStatus();
505
+ this.openAPIparseStatus();
508
506
  this.updateHomeKitCharacteristics();
509
507
  } catch (e: any) {
510
508
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -568,7 +566,7 @@ export class Curtain {
568
566
  this.apiError(e);
569
567
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
570
568
  + ` Connection, Error Message: ${superStringify(e.message)}`);
571
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
569
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
572
570
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
573
571
  await this.openAPIpushChanges();
574
572
  }
@@ -812,9 +810,8 @@ export class Curtain {
812
810
 
813
811
  async BLEconnection(switchbot: any): Promise<void> {
814
812
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
815
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
813
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
816
814
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
817
- this.SwitchToOpenAPI = true;
818
815
  await this.openAPIRefreshStatus();
819
816
  }
820
817
  }
@@ -41,7 +41,6 @@ export class Humidifier {
41
41
  connected?: boolean;
42
42
  serviceData!: serviceData;
43
43
  address!: ad['address'];
44
- SwitchToOpenAPI?: boolean;
45
44
  onState!: serviceData['onState'];
46
45
  autoMode!: serviceData['autoMode'];
47
46
  percentage!: serviceData['percentage'];
@@ -57,8 +56,8 @@ export class Humidifier {
57
56
  doHumidifierUpdate!: Subject<void>;
58
57
 
59
58
  // Connection
60
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
61
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
59
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
60
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
62
61
 
63
62
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
64
63
  // default placeholders
@@ -193,10 +192,9 @@ export class Humidifier {
193
192
  * Parse the device status from the SwitchBot api
194
193
  */
195
194
  async parseStatus(): Promise<void> {
196
- if (this.BLE && !this.SwitchToOpenAPI) {
195
+ if (this.BLE) {
197
196
  await this.BLEparseStatus();
198
197
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
199
- this.SwitchToOpenAPI = false;
200
198
  await this.openAPIparseStatus();
201
199
  } else {
202
200
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -343,7 +341,7 @@ export class Humidifier {
343
341
  // Stop to monitor
344
342
  switchbot.stopScan();
345
343
  if (this.connected) {
346
- this.parseStatus();
344
+ this.BLEparseStatus();
347
345
  this.updateHomeKitCharacteristics();
348
346
  } else {
349
347
  await this.BLEconnection(switchbot);
@@ -399,7 +397,7 @@ export class Humidifier {
399
397
  this.humidity = this.deviceStatus.body.humidity;
400
398
  this.temperature = this.deviceStatus.body.temperature;
401
399
  this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
402
- this.parseStatus();
400
+ this.openAPIparseStatus();
403
401
  this.updateHomeKitCharacteristics();
404
402
  } catch (e: any) {
405
403
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -462,7 +460,7 @@ export class Humidifier {
462
460
  this.apiError(e);
463
461
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
464
462
  + ` Connection, Error Message: ${superStringify(e.message)}`);
465
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
463
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
466
464
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
467
465
  await this.openAPIpushChanges();
468
466
  }
@@ -779,9 +777,8 @@ export class Humidifier {
779
777
 
780
778
  async BLEconnection(switchbot: any): Promise<void> {
781
779
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
782
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
780
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
783
781
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
784
- this.SwitchToOpenAPI = true;
785
782
  await this.openAPIRefreshStatus();
786
783
  }
787
784
  }
@@ -34,8 +34,8 @@ export class Lock {
34
34
  doLockUpdate!: Subject<void>;
35
35
 
36
36
  // Connection
37
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
38
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
37
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
38
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
39
39
 
40
40
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
41
41
  // default placeholders
@@ -132,10 +132,9 @@ export class Lock {
132
132
  * Parse the device status from the SwitchBot api
133
133
  */
134
134
  async parseStatus(): Promise<void> {
135
- /*if (this.BLE && !this.SwitchToOpenAPI) {
135
+ /*if (this.BLE) {
136
136
  await this.BLEparseStatus();
137
- } else*/ if (this.OpenAPI) {
138
- //this.SwitchToOpenAPI = false;
137
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
139
138
  await this.openAPIparseStatus();
140
139
  } else {
141
140
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -143,6 +142,27 @@ export class Lock {
143
142
  }
144
143
  }
145
144
 
145
+ async BLEparseStatus(): Promise<void> {
146
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
147
+ switch (this.lockState) {
148
+ case 'locked':
149
+ this.LockCurrentState = this.platform.Characteristic.LockCurrentState.SECURED;
150
+ this.LockTargetState = this.platform.Characteristic.LockTargetState.SECURED;
151
+ break;
152
+ default:
153
+ this.LockCurrentState = this.platform.Characteristic.LockCurrentState.UNSECURED;
154
+ this.LockTargetState = this.platform.Characteristic.LockTargetState.UNSECURED;
155
+ }
156
+ switch (this.doorState) {
157
+ case 'opened':
158
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
159
+ break;
160
+ default:
161
+ this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
162
+ }
163
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
164
+ }
165
+
146
166
  //{"deviceId":"DBDC23B53139","deviceType":"Smart Lock","hubDeviceId":"E68B14109DA2","lockState":"locked","doorState":"opened","calibrate":true}
147
167
 
148
168
  async openAPIparseStatus(): Promise<void> {
@@ -215,7 +235,7 @@ export class Lock {
215
235
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
216
236
  this.lockState = this.deviceStatus.body.lockState;
217
237
  this.doorState = this.deviceStatus.body.doorState;
218
- this.parseStatus();
238
+ this.openAPIparseStatus();
219
239
  this.updateHomeKitCharacteristics();
220
240
  } catch (e: any) {
221
241
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -280,7 +300,7 @@ export class Lock {
280
300
  this.apiError(e);
281
301
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
282
302
  + ` Connection, Error Message: ${superStringify(e.message)}`);
283
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
303
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
284
304
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
285
305
  await this.openAPIpushChanges();
286
306
  }
@@ -40,7 +40,6 @@ export class Meter {
40
40
  switchbot!: switchbot;
41
41
  serviceData!: serviceData;
42
42
  address!: ad['address'];
43
- SwitchToOpenAPI?: boolean;
44
43
  temperature!: temperature['c'];
45
44
  battery!: serviceData['battery'];
46
45
  humidity!: serviceData['humidity'];
@@ -61,8 +60,8 @@ export class Meter {
61
60
  doMeterUpdate: 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
@@ -177,10 +176,9 @@ export class Meter {
177
176
  * Parse the device status from the SwitchBot api
178
177
  */
179
178
  async parseStatus(): Promise<void> {
180
- if (this.BLE && !this.SwitchToOpenAPI) {
179
+ if (this.BLE) {
181
180
  await this.BLEparseStatus();
182
181
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
183
- this.SwitchToOpenAPI = false;
184
182
  await this.openAPIparseStatus();
185
183
  } else {
186
184
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -299,7 +297,7 @@ export class Meter {
299
297
  // Stop to monitor
300
298
  switchbot.stopScan();
301
299
  if (this.connected) {
302
- this.parseStatus();
300
+ this.BLEparseStatus();
303
301
  this.updateHomeKitCharacteristics();
304
302
  } else {
305
303
  await this.BLEconnection(switchbot);
@@ -351,7 +349,7 @@ export class Meter {
351
349
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
352
350
  this.Humidity = this.deviceStatus.body.humidity!;
353
351
  this.Temperature = this.deviceStatus.body.temperature!;
354
- this.parseStatus();
352
+ this.openAPIparseStatus();
355
353
  this.updateHomeKitCharacteristics();
356
354
  } catch (e: any) {
357
355
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -493,9 +491,8 @@ export class Meter {
493
491
 
494
492
  async BLEconnection(switchbot: any): Promise<void> {
495
493
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
496
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
494
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
497
495
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
498
- this.SwitchToOpenAPI = true;
499
496
  await this.openAPIRefreshStatus();
500
497
  }
501
498
  }
@@ -40,7 +40,6 @@ export class MeterPlus {
40
40
  switchbot!: switchbot;
41
41
  serviceData!: serviceData;
42
42
  address!: ad['address'];
43
- SwitchToOpenAPI?: boolean;
44
43
  temperature!: temperature['c'];
45
44
  battery!: serviceData['battery'];
46
45
  humidity!: serviceData['humidity'];
@@ -61,8 +60,8 @@ export class MeterPlus {
61
60
  doMeterUpdate: 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
@@ -177,10 +176,9 @@ export class MeterPlus {
177
176
  * Parse the device status from the SwitchBot api
178
177
  */
179
178
  async parseStatus(): Promise<void> {
180
- if (this.BLE && !this.SwitchToOpenAPI) {
179
+ if (this.BLE) {
181
180
  await this.BLEparseStatus();
182
181
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
183
- this.SwitchToOpenAPI = false;
184
182
  await this.openAPIparseStatus();
185
183
  } else {
186
184
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -492,9 +490,8 @@ export class MeterPlus {
492
490
 
493
491
  async BLEconnection(switchbot: any): Promise<void> {
494
492
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
495
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
493
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
496
494
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
497
- this.SwitchToOpenAPI = true;
498
495
  await this.openAPIRefreshStatus();
499
496
  }
500
497
  }
@@ -36,7 +36,6 @@ export class Motion {
36
36
  switchbot!: switchbot;
37
37
  serviceData!: serviceData;
38
38
  address!: ad['address'];
39
- SwitchToOpenAPI?: boolean;
40
39
  battery!: serviceData['battery'];
41
40
  movement!: serviceData['movement'];
42
41
  lightLevel!: serviceData['lightLevel'];
@@ -53,8 +52,8 @@ export class Motion {
53
52
  doMotionUpdate!: Subject<void>;
54
53
 
55
54
  // Connection
56
- private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
57
- private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
55
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
56
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
58
57
 
59
58
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
60
59
  // default placeholders
@@ -143,10 +142,9 @@ export class Motion {
143
142
  * Parse the device status from the SwitchBot api
144
143
  */
145
144
  async parseStatus(): Promise<void> {
146
- if (this.BLE && !this.SwitchToOpenAPI) {
145
+ if (this.BLE) {
147
146
  await this.BLEparseStatus();
148
147
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
149
- this.SwitchToOpenAPI = false;
150
148
  await this.openAPIparseStatus();
151
149
  } else {
152
150
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
@@ -279,7 +277,7 @@ export class Motion {
279
277
  // Stop to monitor
280
278
  switchbot.stopScan();
281
279
  if (this.connected) {
282
- this.parseStatus();
280
+ this.BLEparseStatus();
283
281
  this.updateHomeKitCharacteristics();
284
282
  } else {
285
283
  await this.BLEconnection(switchbot);
@@ -332,7 +330,7 @@ export class Motion {
332
330
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
333
331
  this.moveDetected = this.deviceStatus.body.moveDetected;
334
332
  this.brightness = this.deviceStatus.body.brightness;
335
- this.parseStatus();
333
+ this.openAPIparseStatus();
336
334
  this.updateHomeKitCharacteristics();
337
335
  } catch (e: any) {
338
336
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
@@ -409,9 +407,8 @@ export class Motion {
409
407
 
410
408
  async BLEconnection(switchbot: any): Promise<void> {
411
409
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
412
- if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
410
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
413
411
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
414
- this.SwitchToOpenAPI = true;
415
412
  await this.openAPIRefreshStatus();
416
413
  }
417
414
  }
@@ -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,7 +231,7 @@ 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
237
  await this.BLEconnection(switchbot);
@@ -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,7 +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') {
358
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
361
359
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
362
360
  await this.openAPIpushChanges();
363
361
  }
@@ -485,9 +483,8 @@ export class Plug {
485
483
 
486
484
  async BLEconnection(switchbot: any): Promise<void> {
487
485
  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') {
486
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
489
487
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
490
- this.SwitchToOpenAPI = true;
491
488
  await this.openAPIRefreshStatus();
492
489
  }
493
490
  }
@@ -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,7 +351,7 @@ 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
357
  await this.BLEconnection(switchbot);
@@ -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,7 +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') {
480
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
470
481
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
471
482
  await this.openAPIpushChanges();
472
483
  }
@@ -694,7 +705,7 @@ export class StripLight {
694
705
  /**
695
706
  * Handle requests to set the value of the "ColorTemperature" characteristic
696
707
  */
697
- /*async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
708
+ async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
698
709
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
699
710
 
700
711
  // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
@@ -713,8 +724,8 @@ export class StripLight {
713
724
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
714
725
 
715
726
  this.ColorTemperature = value;
716
- this.doColorBulbUpdate.next();
717
- }*/
727
+ this.doStripLightUpdate.next();
728
+ }
718
729
 
719
730
  /**
720
731
  * Handle requests to set the value of the "Hue" characteristic
@@ -755,14 +766,13 @@ export class StripLight {
755
766
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
756
767
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
757
768
  }
758
- /*
759
769
  if (this.ColorTemperature === undefined) {
760
770
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
761
771
  } else {
762
772
  this.accessory.context.ColorTemperature = this.ColorTemperature;
763
773
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
764
774
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
765
- }*/
775
+ }
766
776
  if (this.Hue === undefined) {
767
777
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
768
778
  } else {
@@ -800,9 +810,8 @@ export class StripLight {
800
810
 
801
811
  async BLEconnection(switchbot: any): Promise<void> {
802
812
  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') {
813
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'BLE/OpenAPI') {
804
814
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
805
- this.SwitchToOpenAPI = true;
806
815
  await this.openAPIRefreshStatus();
807
816
  }
808
817
  }
@@ -851,7 +860,7 @@ export class StripLight {
851
860
  return this.set_minStep;
852
861
  }
853
862
 
854
- /*async adaptiveLighting(device: device & devicesConfig): Promise<void> {
863
+ async adaptiveLighting(device: device & devicesConfig): Promise<void> {
855
864
  if (device.colorbulb?.adaptiveLightingShift) {
856
865
  this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
857
866
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
@@ -859,7 +868,7 @@ export class StripLight {
859
868
  this.adaptiveLightingShift = 0;
860
869
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
861
870
  }
862
- }*/
871
+ }
863
872
 
864
873
  async scan(device: device & devicesConfig): Promise<void> {
865
874
  if (device.scanDuration) {
@@ -964,11 +973,11 @@ export class StripLight {
964
973
  } else {
965
974
  this.Saturation = this.accessory.context.Saturation;
966
975
  }
967
- /*if (this.ColorTemperature === undefined) {
976
+ if (this.ColorTemperature === undefined) {
968
977
  this.ColorTemperature = 140;
969
978
  } else {
970
979
  this.ColorTemperature = this.accessory.context.ColorTemperature;
971
- }*/
980
+ }
972
981
  this.minKelvin = 2000;
973
982
  this.maxKelvin = 9000;
974
983
  }