@switchbot/homebridge-switchbot 3.5.1-beta.10 → 3.5.1-beta.12

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 (57) hide show
  1. package/dist/device/ceilinglight.d.ts.map +1 -1
  2. package/dist/device/ceilinglight.js +6 -9
  3. package/dist/device/ceilinglight.js.map +1 -1
  4. package/dist/device/colorbulb.d.ts.map +1 -1
  5. package/dist/device/colorbulb.js +7 -3
  6. package/dist/device/colorbulb.js.map +1 -1
  7. package/dist/irdevice/airconditioner.d.ts +1 -3
  8. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  9. package/dist/irdevice/airconditioner.js +44 -103
  10. package/dist/irdevice/airconditioner.js.map +1 -1
  11. package/dist/irdevice/airpurifier.d.ts +0 -1
  12. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  13. package/dist/irdevice/airpurifier.js +18 -49
  14. package/dist/irdevice/airpurifier.js.map +1 -1
  15. package/dist/irdevice/camera.d.ts.map +1 -1
  16. package/dist/irdevice/camera.js +9 -9
  17. package/dist/irdevice/camera.js.map +1 -1
  18. package/dist/irdevice/fan.d.ts.map +1 -1
  19. package/dist/irdevice/fan.js +19 -19
  20. package/dist/irdevice/fan.js.map +1 -1
  21. package/dist/irdevice/irdevice.d.ts +22 -10
  22. package/dist/irdevice/irdevice.d.ts.map +1 -1
  23. package/dist/irdevice/irdevice.js +89 -67
  24. package/dist/irdevice/irdevice.js.map +1 -1
  25. package/dist/irdevice/light.d.ts.map +1 -1
  26. package/dist/irdevice/light.js +15 -17
  27. package/dist/irdevice/light.js.map +1 -1
  28. package/dist/irdevice/other.d.ts.map +1 -1
  29. package/dist/irdevice/other.js +76 -76
  30. package/dist/irdevice/other.js.map +1 -1
  31. package/dist/irdevice/tv.d.ts.map +1 -1
  32. package/dist/irdevice/tv.js +35 -35
  33. package/dist/irdevice/tv.js.map +1 -1
  34. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  35. package/dist/irdevice/vacuumcleaner.js +9 -9
  36. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  37. package/dist/irdevice/waterheater.d.ts.map +1 -1
  38. package/dist/irdevice/waterheater.js +9 -9
  39. package/dist/irdevice/waterheater.js.map +1 -1
  40. package/dist/platform.d.ts +1 -1
  41. package/dist/platform.d.ts.map +1 -1
  42. package/dist/platform.js +202 -201
  43. package/dist/platform.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/device/ceilinglight.ts +6 -14
  46. package/src/device/colorbulb.ts +7 -10
  47. package/src/irdevice/airconditioner.ts +53 -97
  48. package/src/irdevice/airpurifier.ts +23 -45
  49. package/src/irdevice/camera.ts +9 -9
  50. package/src/irdevice/fan.ts +19 -19
  51. package/src/irdevice/irdevice.ts +92 -68
  52. package/src/irdevice/light.ts +15 -17
  53. package/src/irdevice/other.ts +76 -76
  54. package/src/irdevice/tv.ts +35 -35
  55. package/src/irdevice/vacuumcleaner.ts +9 -9
  56. package/src/irdevice/waterheater.ts +9 -9
  57. package/src/platform.ts +202 -201
@@ -200,7 +200,8 @@ export class ColorBulb extends deviceBase {
200
200
  this.LightBulb.Saturation = saturation;
201
201
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
202
202
  // ColorTemperature
203
- this.LightBulb.ColorTemperature = Math.max(Math.min(serviceData.color_temperature, 500), 140);
203
+ const miredColorTemperature = Math.round(1000000 / serviceData.color_temperature);
204
+ this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
204
205
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
205
206
  }
206
207
 
@@ -209,35 +210,28 @@ export class ColorBulb extends deviceBase {
209
210
  */
210
211
  async openAPIparseStatus(deviceStatus: colorBulbStatus): Promise<void> {
211
212
  await this.debugLog('openAPIparseStatus');
212
-
213
213
  // On
214
214
  this.LightBulb.On = deviceStatus.power === 'on' ? true : false;
215
215
  await this.debugLog(`On: ${this.LightBulb.On}`);
216
-
217
216
  // Brightness
218
217
  this.LightBulb.Brightness = deviceStatus.brightness;
219
218
  await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
220
-
221
219
  // Color, Hue & Brightness
222
220
  await this.debugLog(`color: ${JSON.stringify(deviceStatus.color)}`);
223
221
  const [red, green, blue] = deviceStatus.color.split(':');
224
222
  await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
225
223
  const [hue, saturation] = rgb2hs(red, green, blue);
226
224
  await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
227
-
228
225
  // Hue
229
226
  this.LightBulb.Hue = hue;
230
227
  await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
231
-
232
228
  // Saturation
233
229
  this.LightBulb.Saturation = saturation;
234
230
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
235
-
236
231
  // ColorTemperature
237
232
  const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
238
233
  this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
239
234
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
240
-
241
235
  // Firmware Version
242
236
  const version = deviceStatus.version.toString();
243
237
  await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
@@ -278,7 +272,8 @@ export class ColorBulb extends deviceBase {
278
272
  this.LightBulb.Saturation = saturation;
279
273
  await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
280
274
  // ColorTemperature
281
- this.LightBulb.ColorTemperature = context.colorTemperature;
275
+ const miredColorTemperature = Math.round(1000000 / context.colorTemperature);
276
+ this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
282
277
  await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
283
278
  }
284
279
 
@@ -489,6 +484,8 @@ export class ColorBulb extends deviceBase {
489
484
  async BLEpushColorTemperatureChanges(): Promise<void> {
490
485
  await this.debugLog('BLEpushColorTemperatureChanges');
491
486
  if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
487
+ const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
488
+ this.accessory.context.kelvin = kelvin;
492
489
  const switchbot = await this.platform.connectBLE(this.accessory, this.device);
493
490
  await this.convertBLEAddress();
494
491
  if (switchbot !== false) {
@@ -496,7 +493,7 @@ export class ColorBulb extends deviceBase {
496
493
  .discover({ model: this.device.bleModel, id: this.device.bleMac })
497
494
  .then(async (device_list: any) => {
498
495
  await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
499
- return await device_list[0].setColorTemperature(this.LightBulb.ColorTemperature);
496
+ return await device_list[0].setColorTemperature(kelvin);
500
497
  })
501
498
  .then(async () => {
502
499
  await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`);
@@ -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;
@@ -181,7 +182,7 @@ export class AirConditioner extends irdeviceBase {
181
182
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
182
183
  */
183
184
  async pushAirConditionerOnChanges(): Promise<void> {
184
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},`
185
+ await this.debugLog(`pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},`
185
186
  + ` disablePushOn: ${this.disablePushOn}`);
186
187
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
187
188
  const commandType: string = await this.commandType();
@@ -196,7 +197,7 @@ export class AirConditioner extends irdeviceBase {
196
197
  }
197
198
 
198
199
  async pushAirConditionerOffChanges(): Promise<void> {
199
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},`
200
+ await this.debugLog(`pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},`
200
201
  + ` disablePushOff: ${this.disablePushOff}`);
201
202
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
202
203
  const commandType: string = await this.commandType();
@@ -211,7 +212,7 @@ export class AirConditioner extends irdeviceBase {
211
212
  }
212
213
 
213
214
  async pushAirConditionerStatusChanges(): Promise<void> {
214
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},`
215
+ await this.debugLog(`pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},`
215
216
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
216
217
  if (!this.Busy) {
217
218
  this.Busy = true;
@@ -224,7 +225,7 @@ export class AirConditioner extends irdeviceBase {
224
225
  }
225
226
 
226
227
  async pushAirConditionerDetailsChanges(): Promise<void> {
227
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},`
228
+ await this.debugLog(`pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},`
228
229
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
229
230
  //await this.deviceContext();
230
231
  if (this.CurrentMode === undefined) {
@@ -241,7 +242,7 @@ export class AirConditioner extends irdeviceBase {
241
242
  if (this.CurrentMode === 1) {
242
243
  // Remove or make configurable?
243
244
  this.HeaterCooler.ThresholdTemperature = 25;
244
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
245
+ await this.debugLog(`CurrentMode: ${this.CurrentMode},`
245
246
  + ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
246
247
  }
247
248
  const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
@@ -344,9 +345,9 @@ export class AirConditioner extends irdeviceBase {
344
345
  }
345
346
 
346
347
  async pushChanges(bodyChange: any): Promise<void> {
347
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
348
+ await this.debugLog('pushChanges');
348
349
  if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
349
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
350
+ await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
350
351
  try {
351
352
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
352
353
  const deviceStatus: any = await body.json();
@@ -363,35 +364,33 @@ export class AirConditioner extends irdeviceBase {
363
364
  await this.pushChangeError(e);
364
365
  }
365
366
  } 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();
367
+ await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
368
+ await this.debugLog(`Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`);
369
+ await this.updateHomeKitCharacteristics();
371
370
  }
372
371
  }
373
372
 
374
373
  async CurrentTemperatureGet(): Promise<CharacteristicValue> {
375
374
  if (this.meter?.context?.CurrentTemperature) {
376
375
  this.accessory.context.CurrentTemperature = this.meter.context.CurrentTemperature;
377
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
376
+ await this.debugLog(''
378
377
  + `Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`);
379
378
  }
380
379
 
381
380
  this.HeaterCooler.CurrentTemperature = this.accessory.context.CurrentTemperature || 24;
382
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
381
+ await this.debugLog(`Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
383
382
  return this.HeaterCooler.CurrentTemperature;
384
383
  }
385
384
 
386
385
  async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
387
386
  if (this.meter?.context?.CurrentRelativeHumidity) {
388
387
  this.accessory.context.CurrentRelativeHumidity = this.meter.context.CurrentRelativeHumidity;
389
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} `
388
+ await this.debugLog(''
390
389
  + `Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`);
391
390
  }
392
391
 
393
392
  this.HumiditySensor!.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity || 0;
394
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get`
393
+ await this.debugLog('Get'
395
394
  + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
396
395
  return this.HumiditySensor!.CurrentRelativeHumidity as CharacteristicValue;
397
396
  }
@@ -402,7 +401,7 @@ export class AirConditioner extends irdeviceBase {
402
401
  } else {
403
402
  this.HeaterCooler.RotationSpeed = this.CurrentFanSpeed - 1;
404
403
  }
405
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
404
+ await this.debugLog(`Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
406
405
  return this.HeaterCooler.RotationSpeed;
407
406
  }
408
407
 
@@ -413,24 +412,23 @@ export class AirConditioner extends irdeviceBase {
413
412
  this.CurrentFanSpeed = Number(value) + 1;
414
413
  }
415
414
  this.HeaterCooler.RotationSpeed = value;
416
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
417
- + `Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
415
+ await this.debugLog(`Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
418
416
  this.pushAirConditionerStatusChanges();
419
417
  }
420
418
 
421
419
  async ActiveSet(value: CharacteristicValue): Promise<void> {
422
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
420
+ await this.debugLog(`Set Active: ${value}`);
423
421
 
424
422
  this.HeaterCooler.Active = value;
425
423
  if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
426
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
424
+ await this.debugLog(`pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
427
425
  if (this.disablePushOn) {
428
426
  this.pushAirConditionerStatusChanges();
429
427
  } else {
430
428
  this.pushAirConditionerOnChanges();
431
429
  }
432
430
  } else {
433
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
431
+ await this.debugLog(`pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
434
432
  this.pushAirConditionerOffChanges();
435
433
  }
436
434
  }
@@ -438,7 +436,7 @@ export class AirConditioner extends irdeviceBase {
438
436
  async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
439
437
  const targetState = this.HeaterCooler.TargetHeaterCoolerState || this.accessory.context.TargetHeaterCoolerState;
440
438
  this.HeaterCooler.TargetHeaterCoolerState = this.ValidValues.includes(targetState) ? targetState : this.ValidValues[0];
441
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
439
+ await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
442
440
  + ` ${this.HeaterCooler.TargetHeaterCoolerState}, ValidValues: ${this.ValidValues}, hide_automode: ${this.hide_automode}`);
443
441
  return this.HeaterCooler.TargetHeaterCoolerState;
444
442
  }
@@ -451,7 +449,7 @@ export class AirConditioner extends irdeviceBase {
451
449
  } else if (value === this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
452
450
  this.TargetHeaterCoolerStateCOOL();
453
451
  } else {
454
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: `
452
+ this.errorLog('Set TargetHeaterCoolerState: '
455
453
  + `${this.HeaterCooler.TargetHeaterCoolerState}, hide_automode: ${this.hide_automode} `);
456
454
  }
457
455
  this.pushAirConditionerStatusChanges();
@@ -460,31 +458,30 @@ export class AirConditioner extends irdeviceBase {
460
458
  async TargetHeaterCoolerStateAUTO(): Promise<void> {
461
459
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO;
462
460
  this.CurrentMode = 1;
463
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO)`
461
+ await this.debugLog('Set (AUTO)'
464
462
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
465
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
463
+ await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
466
464
  }
467
465
 
468
466
  async TargetHeaterCoolerStateCOOL(): Promise<void> {
469
467
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL;
470
468
  this.CurrentMode = 2;
471
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL)`
469
+ await this.debugLog('Set (COOL)'
472
470
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
473
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
471
+ await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
474
472
  }
475
473
 
476
474
  async TargetHeaterCoolerStateHEAT(): Promise<void> {
477
475
  this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT;
478
476
  this.CurrentMode = 5;
479
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT)`
477
+ await this.debugLog('Set (HEAT)'
480
478
  + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
481
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
479
+ await this.debugLog(`Switchbot CurrentMode: ${this.CurrentMode}`);
482
480
  }
483
481
 
484
482
  async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
485
483
  await this.UpdateCurrentHeaterCoolerState();
486
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
487
- + ` Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
484
+ await this.debugLog(`Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
488
485
 
489
486
  return this.HeaterCooler.CurrentHeaterCoolerState;
490
487
  }
@@ -538,89 +535,48 @@ export class AirConditioner extends irdeviceBase {
538
535
  this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
539
536
  }
540
537
  }
541
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
538
+ await this.debugLog(`Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
542
539
  return this.HeaterCooler.ThresholdTemperature;
543
540
  }
544
541
 
545
542
  async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
546
543
  this.HeaterCooler.ThresholdTemperature = value;
547
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},`
544
+ await this.debugLog(`Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},`
548
545
  + ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
549
546
  this.pushAirConditionerStatusChanges();
550
547
  }
551
548
 
552
549
  async updateHomeKitCharacteristics(): Promise<void> {
550
+ await this.debugLog('updateHomeKitCharacteristics');
553
551
  // 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
- }
552
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.Active,
553
+ this.HeaterCooler.Active, 'Active');
561
554
  // 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
- }
555
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.RotationSpeed,
556
+ this.HeaterCooler.RotationSpeed, 'RotationSpeed');
570
557
  // 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
- }
558
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentTemperature,
559
+ this.HeaterCooler.CurrentTemperature, 'CurrentTemperature');
592
560
  // 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
- }
561
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.TargetHeaterCoolerState,
562
+ this.HeaterCooler.TargetHeaterCoolerState, 'TargetHeaterCoolerState');
601
563
  // 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}`);
564
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
565
+ this.HeaterCooler.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
566
+ // HeatingThresholdTemperature
567
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.HeatingThresholdTemperature,
568
+ this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
569
+ // CoolingThresholdTemperature
570
+ await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CoolingThresholdTemperature,
571
+ this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
572
+ if (this.meter && this.HumiditySensor?.Service) {
573
+ // CurrentRelativeHumidity
574
+ await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
575
+ this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
620
576
  }
621
577
  }
622
578
 
623
- async apiError({ e }: { e: any }): Promise<void> {
579
+ async apiError(e: any): Promise<void> {
624
580
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
625
581
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
626
582
  this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
@@ -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;
@@ -64,6 +64,7 @@ export class AirPurifier extends irdeviceBase {
64
64
  RotationSpeed: accessory.context.RotationSpeed ?? 0,
65
65
  CurrentAirPurifierState: accessory.context.CurrentAirPurifierState ?? this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
66
66
  TargetAirPurifierState: accessory.context.TargetAirPurifierState ?? this.hap.Characteristic.TargetAirPurifierState.AUTO,
67
+ CurrentHeaterCoolerState: accessory.context.CurrentHeaterCoolerState ?? this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE,
67
68
  };
68
69
  accessory.context.AirPurifier = this.AirPurifier as object;
69
70
 
@@ -106,7 +107,7 @@ export class AirPurifier extends irdeviceBase {
106
107
  }
107
108
 
108
109
  async ActiveSet(value: CharacteristicValue): Promise<void> {
109
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
110
+ await this.debugLog(`Set Active: ${value}`);
110
111
 
111
112
  this.AirPurifier.Active = value;
112
113
  if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE) {
@@ -153,7 +154,7 @@ export class AirPurifier extends irdeviceBase {
153
154
  * AirPurifier: "command" "highSpeed" "default" = fan speed to high
154
155
  */
155
156
  async pushAirPurifierOnChanges(): Promise<void> {
156
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
157
+ await this.debugLog(`pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
157
158
  + ` disablePushOn: ${this.disablePushOn}`);
158
159
  if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
159
160
  const commandType: string = await this.commandType();
@@ -168,7 +169,7 @@ export class AirPurifier extends irdeviceBase {
168
169
  }
169
170
 
170
171
  async pushAirPurifierOffChanges(): Promise<void> {
171
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
172
+ await this.debugLog(`pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
172
173
  + ` disablePushOff: ${this.disablePushOff}`);
173
174
  if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
174
175
  const commandType: string = await this.commandType();
@@ -183,11 +184,11 @@ export class AirPurifier extends irdeviceBase {
183
184
  }
184
185
 
185
186
  async pushAirPurifierStatusChanges(): Promise<void> {
186
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
187
+ await this.debugLog(`pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
187
188
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
188
189
  if (!this.Busy) {
189
190
  this.Busy = true;
190
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
191
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
191
192
  }
192
193
  clearTimeout(this.Timeout);
193
194
 
@@ -196,7 +197,7 @@ export class AirPurifier extends irdeviceBase {
196
197
  }
197
198
 
198
199
  async pushAirPurifierDetailsChanges(): Promise<void> {
199
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
200
+ await this.debugLog(`pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
200
201
  + ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
201
202
  this.CurrentAPTemp = this.TemperatureSensor!.CurrentTemperature ?? 24;
202
203
  this.CurrentAPMode = this.CurrentMode ?? 1;
@@ -210,20 +211,20 @@ export class AirPurifier extends irdeviceBase {
210
211
  });
211
212
  if (this.AirPurifier.Active === 1) {
212
213
  if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
213
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
214
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
214
215
  } else {
215
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
216
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
216
217
  }
217
218
  } else {
218
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
219
+ this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
219
220
  }
220
221
  await this.pushChanges(bodyChange);
221
222
  }
222
223
 
223
224
  async pushChanges(bodyChange: any): Promise<void> {
224
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
225
+ await this.debugLog('pushChanges');
225
226
  if (this.device.connectionType === 'OpenAPI') {
226
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
227
+ this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
227
228
  try {
228
229
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
229
230
  const deviceStatus: any = await body.json();
@@ -240,47 +241,24 @@ export class AirPurifier extends irdeviceBase {
240
241
  await this.pushChangeError(e);
241
242
  }
242
243
  } else {
243
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
244
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
244
+ this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
245
245
  }
246
246
  }
247
247
 
248
248
  async updateHomeKitCharacteristics(): Promise<void> {
249
+ await this.debugLog('updateHomeKitCharacteristics');
249
250
  // 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
- }
251
+ await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.Active,
252
+ this.AirPurifier.Active, 'Active');
257
253
  // 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
- }
254
+ await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.CurrentAirPurifierState,
255
+ this.AirPurifier.CurrentAirPurifierState, 'CurrentAirPurifierState');
266
256
  // 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
- }
257
+ await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
258
+ this.AirPurifier.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
275
259
  // 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
- }
260
+ await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
261
+ this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
284
262
  }
285
263
 
286
264
  async apiError(e: any): Promise<void> {
@@ -48,7 +48,7 @@ export class Camera extends irdeviceBase {
48
48
  }
49
49
 
50
50
  async OnSet(value: CharacteristicValue): Promise<void> {
51
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
51
+ await this.debugLog(`On: ${value}`);
52
52
 
53
53
  this.Switch.On = value;
54
54
  if (this.Switch.On) {
@@ -69,7 +69,7 @@ export class Camera extends irdeviceBase {
69
69
  * Camera - "command" "channelSub" "default" = previous channel
70
70
  */
71
71
  async pushOnChanges(): Promise<void> {
72
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.Switch.On},`
72
+ await this.debugLog(`pushOnChanges On: ${this.Switch.On},`
73
73
  + ` disablePushOn: ${this.disablePushOn}`);
74
74
  if (this.Switch.On && !this.disablePushOn) {
75
75
  const commandType: string = await this.commandType();
@@ -84,7 +84,7 @@ export class Camera extends irdeviceBase {
84
84
  }
85
85
 
86
86
  async pushOffChanges(): Promise<void> {
87
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.Switch.On},`
87
+ await this.debugLog(`pushOffChanges On: ${this.Switch.On},`
88
88
  + ` disablePushOff: ${this.disablePushOff}`);
89
89
  if (!this.Switch.On && !this.disablePushOff) {
90
90
  const commandType: string = await this.commandType();
@@ -99,9 +99,9 @@ export class Camera extends irdeviceBase {
99
99
  }
100
100
 
101
101
  async pushChanges(bodyChange: any): Promise<void> {
102
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
102
+ await this.debugLog('pushChanges');
103
103
  if (this.device.connectionType === 'OpenAPI') {
104
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
104
+ this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
105
105
  try {
106
106
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
107
107
  const deviceStatus: any = await body.json();
@@ -118,19 +118,19 @@ export class Camera extends irdeviceBase {
118
118
  await this.pushChangeError(e);
119
119
  }
120
120
  } else {
121
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
122
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
121
+ await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
123
122
  }
124
123
  }
125
124
 
126
125
  async updateHomeKitCharacteristics(): Promise<void> {
126
+ await this.debugLog('updateHomeKitCharacteristics');
127
127
  // On
128
128
  if (this.Switch.On === undefined) {
129
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch.On}`);
129
+ await this.debugLog(`On: ${this.Switch.On}`);
130
130
  } else {
131
131
  this.accessory.context.On = this.Switch.On;
132
132
  this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
133
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
133
+ await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
134
134
  }
135
135
  }
136
136