@switchbot/homebridge-switchbot 2.2.2-beta.9 → 2.2.3-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.
Files changed (107) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/config.schema.json +18 -42
  3. package/dist/device/bot.d.ts +1 -3
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +1 -1
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/ceilinglight.d.ts +1 -3
  8. package/dist/device/ceilinglight.d.ts.map +1 -1
  9. package/dist/device/ceilinglight.js +1 -1
  10. package/dist/device/ceilinglight.js.map +1 -1
  11. package/dist/device/colorbulb.d.ts +1 -3
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +3 -3
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/contact.d.ts +6 -7
  16. package/dist/device/contact.d.ts.map +1 -1
  17. package/dist/device/contact.js +17 -2
  18. package/dist/device/contact.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +7 -9
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +13 -15
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/meter.d.ts +1 -3
  24. package/dist/device/meter.d.ts.map +1 -1
  25. package/dist/device/meter.js +1 -1
  26. package/dist/device/meter.js.map +1 -1
  27. package/dist/device/meterplus.d.ts +1 -3
  28. package/dist/device/meterplus.d.ts.map +1 -1
  29. package/dist/device/meterplus.js +1 -1
  30. package/dist/device/meterplus.js.map +1 -1
  31. package/dist/device/motion.d.ts +2 -3
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +15 -3
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +1 -3
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +1 -1
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/device/striplight.d.ts +1 -3
  40. package/dist/device/striplight.d.ts.map +1 -1
  41. package/dist/device/striplight.js +9 -7
  42. package/dist/device/striplight.js.map +1 -1
  43. package/dist/irdevice/airconditioner.d.ts +10 -6
  44. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  45. package/dist/irdevice/airconditioner.js +65 -54
  46. package/dist/irdevice/airconditioner.js.map +1 -1
  47. package/dist/irdevice/airpurifier.d.ts +8 -8
  48. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  49. package/dist/irdevice/airpurifier.js +29 -29
  50. package/dist/irdevice/airpurifier.js.map +1 -1
  51. package/dist/irdevice/camera.d.ts +4 -4
  52. package/dist/irdevice/camera.d.ts.map +1 -1
  53. package/dist/irdevice/camera.js +20 -24
  54. package/dist/irdevice/camera.js.map +1 -1
  55. package/dist/irdevice/fan.d.ts +4 -4
  56. package/dist/irdevice/fan.d.ts.map +1 -1
  57. package/dist/irdevice/fan.js +22 -26
  58. package/dist/irdevice/fan.js.map +1 -1
  59. package/dist/irdevice/light.d.ts +4 -4
  60. package/dist/irdevice/light.d.ts.map +1 -1
  61. package/dist/irdevice/light.js +20 -20
  62. package/dist/irdevice/light.js.map +1 -1
  63. package/dist/irdevice/other.d.ts +4 -4
  64. package/dist/irdevice/other.d.ts.map +1 -1
  65. package/dist/irdevice/other.js +20 -24
  66. package/dist/irdevice/other.js.map +1 -1
  67. package/dist/irdevice/tv.d.ts +10 -6
  68. package/dist/irdevice/tv.d.ts.map +1 -1
  69. package/dist/irdevice/tv.js +128 -90
  70. package/dist/irdevice/tv.js.map +1 -1
  71. package/dist/irdevice/vacuumcleaner.d.ts +4 -4
  72. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  73. package/dist/irdevice/vacuumcleaner.js +20 -24
  74. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  75. package/dist/irdevice/waterheater.d.ts +4 -4
  76. package/dist/irdevice/waterheater.d.ts.map +1 -1
  77. package/dist/irdevice/waterheater.js +26 -31
  78. package/dist/irdevice/waterheater.js.map +1 -1
  79. package/dist/platform.d.ts +0 -1
  80. package/dist/platform.d.ts.map +1 -1
  81. package/dist/platform.js +29 -35
  82. package/dist/platform.js.map +1 -1
  83. package/dist/settings.d.ts +10 -19
  84. package/dist/settings.d.ts.map +1 -1
  85. package/dist/settings.js.map +1 -1
  86. package/package.json +9 -9
  87. package/src/device/bot.ts +1 -1
  88. package/src/device/ceilinglight.ts +1 -1
  89. package/src/device/colorbulb.ts +3 -3
  90. package/src/device/contact.ts +24 -10
  91. package/src/device/humidifier.ts +11 -15
  92. package/src/device/meter.ts +1 -1
  93. package/src/device/meterplus.ts +1 -1
  94. package/src/device/motion.ts +18 -7
  95. package/src/device/plug.ts +1 -1
  96. package/src/device/striplight.ts +5 -5
  97. package/src/irdevice/airconditioner.ts +71 -58
  98. package/src/irdevice/airpurifier.ts +34 -33
  99. package/src/irdevice/camera.ts +23 -26
  100. package/src/irdevice/fan.ts +25 -28
  101. package/src/irdevice/light.ts +23 -22
  102. package/src/irdevice/other.ts +23 -26
  103. package/src/irdevice/tv.ts +132 -93
  104. package/src/irdevice/vacuumcleaner.ts +23 -26
  105. package/src/irdevice/waterheater.ts +28 -32
  106. package/src/platform.ts +28 -34
  107. package/src/settings.ts +13 -28
package/src/device/bot.ts CHANGED
@@ -1063,7 +1063,7 @@ export class Bot {
1063
1063
  }
1064
1064
  }
1065
1065
 
1066
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
1066
+ async stopScanning(switchbot: any) {
1067
1067
  await switchbot.stopScan();
1068
1068
  if (this.connected) {
1069
1069
  await this.BLEparseStatus();
@@ -909,7 +909,7 @@ export class CeilingLight {
909
909
  }
910
910
  }
911
911
 
912
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
912
+ async stopScanning(switchbot: any) {
913
913
  await switchbot.stopScan();
914
914
  if (this.connected) {
915
915
  await this.BLEparseStatus();
@@ -392,7 +392,7 @@ export class ColorBulb {
392
392
  if (this.serviceData) {
393
393
  this.connected = true;
394
394
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
395
- await this.stopScanning({ switchbot });
395
+ await this.stopScanning(switchbot);
396
396
  } else {
397
397
  this.connected = false;
398
398
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -403,7 +403,7 @@ export class ColorBulb {
403
403
  })
404
404
  .then(async () => {
405
405
  // Stop to monitor
406
- await this.stopScanning({ switchbot });
406
+ await this.stopScanning(switchbot);
407
407
  })
408
408
  .catch(async (e: any) => {
409
409
  this.apiError(e);
@@ -1065,7 +1065,7 @@ export class ColorBulb {
1065
1065
  }
1066
1066
  }
1067
1067
 
1068
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
1068
+ async stopScanning(switchbot: any) {
1069
1069
  await switchbot.stopScan();
1070
1070
  if (this.connected) {
1071
1071
  await this.BLEparseStatus();
@@ -35,7 +35,12 @@ export class Contact {
35
35
  deviceStatus!: any; //deviceStatusResponse;
36
36
 
37
37
  // BLE Others
38
+ tested!: any;
39
+ contact_open!: any;
40
+ button_count!: any;
41
+ scanning!: boolean;
38
42
  connected?: boolean;
43
+ contact_timeout!: any;
39
44
  switchbot!: switchbot;
40
45
  serviceData!: serviceData;
41
46
  address!: ad['address'];
@@ -43,10 +48,6 @@ export class Contact {
43
48
  movement!: serviceData['movement'];
44
49
  doorState!: serviceData['doorState'];
45
50
  is_light!: any; //serviceData['lightLevel'];
46
- tested!: any;
47
- contact_open!: any;
48
- contact_timeout!: any;
49
- button_count!: any;
50
51
 
51
52
  // Config
52
53
  set_minLux!: number;
@@ -195,10 +196,18 @@ export class Contact {
195
196
  default:
196
197
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
197
198
  }
199
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
200
+ if ((this.ContactSensorState !== this.accessory.context.ContactSensorState)
201
+ && this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED) {
202
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Opened`);
203
+ }
198
204
  // Movement
199
205
  if (!this.device.contact?.hide_motionsensor) {
200
206
  this.MotionDetected = Boolean(this.movement);
201
207
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
208
+ if ((this.MotionDetected !== this.accessory.context.MotionDetected) && this.MotionDetected) {
209
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
210
+ }
202
211
  }
203
212
  // Light Level
204
213
  if (!this.device.contact?.hide_lightsensor) {
@@ -211,10 +220,11 @@ export class Contact {
211
220
  default:
212
221
  this.CurrentAmbientLightLevel = this.set_maxLux;
213
222
  }
214
- this.debugLog(
215
- `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.is_light},` +
216
- ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
217
- );
223
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.is_light},` +
224
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
225
+ if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
226
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
227
+ }
218
228
  }
219
229
  // Battery
220
230
  if (this.battery === undefined) {
@@ -301,6 +311,7 @@ export class Contact {
301
311
  })
302
312
  .then(async () => {
303
313
  // Set an event hander
314
+ this.scanning = true;
304
315
  switchbot.onadvertisement = async (ad: any) => {
305
316
  this.address = ad.address;
306
317
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
@@ -324,6 +335,7 @@ export class Contact {
324
335
  this.connected = true;
325
336
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
326
337
  await this.stopScanning(switchbot);
338
+ this.scanning = false;
327
339
  } else {
328
340
  this.connected = false;
329
341
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -334,7 +346,9 @@ export class Contact {
334
346
  })
335
347
  .then(async () => {
336
348
  // Stop to monitor
337
- await this.stopScanning(switchbot);
349
+ if (this.scanning) {
350
+ await this.stopScanning(switchbot);
351
+ }
338
352
  })
339
353
  .catch(async (e: any) => {
340
354
  this.apiError(e);
@@ -450,7 +464,7 @@ export class Contact {
450
464
  }
451
465
  }
452
466
 
453
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
467
+ async stopScanning(switchbot: any) {
454
468
  await switchbot.stopScan();
455
469
  if (this.connected) {
456
470
  await this.BLEparseStatus();
@@ -765,7 +765,7 @@ export class Humidifier {
765
765
  }
766
766
  }
767
767
 
768
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
768
+ async stopScanning(switchbot: any) {
769
769
  await switchbot.stopScan();
770
770
  if (this.connected) {
771
771
  await this.BLEparseStatus();
@@ -923,21 +923,17 @@ export class Humidifier {
923
923
  }
924
924
  if (this.TargetHumidifierDehumidifierState === undefined) {
925
925
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
926
+ } else if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
927
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
926
928
  } else {
927
929
  this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
928
- if (this.accessory.context.TargetHumidifierDehumidifierState === undefined) {
929
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
930
- }
931
- this.warnLog(this.TargetHumidifierDehumidifierState);
932
930
  }
933
931
  if (this.CurrentHumidifierDehumidifierState === undefined) {
934
932
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
933
+ } else if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
934
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
935
935
  } else {
936
936
  this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
937
- if (this.accessory.context.CurrentHumidifierDehumidifierState === undefined) {
938
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
939
- }
940
- this.warnLog(this.CurrentHumidifierDehumidifierState);
941
937
  }
942
938
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
943
939
  this.RelativeHumidityHumidifierThreshold = 0;
@@ -1008,19 +1004,19 @@ export class Humidifier {
1008
1004
  /**
1009
1005
  * Logging for Device
1010
1006
  */
1011
- infoLog(...log: any[]): void {
1007
+ async infoLog(...log: any[]): Promise<void> {
1012
1008
  if (this.enablingDeviceLogging()) {
1013
1009
  this.platform.log.info(String(...log));
1014
1010
  }
1015
1011
  }
1016
1012
 
1017
- warnLog(...log: any[]): void {
1013
+ async warnLog(...log: any[]): Promise<void> {
1018
1014
  if (this.enablingDeviceLogging()) {
1019
1015
  this.platform.log.warn(String(...log));
1020
1016
  }
1021
1017
  }
1022
1018
 
1023
- debugWarnLog(...log: any[]): void {
1019
+ async debugWarnLog(...log: any[]): Promise<void> {
1024
1020
  if (this.enablingDeviceLogging()) {
1025
1021
  if (this.deviceLogging?.includes('debug')) {
1026
1022
  this.platform.log.warn('[DEBUG]', String(...log));
@@ -1028,13 +1024,13 @@ export class Humidifier {
1028
1024
  }
1029
1025
  }
1030
1026
 
1031
- errorLog(...log: any[]): void {
1027
+ async errorLog(...log: any[]): Promise<void> {
1032
1028
  if (this.enablingDeviceLogging()) {
1033
1029
  this.platform.log.error(String(...log));
1034
1030
  }
1035
1031
  }
1036
1032
 
1037
- debugErrorLog(...log: any[]): void {
1033
+ async debugErrorLog(...log: any[]): Promise<void> {
1038
1034
  if (this.enablingDeviceLogging()) {
1039
1035
  if (this.deviceLogging?.includes('debug')) {
1040
1036
  this.platform.log.error('[DEBUG]', String(...log));
@@ -1042,7 +1038,7 @@ export class Humidifier {
1042
1038
  }
1043
1039
  }
1044
1040
 
1045
- debugLog(...log: any[]): void {
1041
+ async debugLog(...log: any[]): Promise<void> {
1046
1042
  if (this.enablingDeviceLogging()) {
1047
1043
  if (this.deviceLogging === 'debug') {
1048
1044
  this.platform.log.info('[DEBUG]', String(...log));
@@ -488,7 +488,7 @@ export class Meter {
488
488
  : null;
489
489
  }
490
490
 
491
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
491
+ async stopScanning(switchbot: any) {
492
492
  await switchbot.stopScan();
493
493
  if (this.connected) {
494
494
  await this.BLEparseStatus();
@@ -487,7 +487,7 @@ export class MeterPlus {
487
487
  : null;
488
488
  }
489
489
 
490
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
490
+ async stopScanning(switchbot: any) {
491
491
  await switchbot.stopScan();
492
492
  if (this.connected) {
493
493
  await this.BLEparseStatus();
@@ -32,6 +32,7 @@ export class Motion {
32
32
  brightness: deviceStatus['brightness'];
33
33
 
34
34
  // BLE Others
35
+ scanning!: boolean;
35
36
  connected?: boolean;
36
37
  switchbot!: switchbot;
37
38
  serviceData!: serviceData;
@@ -165,6 +166,9 @@ export class Motion {
165
166
  // Movement
166
167
  this.MotionDetected = this.movement!;
167
168
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
169
+ if ((this.MotionDetected !== this.accessory.context.MotionDetected) && this.MotionDetected) {
170
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
171
+ }
168
172
  // Light Level
169
173
  if (!this.device.motion?.hide_lightsensor) {
170
174
  this.set_minLux = this.minLux();
@@ -177,10 +181,11 @@ export class Motion {
177
181
  default:
178
182
  this.CurrentAmbientLightLevel = this.set_maxLux;
179
183
  }
180
- this.debugLog(
181
- `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
182
- ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
183
- );
184
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
185
+ ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
186
+ if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
187
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
188
+ }
184
189
  }
185
190
  // Battery
186
191
  if (this.battery === undefined) {
@@ -255,6 +260,7 @@ export class Motion {
255
260
  })
256
261
  .then(async () => {
257
262
  // Set an event hander
263
+ this.scanning = true;
258
264
  switchbot.onadvertisement = async (ad: any) => {
259
265
  this.address = ad.address;
260
266
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
@@ -278,6 +284,8 @@ export class Motion {
278
284
  this.connected = true;
279
285
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
280
286
  await this.stopScanning(switchbot);
287
+ this.scanning = false;
288
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
281
289
  } else {
282
290
  this.connected = false;
283
291
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
@@ -288,7 +296,10 @@ export class Motion {
288
296
  })
289
297
  .then(async () => {
290
298
  // Stop to monitor
291
- await this.stopScanning(switchbot);
299
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} scanning: ${this.scanning}`);
300
+ if (this.scanning) {
301
+ await this.stopScanning(switchbot);
302
+ }
292
303
  })
293
304
  .catch(async (e: any) => {
294
305
  this.apiError(e);
@@ -394,8 +405,8 @@ export class Motion {
394
405
  }
395
406
  }
396
407
 
397
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
398
- await await switchbot.stopScan();
408
+ async stopScanning(switchbot: any) {
409
+ await switchbot.stopScan();
399
410
  if (this.connected) {
400
411
  await this.BLEparseStatus();
401
412
  await this.updateHomeKitCharacteristics();
@@ -458,7 +458,7 @@ export class Plug {
458
458
  }
459
459
  }
460
460
 
461
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
461
+ async stopScanning(switchbot: any) {
462
462
  await switchbot.stopScan();
463
463
  if (this.connected) {
464
464
  await this.BLEparseStatus();
@@ -215,9 +215,9 @@ export class StripLight {
215
215
  async parseStatus(): Promise<void> {
216
216
  if (!this.device.enableCloudService && this.OpenAPI) {
217
217
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
218
- } else/*if (this.BLE) {
218
+ } else if (this.BLE) {
219
219
  await this.BLEparseStatus();
220
- } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
220
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
221
221
  await this.openAPIparseStatus();
222
222
  } else {
223
223
  await this.offlineOff();
@@ -282,9 +282,9 @@ export class StripLight {
282
282
  async refreshStatus(): Promise<void> {
283
283
  if (!this.device.enableCloudService && this.OpenAPI) {
284
284
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
285
- } else/*if (this.BLE) {
285
+ } else if (this.BLE) {
286
286
  await this.BLERefreshStatus();
287
- } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
287
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
288
288
  await this.openAPIRefreshStatus();
289
289
  } else {
290
290
  await this.offlineOff();
@@ -830,7 +830,7 @@ export class StripLight {
830
830
  }
831
831
  }
832
832
 
833
- async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
833
+ async stopScanning(switchbot: any) {
834
834
  await switchbot.stopScan();
835
835
  if (this.connected) {
836
836
  await this.BLEparseStatus();
@@ -3,7 +3,7 @@ import crypto from 'crypto';
3
3
  import { IncomingMessage } from 'http';
4
4
  import superStringify from 'super-stringify';
5
5
  import { SwitchBotPlatform } from '../platform';
6
- import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
6
+ import { irDevicesConfig, irdevice, HostDomain, DevicePath, body } from '../settings';
7
7
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
8
8
 
9
9
  /**
@@ -36,8 +36,9 @@ export class AirConditioner {
36
36
  static MODE_HEAT: number;
37
37
 
38
38
  // Config
39
- allowPushOn?: boolean;
40
- allowPushOff?: boolean;
39
+ disablePushOn?: boolean;
40
+ disablePushOff?: boolean;
41
+ disablePushDetail?: boolean;
41
42
  deviceLogging!: string;
42
43
  hide_automode?: boolean;
43
44
 
@@ -49,8 +50,9 @@ export class AirConditioner {
49
50
  this.logs({ device });
50
51
  this.config({ device });
51
52
  this.context();
52
- this.allowPushOnChanges({ device });
53
- this.allowPushOffChanges({ device });
53
+ this.disablePushOnChanges({ device });
54
+ this.disablePushOffChanges({ device });
55
+ this.disablePushDetailChanges({ device });
54
56
 
55
57
  // set accessory information
56
58
  accessory
@@ -65,7 +67,7 @@ export class AirConditioner {
65
67
  // get the Television service if it exists, otherwise create a new Television service
66
68
  // you can create multiple services for each accessory
67
69
  (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
68
- `${accessory.displayName} Air Conditioner`;
70
+ `${accessory.displayName} ${device.remoteType}`;
69
71
 
70
72
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
71
73
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -166,8 +168,8 @@ export class AirConditioner {
166
168
  */
167
169
  async pushAirConditionerOnChanges(): Promise<void> {
168
170
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.Active},`
169
- + ` allowPushOn: ${this.allowPushOn}`);
170
- if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
171
+ + ` disablePushOn: ${this.disablePushOn}`);
172
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
171
173
  const commandType: string = await this.commandType();
172
174
  const command: string = await this.commandOn();
173
175
  const body = superStringify({
@@ -181,8 +183,8 @@ export class AirConditioner {
181
183
 
182
184
  async pushAirConditionerOffChanges(): Promise<void> {
183
185
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.Active},`
184
- + ` allowPushOff: ${this.allowPushOff}`);
185
- if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOff) {
186
+ + ` disablePushOff: ${this.disablePushOff}`);
187
+ if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
186
188
  const commandType: string = await this.commandType();
187
189
  const command: string = await this.commandOff();
188
190
  const body = superStringify({
@@ -195,6 +197,8 @@ export class AirConditioner {
195
197
  }
196
198
 
197
199
  async pushAirConditionerStatusChanges(): Promise<void> {
200
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},`
201
+ + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
198
202
  if (!this.Busy) {
199
203
  this.Busy = true;
200
204
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
@@ -206,7 +210,9 @@ export class AirConditioner {
206
210
  }
207
211
 
208
212
  async pushAirConditionerDetailsChanges(): Promise<void> {
209
- await this.context();
213
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},`
214
+ + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
215
+ //await this.context();
210
216
  if (this.CurrentMode === undefined) {
211
217
  this.CurrentMode = 1;
212
218
  }
@@ -246,10 +252,11 @@ export class AirConditioner {
246
252
  await this.pushChanges(body);
247
253
  }
248
254
 
249
- async pushChanges(body: any): Promise<void> {
250
- if (this.device.connectionType === 'OpenAPI') {
255
+ async pushChanges(body: Array<body>): Promise<void> {
256
+ if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
251
257
  try {
252
- // Make Push On request to the API
258
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${body}`);
259
+ // Make Push On request to the API
253
260
  const t = Date.now();
254
261
  const nonce = 'requestID';
255
262
  const data = this.platform.config.credentials?.token + t + nonce;
@@ -286,11 +293,6 @@ export class AirConditioner {
286
293
  req.write(body);
287
294
  req.end();
288
295
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
289
- //this.accessory.context.CurrentTemperature = this.CurrentTemperature;
290
- this.HeatingThresholdTemperature = this.CurrentTemperature;
291
- this.CoolingThresholdTemperature = this.CurrentTemperature;
292
- //this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
293
- //this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
294
296
  this.updateHomeKitCharacteristics();
295
297
  } catch (e: any) {
296
298
  this.apiError({ e });
@@ -301,18 +303,19 @@ export class AirConditioner {
301
303
  } else {
302
304
  this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
303
305
  + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
306
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
307
+ + ` Connection Type: ${this.device.connectionType}, disablePushDetials: ${this.disablePushDetail}`);
308
+ this.updateHomeKitCharacteristics();
304
309
  }
305
310
  }
306
311
 
307
312
  async CurrentTemperatureGet(): Promise<CharacteristicValue> {
308
313
  if (this.CurrentTemperature === undefined) {
309
314
  this.CurrentTemperature = 24;
310
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
311
315
  } else {
312
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
316
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
313
317
  }
314
318
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
315
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
316
319
  return this.CurrentTemperature;
317
320
  }
318
321
 
@@ -325,7 +328,6 @@ export class AirConditioner {
325
328
  this.RotationSpeed = this.CurrentFanSpeed - 1;
326
329
  }
327
330
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
328
- this.accessory.context.RotationSpeed = this.RotationSpeed;
329
331
  return this.RotationSpeed;
330
332
  }
331
333
 
@@ -341,22 +343,19 @@ export class AirConditioner {
341
343
 
342
344
  async ActiveSet(value: CharacteristicValue): Promise<void> {
343
345
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
344
- if (value === this.platform.Characteristic.Active.INACTIVE) {
345
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
346
- this.pushAirConditionerOffChanges();
347
- } else {
346
+
347
+ this.Active = value;
348
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
348
349
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
349
- if (this.allowPushOn) {
350
- this.pushAirConditionerOnChanges();
351
- } else {
350
+ if (this.disablePushOn) {
352
351
  this.pushAirConditionerStatusChanges();
352
+ } else {
353
+ this.pushAirConditionerOnChanges();
353
354
  }
355
+ } else {
356
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
357
+ this.pushAirConditionerOffChanges();
354
358
  }
355
- /**
356
- * pushAirConditionerOnChanges and pushAirConditionerOffChanges above assume they are measuring the state of the accessory BEFORE
357
- * they are updated, so we are only updating the accessory state after calling the above.
358
- */
359
- this.Active = value;
360
359
  }
361
360
 
362
361
  async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
@@ -379,7 +378,6 @@ export class AirConditioner {
379
378
  ` ValidValues: ${this.ValidValues}`,
380
379
  );
381
380
  }
382
- this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
383
381
  return this.TargetHeaterCoolerState;
384
382
  }
385
383
 
@@ -435,7 +433,6 @@ export class AirConditioner {
435
433
 
436
434
  async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
437
435
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
438
- await this.context();
439
436
  if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
440
437
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
441
438
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
@@ -450,15 +447,11 @@ export class AirConditioner {
450
447
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
451
448
  +` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
452
449
  }
453
- this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
454
450
  return this.CurrentHeaterCoolerState;
455
451
  }
456
452
 
457
453
  async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
458
454
  await this.context();
459
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
460
- this.HeatingThresholdTemperature = this.accessory.context.CurrentTemperature;
461
- this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
462
455
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
463
456
  return this.HeatingThresholdTemperature;
464
457
  }
@@ -472,9 +465,6 @@ export class AirConditioner {
472
465
 
473
466
  async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
474
467
  await this.context();
475
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
476
- this.CoolingThresholdTemperature = this.accessory.context.CurrentTemperature;
477
- this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
478
468
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
479
469
  return this.CoolingThresholdTemperature;
480
470
  }
@@ -549,19 +539,27 @@ export class AirConditioner {
549
539
  }
550
540
  }
551
541
 
552
- async allowPushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
553
- if (device.allowPushOn) {
554
- this.allowPushOn = true;
542
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
543
+ if (device.disablePushOn === undefined) {
544
+ this.disablePushOn = false;
545
+ } else {
546
+ this.disablePushOn = device.disablePushOn;
547
+ }
548
+ }
549
+
550
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
551
+ if (device.disablePushOff === undefined) {
552
+ this.disablePushOff = false;
555
553
  } else {
556
- this.allowPushOn = false;
554
+ this.disablePushOff = device.disablePushOff;
557
555
  }
558
556
  }
559
557
 
560
- async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
561
- if (device.allowPushOff) {
562
- this.allowPushOff = true;
558
+ async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
559
+ if (device.disablePushDetail === undefined) {
560
+ this.disablePushDetail = false;
563
561
  } else {
564
- this.allowPushOff = false;
562
+ this.disablePushDetail = device.disablePushDetail;
565
563
  }
566
564
  }
567
565
 
@@ -655,17 +653,29 @@ export class AirConditioner {
655
653
  async context(): Promise<void> {
656
654
  if (this.Active === undefined) {
657
655
  this.Active = this.platform.Characteristic.Active.INACTIVE;
656
+ } else if (this.Active) {
657
+ this.Active;
658
658
  } else {
659
659
  this.Active = this.accessory.context.Active;
660
660
  }
661
661
  if (this.CurrentTemperature === undefined) {
662
662
  this.CurrentTemperature = 24;
663
+ } else if (this.CurrentTemperature) {
664
+ this.CurrentTemperature;
665
+ } else if (this.accessory.context.CurrentTemperature === undefined) {
666
+ this.CurrentTemperature = 24;
663
667
  } else {
664
668
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
665
669
  }
666
- if (this.accessory.context.CurrentTemperature === undefined) {
667
- this.CurrentTemperature = 30;
670
+
671
+ if (this.CoolingThresholdTemperature === undefined) {
672
+ this.CoolingThresholdTemperature = this.CurrentTemperature;
673
+ }
674
+
675
+ if (this.HeatingThresholdTemperature === undefined) {
676
+ this.HeatingThresholdTemperature = this.CurrentTemperature;
668
677
  }
678
+
669
679
  if (this.device.irair?.hide_automode) {
670
680
  this.hide_automode = this.device.irair?.hide_automode;
671
681
  this.accessory.context.hide_automode = this.hide_automode;
@@ -698,11 +708,14 @@ export class AirConditioner {
698
708
  if (device.customize !== undefined) {
699
709
  config['customize'] = device.customize;
700
710
  }
701
- if (device.allowPushOn !== undefined) {
702
- config['allowPushOn'] = device.allowPushOn;
711
+ if (device.disablePushOn !== undefined) {
712
+ config['disablePushOn'] = device.disablePushOn;
713
+ }
714
+ if (device.disablePushOff !== undefined) {
715
+ config['disablePushOff'] = device.disablePushOff;
703
716
  }
704
- if (device.allowPushOff !== undefined) {
705
- config['allowPushOff'] = device.allowPushOff;
717
+ if (device.disablePushDetail !== undefined) {
718
+ config['disablePushDetail'] = device.disablePushDetail;
706
719
  }
707
720
  if (Object.entries(config).length !== 0) {
708
721
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);