@switchbot/homebridge-switchbot 2.2.0-beta.2 → 2.2.0-beta.3

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 (79) hide show
  1. package/dist/device/bot.d.ts +3 -1
  2. package/dist/device/bot.d.ts.map +1 -1
  3. package/dist/device/bot.js +3 -3
  4. package/dist/device/bot.js.map +1 -1
  5. package/dist/device/colorbulb.js +79 -77
  6. package/dist/device/colorbulb.js.map +1 -1
  7. package/dist/device/contact.d.ts +3 -1
  8. package/dist/device/contact.d.ts.map +1 -1
  9. package/dist/device/contact.js +3 -3
  10. package/dist/device/contact.js.map +1 -1
  11. package/dist/device/curtain.js +2 -2
  12. package/dist/device/curtain.js.map +1 -1
  13. package/dist/device/humidifier.js +2 -2
  14. package/dist/device/humidifier.js.map +1 -1
  15. package/dist/device/lock.d.ts +8 -1
  16. package/dist/device/lock.d.ts.map +1 -1
  17. package/dist/device/lock.js +83 -0
  18. package/dist/device/lock.js.map +1 -1
  19. package/dist/device/meter.js +2 -2
  20. package/dist/device/meter.js.map +1 -1
  21. package/dist/device/meterplus.js +2 -2
  22. package/dist/device/meterplus.js.map +1 -1
  23. package/dist/device/motion.d.ts +3 -1
  24. package/dist/device/motion.d.ts.map +1 -1
  25. package/dist/device/motion.js +3 -3
  26. package/dist/device/motion.js.map +1 -1
  27. package/dist/device/plug.js +2 -2
  28. package/dist/device/plug.js.map +1 -1
  29. package/dist/device/striplight.js +2 -2
  30. package/dist/device/striplight.js.map +1 -1
  31. package/dist/irdevice/airconditioner.d.ts +1 -4
  32. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  33. package/dist/irdevice/airconditioner.js +16 -28
  34. package/dist/irdevice/airconditioner.js.map +1 -1
  35. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  36. package/dist/irdevice/airpurifier.js +4 -5
  37. package/dist/irdevice/airpurifier.js.map +1 -1
  38. package/dist/irdevice/camera.d.ts.map +1 -1
  39. package/dist/irdevice/camera.js +2 -3
  40. package/dist/irdevice/camera.js.map +1 -1
  41. package/dist/irdevice/fan.d.ts.map +1 -1
  42. package/dist/irdevice/fan.js +11 -10
  43. package/dist/irdevice/fan.js.map +1 -1
  44. package/dist/irdevice/light.d.ts.map +1 -1
  45. package/dist/irdevice/light.js +2 -3
  46. package/dist/irdevice/light.js.map +1 -1
  47. package/dist/irdevice/other.d.ts.map +1 -1
  48. package/dist/irdevice/other.js +1 -1
  49. package/dist/irdevice/other.js.map +1 -1
  50. package/dist/irdevice/tv.d.ts.map +1 -1
  51. package/dist/irdevice/tv.js +11 -12
  52. package/dist/irdevice/tv.js.map +1 -1
  53. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  54. package/dist/irdevice/vacuumcleaner.js +2 -3
  55. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  56. package/dist/irdevice/waterheater.d.ts.map +1 -1
  57. package/dist/irdevice/waterheater.js +2 -3
  58. package/dist/irdevice/waterheater.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/device/bot.ts +3 -3
  61. package/src/device/colorbulb.ts +74 -74
  62. package/src/device/contact.ts +3 -3
  63. package/src/device/curtain.ts +2 -2
  64. package/src/device/humidifier.ts +2 -2
  65. package/src/device/lock.ts +92 -1
  66. package/src/device/meter.ts +2 -2
  67. package/src/device/meterplus.ts +2 -2
  68. package/src/device/motion.ts +3 -3
  69. package/src/device/plug.ts +2 -2
  70. package/src/device/striplight.ts +2 -2
  71. package/src/irdevice/airconditioner.ts +20 -37
  72. package/src/irdevice/airpurifier.ts +4 -5
  73. package/src/irdevice/camera.ts +3 -4
  74. package/src/irdevice/fan.ts +11 -10
  75. package/src/irdevice/light.ts +2 -3
  76. package/src/irdevice/other.ts +1 -1
  77. package/src/irdevice/tv.ts +11 -12
  78. package/src/irdevice/vacuumcleaner.ts +2 -3
  79. package/src/irdevice/waterheater.ts +2 -3
@@ -506,85 +506,85 @@ export class ColorBulb {
506
506
 
507
507
  async BLEpushChanges(): Promise<void> {
508
508
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
509
- //if (this.On !== this.accessory.context.On) {
510
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
511
- const switchbot = await this.platform.connectBLE();
512
- // Convert to BLE Address
513
- this.device.bleMac = this.device
514
- .deviceId!.match(/.{1,2}/g)!
515
- .join(':')
516
- .toLowerCase();
517
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
518
- switchbot
519
- .discover({
520
- model: 'u',
521
- id: this.device.bleMac,
522
- })
523
- .then((device_list: any) => {
524
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
525
- return this.turnOnOff(device_list);
526
- })
527
- .then(() => {
528
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
529
- this.On = false;
530
- })
531
- .catch(async (e: any) => {
532
- this.apiError(e);
533
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
509
+ if (this.On !== this.accessory.context.On) {
510
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
511
+ const switchbot = await this.platform.connectBLE();
512
+ // Convert to BLE Address
513
+ this.device.bleMac = this.device
514
+ .deviceId!.match(/.{1,2}/g)!
515
+ .join(':')
516
+ .toLowerCase();
517
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
518
+ switchbot
519
+ .discover({
520
+ model: 'u',
521
+ id: this.device.bleMac,
522
+ })
523
+ .then((device_list: any) => {
524
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
525
+ return this.turnOnOff(device_list);
526
+ })
527
+ .then(() => {
528
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
529
+ this.On = false;
530
+ })
531
+ .catch(async (e: any) => {
532
+ this.apiError(e);
533
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
534
534
  + ` Connection, Error Message: ${superStringify(e.message)}`);
535
- await this.BLEPushConnection();
536
- });
537
- // Push Brightness Update
538
- if (this.On) {
539
- await this.BLEpushBrightnessChanges();
540
- }
541
- // Push ColorTemperature Update
542
- if (this.On) {
543
- await this.BLEpushColorTemperatureChanges();
544
- }
545
- // Push Hue & Saturation Update
546
- if (this.On) {
547
- await this.BLEpushRGBChanges();
535
+ await this.BLEPushConnection();
536
+ });
537
+ // Push Brightness Update
538
+ if (this.On) {
539
+ await this.BLEpushBrightnessChanges();
540
+ }
541
+ // Push ColorTemperature Update
542
+ if (this.On) {
543
+ await this.BLEpushColorTemperatureChanges();
544
+ }
545
+ // Push Hue & Saturation Update
546
+ if (this.On) {
547
+ await this.BLEpushRGBChanges();
548
+ }
549
+ } else {
550
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
551
+ +`OnCached: ${this.accessory.context.On}`);
548
552
  }
549
- // } else {
550
- // this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
551
- // +`OnCached: ${this.accessory.context.On}`);
552
- // }
553
553
  }
554
554
 
555
555
  async BLEpushBrightnessChanges(): Promise<void> {
556
556
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushBrightnessChanges`);
557
- //if (this.Brightness !== this.accessory.context.Brightness) {
558
- const switchbot = await this.platform.connectBLE();
559
- // Convert to BLE Address
560
- this.device.bleMac = this.device
561
- .deviceId!.match(/.{1,2}/g)!
562
- .join(':')
563
- .toLowerCase();
564
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
565
- switchbot
566
- .discover({
567
- model: 'u',
568
- id: this.device.bleMac,
569
- })
570
- .then((device_list: any) => {
571
- this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
572
- return device_list[0].setBrightness(this.Brightness);
573
- })
574
- .then(() => {
575
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
576
- this.On = false;
577
- })
578
- .catch(async (e: any) => {
579
- this.apiError(e);
580
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
557
+ if (this.Brightness !== this.accessory.context.Brightness) {
558
+ const switchbot = await this.platform.connectBLE();
559
+ // Convert to BLE Address
560
+ this.device.bleMac = this.device
561
+ .deviceId!.match(/.{1,2}/g)!
562
+ .join(':')
563
+ .toLowerCase();
564
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
565
+ switchbot
566
+ .discover({
567
+ model: 'u',
568
+ id: this.device.bleMac,
569
+ })
570
+ .then((device_list: any) => {
571
+ this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
572
+ return device_list[0].setBrightness(this.Brightness);
573
+ })
574
+ .then(() => {
575
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
576
+ this.On = false;
577
+ })
578
+ .catch(async (e: any) => {
579
+ this.apiError(e);
580
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
581
581
  + ` Connection, Error Message: ${superStringify(e.message)}`);
582
- await this.BLEPushConnection();
583
- });
584
- // } else {
585
- // this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
586
- // +`BrightnessCached: ${this.accessory.context.Brightness}`);
587
- //}
582
+ await this.BLEPushConnection();
583
+ });
584
+ } else {
585
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
586
+ +`BrightnessCached: ${this.accessory.context.Brightness}`);
587
+ }
588
588
  }
589
589
 
590
590
  async BLEpushColorTemperatureChanges(): Promise<void> {
@@ -1068,8 +1068,8 @@ export class ColorBulb {
1068
1068
  async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
1069
1069
  switchbot.stopScan();
1070
1070
  if (this.connected) {
1071
- this.BLEparseStatus();
1072
- this.updateHomeKitCharacteristics();
1071
+ await this.BLEparseStatus();
1072
+ await this.updateHomeKitCharacteristics();
1073
1073
  } else {
1074
1074
  await this.BLERefreshConnection(switchbot);
1075
1075
  }
@@ -450,11 +450,11 @@ export class Contact {
450
450
  }
451
451
  }
452
452
 
453
- async stopScanning(switchbot: any) {
453
+ async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
454
454
  switchbot.stopScan();
455
455
  if (this.connected) {
456
- this.BLEparseStatus();
457
- this.updateHomeKitCharacteristics();
456
+ await this.BLEparseStatus();
457
+ await this.updateHomeKitCharacteristics();
458
458
  } else {
459
459
  await this.BLERefreshConnection(switchbot);
460
460
  }
@@ -809,8 +809,8 @@ export class Curtain {
809
809
  async stopScanning(switchbot: any) {
810
810
  switchbot.stopScan();
811
811
  if (this.connected) {
812
- this.BLEparseStatus();
813
- this.updateHomeKitCharacteristics();
812
+ await this.BLEparseStatus();
813
+ await this.updateHomeKitCharacteristics();
814
814
  } else {
815
815
  await this.BLERefreshConnection(switchbot);
816
816
  }
@@ -768,8 +768,8 @@ export class Humidifier {
768
768
  async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
769
769
  switchbot.stopScan();
770
770
  if (this.connected) {
771
- this.BLEparseStatus();
772
- this.updateHomeKitCharacteristics();
771
+ await this.BLEparseStatus();
772
+ await this.updateHomeKitCharacteristics();
773
773
  } else {
774
774
  await this.BLERefreshConnection(switchbot);
775
775
  }
@@ -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 } from 'homebridge';
10
- import { device, devicesConfig, deviceStatus, HostDomain, DevicePath } from '../settings';
10
+ import { device, devicesConfig, deviceStatus, HostDomain, DevicePath, switchbot, ad, serviceData } from '../settings';
11
11
 
12
12
  export class Lock {
13
13
  // Services
@@ -24,6 +24,12 @@ export class Lock {
24
24
  lockState!: deviceStatus['lockState'];
25
25
  deviceStatus!: any; //deviceStatusResponse;
26
26
 
27
+ // BLE Others
28
+ connected?: boolean;
29
+ switchbot!: switchbot;
30
+ address!: ad['address'];
31
+ serviceData!: serviceData;
32
+
27
33
  // Config
28
34
  scanDuration!: number;
29
35
  deviceLogging!: string;
@@ -206,6 +212,63 @@ export class Lock {
206
212
  }
207
213
  }
208
214
 
215
+ async BLERefreshStatus(): Promise<void> {
216
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
217
+ const switchbot = await this.platform.connectBLE();
218
+ // Convert to BLE Address
219
+ this.device.bleMac = this.device
220
+ .deviceId!.match(/.{1,2}/g)!
221
+ .join(':')
222
+ .toLowerCase();
223
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
224
+ this.getCustomBLEAddress(switchbot);
225
+ // Start to monitor advertisement packets
226
+ if (switchbot !== false) {
227
+ switchbot
228
+ .startScan({
229
+ model: 'o',
230
+ id: this.device.bleMac,
231
+ })
232
+ .then(() => {
233
+ // Set an event hander
234
+ switchbot.onadvertisement = async (ad: any) => {
235
+ this.address = ad.address;
236
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
237
+ + ` BLE Address Found: ${this.address}`);
238
+ this.serviceData = ad.serviceData;
239
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
240
+ this.debugLog(
241
+ `${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
242
+ `position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
243
+ `inMotion: ${ad.serviceData.inMotion}`);
244
+
245
+ if (this.serviceData) {
246
+ this.connected = true;
247
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
248
+ await this.stopScanning(switchbot);
249
+ } else {
250
+ this.connected = false;
251
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
252
+ }
253
+ };
254
+ // Wait 2 seconds
255
+ return switchbot.wait(this.scanDuration * 1000);
256
+ })
257
+ .then(async () => {
258
+ // Stop to monitor
259
+ await this.stopScanning(switchbot);
260
+ })
261
+ .catch(async (e: any) => {
262
+ this.apiError(e);
263
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
264
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
265
+ await this.BLERefreshConnection(switchbot);
266
+ });
267
+ } else {
268
+ await this.BLERefreshConnection(switchbot);
269
+ }
270
+ }
271
+
209
272
  async openAPIRefreshStatus(): Promise<void> {
210
273
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
211
274
  try {
@@ -427,6 +490,34 @@ export class Lock {
427
490
  }
428
491
  }
429
492
 
493
+ async stopScanning(switchbot: any) {
494
+ switchbot.stopScan();
495
+ if (this.connected) {
496
+ await this.BLEparseStatus();
497
+ await this.updateHomeKitCharacteristics();
498
+ } else {
499
+ await this.BLERefreshConnection(switchbot);
500
+ }
501
+ }
502
+
503
+ async getCustomBLEAddress(switchbot: any) {
504
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
505
+ (async () => {
506
+ // Start to monitor advertisement packets
507
+ await switchbot.startScan({
508
+ model: 'c',
509
+ });
510
+ // Set an event handler
511
+ switchbot.onadvertisement = (ad: any) => {
512
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
513
+ };
514
+ await switchbot.wait(10000);
515
+ // Stop to monitor
516
+ switchbot.stopScan();
517
+ })();
518
+ }
519
+ }
520
+
430
521
  async BLEPushConnection() {
431
522
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
432
523
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
@@ -491,8 +491,8 @@ export class Meter {
491
491
  async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
492
492
  switchbot.stopScan();
493
493
  if (this.connected) {
494
- this.BLEparseStatus();
495
- this.updateHomeKitCharacteristics();
494
+ await this.BLEparseStatus();
495
+ await this.updateHomeKitCharacteristics();
496
496
  } else {
497
497
  await this.BLERefreshConnection(switchbot);
498
498
  }
@@ -490,8 +490,8 @@ export class MeterPlus {
490
490
  async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
491
491
  switchbot.stopScan();
492
492
  if (this.connected) {
493
- this.BLEparseStatus();
494
- this.updateHomeKitCharacteristics();
493
+ await this.BLEparseStatus();
494
+ await this.updateHomeKitCharacteristics();
495
495
  } else {
496
496
  await this.BLERefreshConnection(switchbot);
497
497
  }
@@ -394,11 +394,11 @@ export class Motion {
394
394
  }
395
395
  }
396
396
 
397
- async stopScanning(switchbot: any) {
397
+ async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
398
398
  switchbot.stopScan();
399
399
  if (this.connected) {
400
- this.BLEparseStatus();
401
- this.updateHomeKitCharacteristics();
400
+ await this.BLEparseStatus();
401
+ await this.updateHomeKitCharacteristics();
402
402
  } else {
403
403
  await this.BLERefreshConnection(switchbot);
404
404
  }
@@ -461,8 +461,8 @@ export class Plug {
461
461
  async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
462
462
  switchbot.stopScan();
463
463
  if (this.connected) {
464
- this.BLEparseStatus();
465
- this.updateHomeKitCharacteristics();
464
+ await this.BLEparseStatus();
465
+ await this.updateHomeKitCharacteristics();
466
466
  } else {
467
467
  await this.BLERefreshConnection(switchbot);
468
468
  }
@@ -812,8 +812,8 @@ export class StripLight {
812
812
  async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
813
813
  switchbot.stopScan();
814
814
  if (this.connected) {
815
- this.BLEparseStatus();
816
- this.updateHomeKitCharacteristics();
815
+ await this.BLEparseStatus();
816
+ await this.updateHomeKitCharacteristics();
817
817
  } else {
818
818
  await this.BLERefreshConnection(switchbot);
819
819
  }
@@ -48,7 +48,7 @@ export class AirConditioner {
48
48
  // default placeholders
49
49
  this.logs({ device });
50
50
  this.config({ device });
51
- this.context({ device });
51
+ this.context();
52
52
  this.allowPushOnChanges({ device });
53
53
  this.allowPushOffChanges({ device });
54
54
 
@@ -202,7 +202,7 @@ export class AirConditioner {
202
202
  }
203
203
 
204
204
  async pushAirConditionerDetailsChanges(): Promise<void> {
205
- this.CurrentTemperatureUndefined();
205
+ await this.context();
206
206
  if (this.CurrentMode === undefined) {
207
207
  this.CurrentMode = 1;
208
208
  }
@@ -224,7 +224,7 @@ export class AirConditioner {
224
224
  const parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
225
225
 
226
226
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
227
- this.CurrentTemperatureUndefined();
227
+ await this.context();
228
228
  if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
229
229
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
230
230
  } else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
@@ -282,11 +282,11 @@ export class AirConditioner {
282
282
  req.write(body);
283
283
  req.end();
284
284
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
285
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
285
+ //this.accessory.context.CurrentTemperature = this.CurrentTemperature;
286
286
  this.HeatingThresholdTemperature = this.CurrentTemperature;
287
287
  this.CoolingThresholdTemperature = this.CurrentTemperature;
288
- this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
289
- this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
288
+ //this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
289
+ //this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
290
290
  this.updateHomeKitCharacteristics();
291
291
  } catch (e: any) {
292
292
  this.apiError({ e });
@@ -332,7 +332,6 @@ export class AirConditioner {
332
332
  this.CurrentFanSpeed = Number(value) + 1;
333
333
  }
334
334
  this.RotationSpeed = this.CurrentFanSpeed;
335
- this.accessory.context.RotationSpeed = this.RotationSpeed;
336
335
  this.pushAirConditionerStatusChanges();
337
336
  }
338
337
 
@@ -354,7 +353,6 @@ export class AirConditioner {
354
353
  * they are updated, so we are only updating the accessory state after calling the above.
355
354
  */
356
355
  this.Active = value;
357
- this.accessory.context.Active = this.Active;
358
356
  }
359
357
 
360
358
  async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
@@ -407,7 +405,6 @@ export class AirConditioner {
407
405
  );
408
406
  }
409
407
  }
410
- this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
411
408
  this.pushAirConditionerStatusChanges();
412
409
  }
413
410
 
@@ -434,7 +431,7 @@ export class AirConditioner {
434
431
 
435
432
  async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
436
433
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
437
- this.CurrentTemperatureUndefined();
434
+ await this.context();
438
435
  if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
439
436
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
440
437
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
@@ -454,7 +451,7 @@ export class AirConditioner {
454
451
  }
455
452
 
456
453
  async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
457
- this.CurrentTemperatureUndefined;
454
+ await this.context();
458
455
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
459
456
  this.HeatingThresholdTemperature = this.accessory.context.CurrentTemperature;
460
457
  this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
@@ -463,18 +460,14 @@ export class AirConditioner {
463
460
  }
464
461
 
465
462
  async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
466
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
467
463
  this.CurrentTemperature = value;
468
- this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
469
- this.debugLog(
470
- `${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
471
- ` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
472
- );
464
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
465
+ ` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`);
473
466
  this.pushAirConditionerStatusChanges();
474
467
  }
475
468
 
476
469
  async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
477
- this.CurrentTemperatureUndefined;
470
+ await this.context();
478
471
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
479
472
  this.CoolingThresholdTemperature = this.accessory.context.CurrentTemperature;
480
473
  this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
@@ -483,25 +476,12 @@ export class AirConditioner {
483
476
  }
484
477
 
485
478
  async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
486
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
487
479
  this.CurrentTemperature = value;
488
- this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
489
- this.debugLog(
490
- `${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
491
- ` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
492
- );
480
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
481
+ ` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`);
493
482
  this.pushAirConditionerStatusChanges();
494
483
  }
495
484
 
496
- async CurrentTemperatureUndefined(): Promise<void> {
497
- if (this.CurrentTemperature === undefined) {
498
- this.CurrentTemperature = 24;
499
- }
500
- if (this.accessory.context.CurrentTemperature === undefined) {
501
- this.CurrentTemperature = 30;
502
- }
503
- }
504
-
505
485
  async updateHomeKitCharacteristics(): Promise<void> {
506
486
  if (this.Active === undefined) {
507
487
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
@@ -668,7 +648,7 @@ export class AirConditioner {
668
648
  return FirmwareRevision;
669
649
  }
670
650
 
671
- async context({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
651
+ async context(): Promise<void> {
672
652
  if (this.Active === undefined) {
673
653
  this.Active = this.platform.Characteristic.Active.INACTIVE;
674
654
  } else {
@@ -679,11 +659,14 @@ export class AirConditioner {
679
659
  } else {
680
660
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
681
661
  }
682
- if (device.irair?.hide_automode) {
683
- this.hide_automode = device.irair?.hide_automode;
662
+ if (this.accessory.context.CurrentTemperature === undefined) {
663
+ this.CurrentTemperature = 30;
664
+ }
665
+ if (this.device.irair?.hide_automode) {
666
+ this.hide_automode = this.device.irair?.hide_automode;
684
667
  this.accessory.context.hide_automode = this.hide_automode;
685
668
  } else {
686
- this.hide_automode = device.irair?.hide_automode;
669
+ this.hide_automode = this.device.irair?.hide_automode;
687
670
  this.accessory.context.hide_automode = this.hide_automode;
688
671
  }
689
672
  }
@@ -94,7 +94,6 @@ export class AirPurifier {
94
94
  * they are updated, so we are only updating the accessory state after calling the above.
95
95
  */
96
96
  this.Active = value;
97
- this.accessory.context.Active = this.Active;
98
97
  }
99
98
 
100
99
  async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
@@ -134,7 +133,7 @@ export class AirPurifier {
134
133
  * AirPurifier: "command" "highSpeed" "default" = fan speed to high
135
134
  */
136
135
  async pushAirPurifierOnChanges(): Promise<void> {
137
- if (this.Active !== 1) {
136
+ if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
138
137
  const commandType: string = await this.commandType();
139
138
  const command: string = await this.commandOn();
140
139
  const body = superStringify({
@@ -147,9 +146,9 @@ export class AirPurifier {
147
146
  }
148
147
 
149
148
  async pushAirPurifierOffChanges(): Promise<void> {
150
- const commandType: string = await this.commandType();
151
- const command: string = await this.commandOff();
152
- if (this.Active !== 0) {
149
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOn) {
150
+ const commandType: string = await this.commandType();
151
+ const command: string = await this.commandOff();
153
152
  const body = superStringify({
154
153
  'command': command,
155
154
  'parameter': 'default',
@@ -70,7 +70,6 @@ export class Camera {
70
70
  * they are updated, so we are only updating the accessory state after calling the above.
71
71
  */
72
72
  this.On = value;
73
- this.accessory.context.On = this.On;
74
73
  }
75
74
 
76
75
  /**
@@ -84,7 +83,7 @@ export class Camera {
84
83
  * Camera - "command" "channelSub" "default" = previous channel
85
84
  */
86
85
  async pushOnChanges(): Promise<void> {
87
- if (this.On) {
86
+ if (this.On || this.allowPushOn) {
88
87
  const commandType: string = await this.commandType();
89
88
  const command: string = await this.commandOn();
90
89
  const body = superStringify({
@@ -99,7 +98,7 @@ export class Camera {
99
98
  async pushOffChanges(): Promise<void> {
100
99
  const commandType: string = await this.commandType();
101
100
  const command: string = await this.commandOff();
102
- if (!this.On) {
101
+ if (!this.On || this.allowPushOff) {
103
102
  const body = superStringify({
104
103
  'command': command,
105
104
  'parameter': 'default',
@@ -109,7 +108,7 @@ export class Camera {
109
108
  }
110
109
  }
111
110
 
112
- async pushChanges(body): Promise<void> {
111
+ async pushChanges(body: any): Promise<void> {
113
112
  if (this.device.connectionType === 'OpenAPI') {
114
113
  try {
115
114
  // Make Push On request to the API
@@ -161,7 +161,6 @@ export class Fan {
161
161
  * they are updated, so we are only updating the accessory state after calling the above.
162
162
  */
163
163
  this.Active = value;
164
- this.accessory.context.Active = this.Active;
165
164
  }
166
165
 
167
166
  /**
@@ -174,7 +173,7 @@ export class Fan {
174
173
  * Fan - "command" "highSpeed" "default" = fan speed to high
175
174
  */
176
175
  async pushFanOnChanges(): Promise<void> {
177
- if (this.Active !== 1) {
176
+ if (this.Active === this.platform.Characteristic.Active.INACTIVE || this.allowPushOn) {
178
177
  const commandType: string = await this.commandType();
179
178
  const command: string = await this.commandOn();
180
179
  const body = superStringify({
@@ -187,14 +186,16 @@ export class Fan {
187
186
  }
188
187
 
189
188
  async pushFanOffChanges(): Promise<void> {
190
- const commandType: string = await this.commandType();
191
- const command: string = await this.commandOff();
192
- const body = superStringify({
193
- 'command': command,
194
- 'parameter': 'default',
195
- 'commandType': commandType,
196
- });
197
- await this.pushTVChanges(body);
189
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE || this.allowPushOff) {
190
+ const commandType: string = await this.commandType();
191
+ const command: string = await this.commandOff();
192
+ const body = superStringify({
193
+ 'command': command,
194
+ 'parameter': 'default',
195
+ 'commandType': commandType,
196
+ });
197
+ await this.pushTVChanges(body);
198
+ }
198
199
  }
199
200
 
200
201
  async pushFanSpeedUpChanges(): Promise<void> {