@switchbot/homebridge-switchbot 2.2.2-beta.9 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/config.schema.json +9 -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 +6 -6
  44. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  45. package/dist/irdevice/airconditioner.js +39 -35
  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 +6 -6
  68. package/dist/irdevice/tv.d.ts.map +1 -1
  69. package/dist/irdevice/tv.js +35 -36
  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 +9 -19
  84. package/dist/settings.d.ts.map +1 -1
  85. package/dist/settings.js.map +1 -1
  86. package/package.json +5 -5
  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 +43 -39
  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 +38 -39
  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 +12 -28
  108. package/.github/npm-version-script.js +0 -81
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,8 @@ 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
41
  deviceLogging!: string;
42
42
  hide_automode?: boolean;
43
43
 
@@ -49,8 +49,8 @@ export class AirConditioner {
49
49
  this.logs({ device });
50
50
  this.config({ device });
51
51
  this.context();
52
- this.allowPushOnChanges({ device });
53
- this.allowPushOffChanges({ device });
52
+ this.disablePushOnChanges({ device });
53
+ this.disablePushOffChanges({ device });
54
54
 
55
55
  // set accessory information
56
56
  accessory
@@ -65,7 +65,7 @@ export class AirConditioner {
65
65
  // get the Television service if it exists, otherwise create a new Television service
66
66
  // you can create multiple services for each accessory
67
67
  (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
68
- `${accessory.displayName} Air Conditioner`;
68
+ `${accessory.displayName} ${device.remoteType}`;
69
69
 
70
70
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
71
71
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -166,8 +166,8 @@ export class AirConditioner {
166
166
  */
167
167
  async pushAirConditionerOnChanges(): Promise<void> {
168
168
  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) {
169
+ + ` disablePushOn: ${this.disablePushOn}`);
170
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
171
171
  const commandType: string = await this.commandType();
172
172
  const command: string = await this.commandOn();
173
173
  const body = superStringify({
@@ -181,8 +181,8 @@ export class AirConditioner {
181
181
 
182
182
  async pushAirConditionerOffChanges(): Promise<void> {
183
183
  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) {
184
+ + ` disablePushOff: ${this.disablePushOff}`);
185
+ if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
186
186
  const commandType: string = await this.commandType();
187
187
  const command: string = await this.commandOff();
188
188
  const body = superStringify({
@@ -195,6 +195,8 @@ export class AirConditioner {
195
195
  }
196
196
 
197
197
  async pushAirConditionerStatusChanges(): Promise<void> {
198
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},`
199
+ + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
198
200
  if (!this.Busy) {
199
201
  this.Busy = true;
200
202
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
@@ -206,6 +208,8 @@ export class AirConditioner {
206
208
  }
207
209
 
208
210
  async pushAirConditionerDetailsChanges(): Promise<void> {
211
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},`
212
+ + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
209
213
  await this.context();
210
214
  if (this.CurrentMode === undefined) {
211
215
  this.CurrentMode = 1;
@@ -246,10 +250,11 @@ export class AirConditioner {
246
250
  await this.pushChanges(body);
247
251
  }
248
252
 
249
- async pushChanges(body: any): Promise<void> {
253
+ async pushChanges(body: Array<body>): Promise<void> {
250
254
  if (this.device.connectionType === 'OpenAPI') {
251
255
  try {
252
- // Make Push On request to the API
256
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} body: ${body}`);
257
+ // Make Push On request to the API
253
258
  const t = Date.now();
254
259
  const nonce = 'requestID';
255
260
  const data = this.platform.config.credentials?.token + t + nonce;
@@ -286,11 +291,11 @@ export class AirConditioner {
286
291
  req.write(body);
287
292
  req.end();
288
293
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
289
- //this.accessory.context.CurrentTemperature = this.CurrentTemperature;
294
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
290
295
  this.HeatingThresholdTemperature = this.CurrentTemperature;
291
296
  this.CoolingThresholdTemperature = this.CurrentTemperature;
292
- //this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
293
- //this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
297
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
298
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
294
299
  this.updateHomeKitCharacteristics();
295
300
  } catch (e: any) {
296
301
  this.apiError({ e });
@@ -341,22 +346,19 @@ export class AirConditioner {
341
346
 
342
347
  async ActiveSet(value: CharacteristicValue): Promise<void> {
343
348
  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 {
349
+
350
+ this.Active = value;
351
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
348
352
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
349
- if (this.allowPushOn) {
350
- this.pushAirConditionerOnChanges();
351
- } else {
353
+ if (this.disablePushOn) {
352
354
  this.pushAirConditionerStatusChanges();
355
+ } else {
356
+ this.pushAirConditionerOnChanges();
353
357
  }
358
+ } else {
359
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
360
+ this.pushAirConditionerOffChanges();
354
361
  }
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
362
  }
361
363
 
362
364
  async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
@@ -549,19 +551,19 @@ export class AirConditioner {
549
551
  }
550
552
  }
551
553
 
552
- async allowPushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
553
- if (device.allowPushOn) {
554
- this.allowPushOn = true;
554
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
555
+ if (device.disablePushOn === undefined) {
556
+ this.disablePushOn = false;
555
557
  } else {
556
- this.allowPushOn = false;
558
+ this.disablePushOn = device.disablePushOn;
557
559
  }
558
560
  }
559
561
 
560
- async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
561
- if (device.allowPushOff) {
562
- this.allowPushOff = true;
562
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
563
+ if (device.disablePushOff === undefined) {
564
+ this.disablePushOff = false;
563
565
  } else {
564
- this.allowPushOff = false;
566
+ this.disablePushOff = device.disablePushOff;
565
567
  }
566
568
  }
567
569
 
@@ -655,6 +657,8 @@ export class AirConditioner {
655
657
  async context(): Promise<void> {
656
658
  if (this.Active === undefined) {
657
659
  this.Active = this.platform.Characteristic.Active.INACTIVE;
660
+ } else if (this.Active) {
661
+ this.Active;
658
662
  } else {
659
663
  this.Active = this.accessory.context.Active;
660
664
  }
@@ -698,11 +702,11 @@ export class AirConditioner {
698
702
  if (device.customize !== undefined) {
699
703
  config['customize'] = device.customize;
700
704
  }
701
- if (device.allowPushOn !== undefined) {
702
- config['allowPushOn'] = device.allowPushOn;
705
+ if (device.disablePushOn !== undefined) {
706
+ config['disablePushOn'] = device.disablePushOn;
703
707
  }
704
- if (device.allowPushOff !== undefined) {
705
- config['allowPushOff'] = device.allowPushOff;
708
+ if (device.disablePushOff !== undefined) {
709
+ config['disablePushOff'] = device.disablePushOff;
706
710
  }
707
711
  if (Object.entries(config).length !== 0) {
708
712
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);