@switchbot/homebridge-switchbot 3.5.1-beta.8 → 3.5.1

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 (159) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/config.schema.json +19 -3
  3. package/dist/device/blindtilt.d.ts +6 -4
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +60 -46
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +6 -3
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +59 -25
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +6 -3
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +47 -29
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +6 -3
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +53 -36
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +6 -3
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +45 -31
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +6 -4
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +41 -27
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/device.d.ts +6 -3
  28. package/dist/device/device.d.ts.map +1 -1
  29. package/dist/device/device.js +59 -152
  30. package/dist/device/device.js.map +1 -1
  31. package/dist/device/fan.d.ts +6 -3
  32. package/dist/device/fan.d.ts.map +1 -1
  33. package/dist/device/fan.js +53 -32
  34. package/dist/device/fan.js.map +1 -1
  35. package/dist/device/hub.d.ts +6 -3
  36. package/dist/device/hub.d.ts.map +1 -1
  37. package/dist/device/hub.js +49 -30
  38. package/dist/device/hub.js.map +1 -1
  39. package/dist/device/humidifier.d.ts +6 -3
  40. package/dist/device/humidifier.d.ts.map +1 -1
  41. package/dist/device/humidifier.js +47 -28
  42. package/dist/device/humidifier.js.map +1 -1
  43. package/dist/device/iosensor.d.ts +6 -3
  44. package/dist/device/iosensor.d.ts.map +1 -1
  45. package/dist/device/iosensor.js +44 -27
  46. package/dist/device/iosensor.js.map +1 -1
  47. package/dist/device/lightstrip.d.ts +6 -3
  48. package/dist/device/lightstrip.d.ts.map +1 -1
  49. package/dist/device/lightstrip.js +46 -28
  50. package/dist/device/lightstrip.js.map +1 -1
  51. package/dist/device/lock.d.ts +6 -3
  52. package/dist/device/lock.d.ts.map +1 -1
  53. package/dist/device/lock.js +38 -25
  54. package/dist/device/lock.js.map +1 -1
  55. package/dist/device/meter.d.ts +6 -3
  56. package/dist/device/meter.d.ts.map +1 -1
  57. package/dist/device/meter.js +43 -27
  58. package/dist/device/meter.js.map +1 -1
  59. package/dist/device/meterplus.d.ts +6 -3
  60. package/dist/device/meterplus.d.ts.map +1 -1
  61. package/dist/device/meterplus.js +42 -27
  62. package/dist/device/meterplus.js.map +1 -1
  63. package/dist/device/motion.d.ts +6 -3
  64. package/dist/device/motion.d.ts.map +1 -1
  65. package/dist/device/motion.js +37 -24
  66. package/dist/device/motion.js.map +1 -1
  67. package/dist/device/plug.d.ts +6 -3
  68. package/dist/device/plug.d.ts.map +1 -1
  69. package/dist/device/plug.js +30 -17
  70. package/dist/device/plug.js.map +1 -1
  71. package/dist/device/robotvacuumcleaner.d.ts +6 -3
  72. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  73. package/dist/device/robotvacuumcleaner.js +37 -22
  74. package/dist/device/robotvacuumcleaner.js.map +1 -1
  75. package/dist/device/waterdetector.d.ts +6 -3
  76. package/dist/device/waterdetector.d.ts.map +1 -1
  77. package/dist/device/waterdetector.js +44 -25
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/homebridge-ui/public/index.html +2 -2
  80. package/dist/irdevice/airconditioner.d.ts +1 -3
  81. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  82. package/dist/irdevice/airconditioner.js +67 -177
  83. package/dist/irdevice/airconditioner.js.map +1 -1
  84. package/dist/irdevice/airpurifier.d.ts +0 -1
  85. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  86. package/dist/irdevice/airpurifier.js +24 -53
  87. package/dist/irdevice/airpurifier.js.map +1 -1
  88. package/dist/irdevice/camera.d.ts.map +1 -1
  89. package/dist/irdevice/camera.js +12 -17
  90. package/dist/irdevice/camera.js.map +1 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +22 -38
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +22 -10
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +94 -100
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts.map +1 -1
  99. package/dist/irdevice/light.js +20 -38
  100. package/dist/irdevice/light.js.map +1 -1
  101. package/dist/irdevice/other.d.ts.map +1 -1
  102. package/dist/irdevice/other.js +79 -77
  103. package/dist/irdevice/other.js.map +1 -1
  104. package/dist/irdevice/tv.d.ts.map +1 -1
  105. package/dist/irdevice/tv.js +38 -53
  106. package/dist/irdevice/tv.js.map +1 -1
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +11 -16
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts.map +1 -1
  111. package/dist/irdevice/waterheater.js +11 -16
  112. package/dist/irdevice/waterheater.js.map +1 -1
  113. package/dist/platform.d.ts +4 -6
  114. package/dist/platform.d.ts.map +1 -1
  115. package/dist/platform.js +564 -665
  116. package/dist/platform.js.map +1 -1
  117. package/dist/settings.d.ts +10 -8
  118. package/dist/settings.d.ts.map +1 -1
  119. package/dist/settings.js.map +1 -1
  120. package/dist/types/bledevicestatus.d.ts +2 -1
  121. package/dist/types/bledevicestatus.d.ts.map +1 -1
  122. package/dist/types/devicestatus.d.ts +1 -1
  123. package/dist/types/devicestatus.d.ts.map +1 -1
  124. package/package.json +11 -11
  125. package/src/device/blindtilt.ts +64 -48
  126. package/src/device/bot.ts +79 -26
  127. package/src/device/ceilinglight.ts +57 -31
  128. package/src/device/colorbulb.ts +57 -43
  129. package/src/device/contact.ts +49 -31
  130. package/src/device/curtain.ts +51 -28
  131. package/src/device/device.ts +61 -135
  132. package/src/device/fan.ts +67 -33
  133. package/src/device/hub.ts +62 -33
  134. package/src/device/humidifier.ts +60 -33
  135. package/src/device/iosensor.ts +51 -30
  136. package/src/device/lightstrip.ts +52 -29
  137. package/src/device/lock.ts +55 -26
  138. package/src/device/meter.ts +60 -29
  139. package/src/device/meterplus.ts +56 -29
  140. package/src/device/motion.ts +50 -26
  141. package/src/device/plug.ts +38 -18
  142. package/src/device/robotvacuumcleaner.ts +53 -24
  143. package/src/device/waterdetector.ts +63 -27
  144. package/src/homebridge-ui/public/index.html +2 -2
  145. package/src/irdevice/airconditioner.ts +76 -165
  146. package/src/irdevice/airpurifier.ts +29 -49
  147. package/src/irdevice/camera.ts +13 -16
  148. package/src/irdevice/fan.ts +25 -35
  149. package/src/irdevice/irdevice.ts +97 -96
  150. package/src/irdevice/light.ts +21 -35
  151. package/src/irdevice/other.ts +79 -77
  152. package/src/irdevice/tv.ts +40 -51
  153. package/src/irdevice/vacuumcleaner.ts +12 -15
  154. package/src/irdevice/waterheater.ts +12 -15
  155. package/src/platform.ts +566 -696
  156. package/src/settings.ts +11 -8
  157. package/src/types/bledevicestatus.ts +4 -2
  158. package/src/types/devicestatus.ts +1 -1
  159. package/.github/npm-version-script.cjs +0 -81
@@ -28,6 +28,7 @@ export class AirConditioner extends irdeviceBase {
28
28
  };
29
29
 
30
30
  meter?: PlatformAccessory;
31
+
31
32
  private HumiditySensor?: {
32
33
  Name: CharacteristicValue;
33
34
  Service: Service;
@@ -55,13 +56,14 @@ export class AirConditioner extends irdeviceBase {
55
56
  device: irdevice & irDevicesConfig,
56
57
  ) {
57
58
  super(platform, accessory, device);
59
+ // Set category
60
+ accessory.category = this.hap.Categories.AIR_CONDITIONER;
58
61
 
59
62
  // default placeholders
60
63
  this.getAirConditionerConfigSettings(accessory, device);
61
64
 
62
65
  this.ValidValues = this.hide_automode ? [1, 2] : [0, 1, 2];
63
66
 
64
-
65
67
  // Initialize HeaterCooler Service
66
68
  accessory.context.HeaterCooler = accessory.context.HeaterCooler ?? {};
67
69
  this.HeaterCooler = {
@@ -181,7 +183,7 @@ export class AirConditioner extends irdeviceBase {
181
183
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
182
184
  */
183
185
  async pushAirConditionerOnChanges(): Promise<void> {
184
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},`
186
+ await this.debugLog(`pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},`
185
187
  + ` disablePushOn: ${this.disablePushOn}`);
186
188
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
187
189
  const commandType: string = await this.commandType();
@@ -196,7 +198,7 @@ export class AirConditioner extends irdeviceBase {
196
198
  }
197
199
 
198
200
  async pushAirConditionerOffChanges(): Promise<void> {
199
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},`
201
+ await this.debugLog(`pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},`
200
202
  + ` disablePushOff: ${this.disablePushOff}`);
201
203
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
202
204
  const commandType: string = await this.commandType();
@@ -211,7 +213,7 @@ export class AirConditioner extends irdeviceBase {
211
213
  }
212
214
 
213
215
  async pushAirConditionerStatusChanges(): Promise<void> {
214
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},`
216
+ await this.debugLog(`pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},`
215
217
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
216
218
  if (!this.Busy) {
217
219
  this.Busy = true;
@@ -224,7 +226,7 @@ export class AirConditioner extends irdeviceBase {
224
226
  }
225
227
 
226
228
  async pushAirConditionerDetailsChanges(): Promise<void> {
227
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},`
229
+ await this.debugLog(`pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},`
228
230
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
229
231
  //await this.deviceContext();
230
232
  if (this.CurrentMode === undefined) {
@@ -241,7 +243,7 @@ export class AirConditioner extends irdeviceBase {
241
243
  if (this.CurrentMode === 1) {
242
244
  // Remove or make configurable?
243
245
  this.HeaterCooler.ThresholdTemperature = 25;
244
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
246
+ await this.debugLog(`CurrentMode: ${this.CurrentMode},`
245
247
  + ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
246
248
  }
247
249
  const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
@@ -344,14 +346,14 @@ export class AirConditioner extends irdeviceBase {
344
346
  }
345
347
 
346
348
  async pushChanges(bodyChange: any): Promise<void> {
347
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
349
+ await this.debugLog('pushChanges');
348
350
  if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
349
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
351
+ await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
350
352
  try {
351
353
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
352
354
  const deviceStatus: any = await body.json();
353
355
  await this.pushStatusCodes(statusCode, deviceStatus);
354
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
356
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
355
357
  await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
356
358
  await this.updateHomeKitCharacteristics();
357
359
  } else {
@@ -363,35 +365,33 @@ export class AirConditioner extends irdeviceBase {
363
365
  await this.pushChangeError(e);
364
366
  }
365
367
  } else {
366
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
367
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
368
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
369
- + ` Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`);
370
- this.updateHomeKitCharacteristics();
368
+ await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
369
+ await this.debugLog(`Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`);
370
+ await this.updateHomeKitCharacteristics();
371
371
  }
372
372
  }
373
373
 
374
374
  async CurrentTemperatureGet(): Promise<CharacteristicValue> {
375
375
  if (this.meter?.context?.CurrentTemperature) {
376
376
  this.accessory.context.CurrentTemperature = this.meter.context.CurrentTemperature;
377
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
378
- + `Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`);
377
+ await this.debugLog(''
378
+ + `Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceId})`);
379
379
  }
380
380
 
381
381
  this.HeaterCooler.CurrentTemperature = this.accessory.context.CurrentTemperature || 24;
382
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
382
+ await this.debugLog(`Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
383
383
  return this.HeaterCooler.CurrentTemperature;
384
384
  }
385
385
 
386
386
  async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
387
387
  if (this.meter?.context?.CurrentRelativeHumidity) {
388
388
  this.accessory.context.CurrentRelativeHumidity = this.meter.context.CurrentRelativeHumidity;
389
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
390
- + `Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`);
389
+ await this.debugLog(''
390
+ + `Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceId})`);
391
391
  }
392
392
 
393
393
  this.HumiditySensor!.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity || 0;
394
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get`
394
+ await this.debugLog('Get'
395
395
  + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
396
396
  return this.HumiditySensor!.CurrentRelativeHumidity as CharacteristicValue;
397
397
  }
@@ -402,7 +402,7 @@ export class AirConditioner extends irdeviceBase {
402
402
  } else {
403
403
  this.HeaterCooler.RotationSpeed = this.CurrentFanSpeed - 1;
404
404
  }
405
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
405
+ await this.debugLog(`Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
406
406
  return this.HeaterCooler.RotationSpeed;
407
407
  }
408
408
 
@@ -413,24 +413,23 @@ export class AirConditioner extends irdeviceBase {
413
413
  this.CurrentFanSpeed = Number(value) + 1;
414
414
  }
415
415
  this.HeaterCooler.RotationSpeed = value;
416
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
417
- + `Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
416
+ await this.debugLog(`Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
418
417
  this.pushAirConditionerStatusChanges();
419
418
  }
420
419
 
421
420
  async ActiveSet(value: CharacteristicValue): Promise<void> {
422
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
421
+ await this.debugLog(`Set Active: ${value}`);
423
422
 
424
423
  this.HeaterCooler.Active = value;
425
424
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
426
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
425
+ await this.debugLog(`pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
427
426
  if (this.disablePushOn) {
428
427
  this.pushAirConditionerStatusChanges();
429
428
  } else {
430
429
  this.pushAirConditionerOnChanges();
431
430
  }
432
431
  } else {
433
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
432
+ await this.debugLog(`pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
434
433
  this.pushAirConditionerOffChanges();
435
434
  }
436
435
  }
@@ -438,7 +437,7 @@ export class AirConditioner extends irdeviceBase {
438
437
  async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
439
438
  const targetState = this.HeaterCooler.TargetHeaterCoolerState || this.accessory.context.TargetHeaterCoolerState;
440
439
  this.HeaterCooler.TargetHeaterCoolerState = this.ValidValues.includes(targetState) ? targetState : this.ValidValues[0];
441
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
440
+ await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
442
441
  + ` ${this.HeaterCooler.TargetHeaterCoolerState}, ValidValues: ${this.ValidValues}, hide_automode: ${this.hide_automode}`);
443
442
  return this.HeaterCooler.TargetHeaterCoolerState;
444
443
  }
@@ -451,7 +450,7 @@ export class AirConditioner extends irdeviceBase {
451
450
  } else if (value === this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
452
451
  this.TargetHeaterCoolerStateCOOL();
453
452
  } else {
454
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: `
453
+ this.errorLog('Set TargetHeaterCoolerState: '
455
454
  + `${this.HeaterCooler.TargetHeaterCoolerState}, hide_automode: ${this.hide_automode} `);
456
455
  }
457
456
  this.pushAirConditionerStatusChanges();
@@ -460,31 +459,30 @@ export class AirConditioner extends irdeviceBase {
460
459
  async TargetHeaterCoolerStateAUTO(): Promise<void> {
461
460
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO;
462
461
  this.CurrentMode = 1;
463
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO)`
462
+ await this.debugLog('Set (AUTO)'
464
463
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
465
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
464
+ await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
466
465
  }
467
466
 
468
467
  async TargetHeaterCoolerStateCOOL(): Promise<void> {
469
468
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL;
470
469
  this.CurrentMode = 2;
471
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL)`
470
+ await this.debugLog('Set (COOL)'
472
471
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
473
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
472
+ await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
474
473
  }
475
474
 
476
475
  async TargetHeaterCoolerStateHEAT(): Promise<void> {
477
476
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT;
478
477
  this.CurrentMode = 5;
479
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT)`
478
+ await this.debugLog('Set (HEAT)'
480
479
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
481
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
480
+ await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
482
481
  }
483
482
 
484
483
  async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
485
484
  await this.UpdateCurrentHeaterCoolerState();
486
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
487
- + ` Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
485
+ await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
488
486
 
489
487
  return this.HeaterCooler.CurrentHeaterCoolerState;
490
488
  }
@@ -504,123 +502,68 @@ export class AirConditioner extends irdeviceBase {
504
502
  }
505
503
 
506
504
  async ThresholdTemperatureGet(): Promise<CharacteristicValue> {
505
+ this.HeaterCooler.Active = this.HeaterCooler.Active === undefined ? this.hap.Characteristic.Active.INACTIVE
506
+ : this.HeaterCooler.Active ?? this.accessory.context.Active;
507
507
 
508
- if (this.HeaterCooler.Active === undefined) {
509
- this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE;
510
- } else {
511
- this.HeaterCooler.Active = this.HeaterCooler.Active ? this.HeaterCooler.Active : this.accessory.context.Active;
512
- }
508
+ this.HeaterCooler.CurrentTemperature = (this.HeaterCooler.CurrentTemperature === undefined
509
+ && this.accessory.context.CurrentTemperature === undefined) ? 24 : this.HeaterCooler.CurrentTemperature
510
+ ?? this.accessory.context.CurrentTemperature;
513
511
 
514
- if (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
515
- this.HeaterCooler.CurrentTemperature = 24;
516
- } else {
517
- this.HeaterCooler.CurrentTemperature = this.HeaterCooler.CurrentTemperature || this.accessory.context.CurrentTemperature;
518
- }
512
+ this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature === undefined ? 24 : this.HeaterCooler.ThresholdTemperature
513
+ ?? this.accessory.context.ThresholdTemperature;
519
514
 
520
- if (this.HeaterCooler.ThresholdTemperature === undefined && this.accessory.context.ThresholdTemperature === undefined) {
521
- this.HeaterCooler.ThresholdTemperature = 24;
522
- } else {
523
- this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature || this.accessory.context.ThresholdTemperature;
524
- }
525
-
526
- if (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
527
- this.HeaterCooler.RotationSpeed = 4;
528
- } else {
529
- this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed;
530
- }
515
+ this.HeaterCooler.RotationSpeed = (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) ? 4
516
+ : this.HeaterCooler.RotationSpeed ?? this.accessory.context.RotationSpeed;
531
517
 
532
518
  await this.getAirConditionerConfigSettings(this.accessory, this.device);
533
519
 
534
- if (this.meter) {
535
- if (this.HumiditySensor!.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
536
- this.HumiditySensor!.CurrentRelativeHumidity = 0;
537
- } else {
538
- this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
539
- }
520
+ if (this.meter && this.HumiditySensor?.Service) {
521
+ this.HumiditySensor.CurrentRelativeHumidity = (this.HumiditySensor.CurrentRelativeHumidity === undefined
522
+ && this.accessory.context.CurrentRelativeHumidity === undefined) ? 0 : this.HumiditySensor.CurrentRelativeHumidity
523
+ ?? this.accessory.context.CurrentRelativeHumidity;
540
524
  }
541
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
525
+ await this.debugLog(`Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
542
526
  return this.HeaterCooler.ThresholdTemperature;
543
527
  }
544
528
 
545
529
  async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
546
530
  this.HeaterCooler.ThresholdTemperature = value;
547
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},`
531
+ await this.debugLog(`Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},`
548
532
  + ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
549
533
  this.pushAirConditionerStatusChanges();
550
534
  }
551
535
 
552
536
  async updateHomeKitCharacteristics(): Promise<void> {
537
+ await this.debugLog('updateHomeKitCharacteristics');
553
538
  // Active
554
- if (this.HeaterCooler.Active === undefined) {
555
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.HeaterCooler.Active}`);
556
- } else {
557
- this.accessory.context.Active = this.HeaterCooler.Active;
558
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HeaterCooler.Active);
559
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HeaterCooler.Active}`);
560
- }
539
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.Active,
540
+ this.HeaterCooler.Active, 'Active');
561
541
  // RotationSpeed
562
- if (this.HeaterCooler.RotationSpeed === undefined) {
563
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
564
- } else {
565
- this.accessory.context.RotationSpeed = this.HeaterCooler.RotationSpeed;
566
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.HeaterCooler.RotationSpeed);
567
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
568
- + ` RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
569
- }
542
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.RotationSpeed,
543
+ this.HeaterCooler.RotationSpeed, 'RotationSpeed');
570
544
  // CurrentTemperature
571
- if (this.HeaterCooler.CurrentTemperature === undefined) {
572
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
573
- } else {
574
- this.accessory.context.CurrentTemperature = this.HeaterCooler.CurrentTemperature;
575
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.HeaterCooler.CurrentTemperature);
576
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
577
- + ` CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
578
- }
579
- // CurrentRelativeHumidity
580
- if (this.meter) {
581
- if (this.HumiditySensor!.CurrentRelativeHumidity === undefined) {
582
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
583
- + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
584
- } else {
585
- this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity;
586
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
587
- this.HumiditySensor!.CurrentRelativeHumidity);
588
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
589
- + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
590
- }
591
- }
545
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentTemperature,
546
+ this.HeaterCooler.CurrentTemperature, 'CurrentTemperature');
592
547
  // TargetHeaterCoolerState
593
- if (this.HeaterCooler.TargetHeaterCoolerState === undefined) {
594
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
595
- } else {
596
- this.accessory.context.TargetHeaterCoolerState = this.HeaterCooler.TargetHeaterCoolerState;
597
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, this.HeaterCooler.TargetHeaterCoolerState);
598
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
599
- + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
600
- }
548
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.TargetHeaterCoolerState,
549
+ this.HeaterCooler.TargetHeaterCoolerState, 'TargetHeaterCoolerState');
601
550
  // CurrentHeaterCoolerState
602
- if (this.HeaterCooler.CurrentHeaterCoolerState === undefined) {
603
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
604
- + ` CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
605
- } else {
606
- this.accessory.context.CurrentHeaterCoolerState = this.HeaterCooler.CurrentHeaterCoolerState;
607
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.HeaterCooler.CurrentHeaterCoolerState);
608
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
609
- + ` updateCharacteristic CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
610
- }
611
- // ThresholdTemperature
612
- if (this.HeaterCooler.ThresholdTemperature === undefined) {
613
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
614
- } else {
615
- this.accessory.context.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature;
616
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
617
- this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
618
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
619
- + ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
551
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
552
+ this.HeaterCooler.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
553
+ // HeatingThresholdTemperature
554
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.HeatingThresholdTemperature,
555
+ this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
556
+ // CoolingThresholdTemperature
557
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CoolingThresholdTemperature,
558
+ this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
559
+ if (this.meter && this.HumiditySensor?.Service) {
560
+ // CurrentRelativeHumidity
561
+ await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
562
+ this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
620
563
  }
621
564
  }
622
565
 
623
- async apiError({ e }: { e: any }): Promise<void> {
566
+ async apiError(e: any): Promise<void> {
624
567
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
625
568
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
626
569
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
@@ -632,42 +575,10 @@ export class AirConditioner extends irdeviceBase {
632
575
  }
633
576
 
634
577
  async getAirConditionerConfigSettings(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
635
- if (this.device.irair?.hide_automode) {
636
- this.hide_automode = device.irair?.hide_automode;
637
- accessory.context.hide_automode = this.hide_automode;
638
- } else {
639
- this.hide_automode = device.irair?.hide_automode;
640
- accessory.context.hide_automode = this.hide_automode;
641
- }
642
-
643
- if (this.device.irair?.set_max_heat) {
644
- this.set_max_heat = device.irair?.set_max_heat;
645
- accessory.context.set_max_heat = this.set_max_heat;
646
- } else {
647
- this.set_max_heat = 35;
648
- accessory.context.set_max_heat = this.set_max_heat;
649
- }
650
- if (this.device.irair?.set_min_heat) {
651
- this.set_min_heat = device.irair?.set_min_heat;
652
- accessory.context.set_min_heat = this.set_min_heat;
653
- } else {
654
- this.set_min_heat = 0;
655
- accessory.context.set_min_heat = this.set_min_heat;
656
- }
657
-
658
- if (this.device.irair?.set_max_cool) {
659
- this.set_max_cool = device.irair?.set_max_cool;
660
- accessory.context.set_max_cool = this.set_max_cool;
661
- } else {
662
- this.set_max_cool = 35;
663
- accessory.context.set_max_cool = this.set_max_cool;
664
- }
665
- if (this.device.irair?.set_min_cool) {
666
- this.set_min_cool = device.irair?.set_min_cool;
667
- accessory.context.set_min_cool = this.set_min_cool;
668
- } else {
669
- this.set_min_cool = 0;
670
- accessory.context.set_min_cool = this.set_min_cool;
671
- }
578
+ accessory.context.hide_automode = this.hide_automode = device.irair?.hide_automode;
579
+ accessory.context.set_max_heat = this.set_max_heat = device.irair?.set_max_heat ?? 35;
580
+ accessory.context.set_min_heat = this.set_min_heat = device.irair?.set_min_heat ?? 0;
581
+ accessory.context.set_max_cool = this.set_max_cool = device.irair?.set_max_cool ?? 35;
582
+ accessory.context.set_min_cool = this.set_min_cool = device.irair?.set_min_cool ?? 0;
672
583
  }
673
584
  }
@@ -23,6 +23,7 @@ export class AirPurifier extends irdeviceBase {
23
23
  RotationSpeed: CharacteristicValue;
24
24
  CurrentAirPurifierState: CharacteristicValue;
25
25
  TargetAirPurifierState: CharacteristicValue;
26
+ CurrentHeaterCoolerState: CharacteristicValue;
26
27
  };
27
28
 
28
29
  private TemperatureSensor: {
@@ -36,7 +37,6 @@ export class AirPurifier extends irdeviceBase {
36
37
  CurrentAPTemp!: CharacteristicValue;
37
38
  CurrentAPMode!: CharacteristicValue;
38
39
  CurrentAPFanSpeed!: CharacteristicValue;
39
- CurrentHeaterCoolerState!: CharacteristicValue;
40
40
 
41
41
  // Others
42
42
  Busy: any;
@@ -54,6 +54,8 @@ export class AirPurifier extends irdeviceBase {
54
54
  device: irdevice & irDevicesConfig,
55
55
  ) {
56
56
  super(platform, accessory, device);
57
+ // Set category
58
+ accessory.category = this.hap.Categories.AIR_PURIFIER;
57
59
 
58
60
  // Initialize AirPurifier Service
59
61
  accessory.context.AirPurifier = accessory.context.AirPurifier ?? {};
@@ -64,6 +66,7 @@ export class AirPurifier extends irdeviceBase {
64
66
  RotationSpeed: accessory.context.RotationSpeed ?? 0,
65
67
  CurrentAirPurifierState: accessory.context.CurrentAirPurifierState ?? this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
66
68
  TargetAirPurifierState: accessory.context.TargetAirPurifierState ?? this.hap.Characteristic.TargetAirPurifierState.AUTO,
69
+ CurrentHeaterCoolerState: accessory.context.CurrentHeaterCoolerState ?? this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE,
67
70
  };
68
71
  accessory.context.AirPurifier = this.AirPurifier as object;
69
72
 
@@ -106,7 +109,7 @@ export class AirPurifier extends irdeviceBase {
106
109
  }
107
110
 
108
111
  async ActiveSet(value: CharacteristicValue): Promise<void> {
109
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
112
+ await this.debugLog(`Set Active: ${value}`);
110
113
 
111
114
  this.AirPurifier.Active = value;
112
115
  if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE) {
@@ -153,7 +156,7 @@ export class AirPurifier extends irdeviceBase {
153
156
  * AirPurifier: "command" "highSpeed" "default" = fan speed to high
154
157
  */
155
158
  async pushAirPurifierOnChanges(): Promise<void> {
156
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
159
+ await this.debugLog(`pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
157
160
  + ` disablePushOn: ${this.disablePushOn}`);
158
161
  if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
159
162
  const commandType: string = await this.commandType();
@@ -168,7 +171,7 @@ export class AirPurifier extends irdeviceBase {
168
171
  }
169
172
 
170
173
  async pushAirPurifierOffChanges(): Promise<void> {
171
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
174
+ await this.debugLog(`pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
172
175
  + ` disablePushOff: ${this.disablePushOff}`);
173
176
  if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
174
177
  const commandType: string = await this.commandType();
@@ -183,11 +186,11 @@ export class AirPurifier extends irdeviceBase {
183
186
  }
184
187
 
185
188
  async pushAirPurifierStatusChanges(): Promise<void> {
186
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
189
+ await this.debugLog(`pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
187
190
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
188
191
  if (!this.Busy) {
189
192
  this.Busy = true;
190
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
193
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
191
194
  }
192
195
  clearTimeout(this.Timeout);
193
196
 
@@ -196,7 +199,7 @@ export class AirPurifier extends irdeviceBase {
196
199
  }
197
200
 
198
201
  async pushAirPurifierDetailsChanges(): Promise<void> {
199
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
202
+ await this.debugLog(`pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
200
203
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
201
204
  this.CurrentAPTemp = this.TemperatureSensor!.CurrentTemperature ?? 24;
202
205
  this.CurrentAPMode = this.CurrentMode ?? 1;
@@ -210,25 +213,25 @@ export class AirPurifier extends irdeviceBase {
210
213
  });
211
214
  if (this.AirPurifier.Active === 1) {
212
215
  if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
213
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
216
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
214
217
  } else {
215
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
218
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
216
219
  }
217
220
  } else {
218
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
221
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
219
222
  }
220
223
  await this.pushChanges(bodyChange);
221
224
  }
222
225
 
223
226
  async pushChanges(bodyChange: any): Promise<void> {
224
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
227
+ await this.debugLog('pushChanges');
225
228
  if (this.device.connectionType === 'OpenAPI') {
226
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
229
+ this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
227
230
  try {
228
231
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
229
232
  const deviceStatus: any = await body.json();
230
233
  await this.pushStatusCodes(statusCode, deviceStatus);
231
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
234
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
232
235
  await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
233
236
  await this.updateHomeKitCharacteristics();
234
237
  } else {
@@ -240,54 +243,31 @@ export class AirPurifier extends irdeviceBase {
240
243
  await this.pushChangeError(e);
241
244
  }
242
245
  } else {
243
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
244
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
246
+ this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
245
247
  }
246
248
  }
247
249
 
248
250
  async updateHomeKitCharacteristics(): Promise<void> {
251
+ await this.debugLog('updateHomeKitCharacteristics');
249
252
  // Active
250
- if (this.AirPurifier.Active === undefined) {
251
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.AirPurifier.Active}`);
252
- } else {
253
- this.accessory.context.Active = this.AirPurifier.Active;
254
- this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.AirPurifier.Active);
255
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.AirPurifier.Active}`);
256
- }
253
+ await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.Active,
254
+ this.AirPurifier.Active, 'Active');
257
255
  // CurrentAirPurifierState
258
- if (this.AirPurifier.CurrentAirPurifierState === undefined) {
259
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
260
- } else {
261
- this.accessory.context.CurrentAirPurifierState = this.AirPurifier.CurrentAirPurifierState;
262
- this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, this.AirPurifier.CurrentAirPurifierState);
263
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
264
- + ` CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
265
- }
256
+ await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.CurrentAirPurifierState,
257
+ this.AirPurifier.CurrentAirPurifierState, 'CurrentAirPurifierState');
266
258
  // CurrentHeaterCoolerState
267
- if (this.CurrentHeaterCoolerState === undefined) {
268
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
269
- } else {
270
- this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
271
- this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
272
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
273
- + ` CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
274
- }
259
+ await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
260
+ this.AirPurifier.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
275
261
  // CurrentTemperature
276
- if (this.TemperatureSensor.CurrentTemperature === undefined) {
277
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
278
- } else {
279
- this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
280
- this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
281
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
282
- + ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
283
- }
262
+ await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
263
+ this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
284
264
  }
285
265
 
286
266
  async apiError(e: any): Promise<void> {
287
- this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
288
- this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, e);
289
- this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.TargetAirPurifierState, e);
290
267
  this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
268
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.TargetAirPurifierState, e);
269
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, e);
270
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
291
271
  this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
292
272
  }
293
273
  }