@switchbot/homebridge-switchbot 1.11.0 → 1.12.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 (93) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/config.schema.json +18 -3
  3. package/dist/device/bot.d.ts +8 -0
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +40 -21
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +22 -32
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts.map +1 -1
  11. package/dist/device/contact.js +4 -10
  12. package/dist/device/contact.js.map +1 -1
  13. package/dist/device/curtain.d.ts.map +1 -1
  14. package/dist/device/curtain.js +13 -28
  15. package/dist/device/curtain.js.map +1 -1
  16. package/dist/device/humidifier.d.ts.map +1 -1
  17. package/dist/device/humidifier.js +9 -30
  18. package/dist/device/humidifier.js.map +1 -1
  19. package/dist/device/lock.d.ts.map +1 -1
  20. package/dist/device/lock.js +4 -10
  21. package/dist/device/lock.js.map +1 -1
  22. package/dist/device/meter.d.ts.map +1 -1
  23. package/dist/device/meter.js +4 -10
  24. package/dist/device/meter.js.map +1 -1
  25. package/dist/device/motion.d.ts.map +1 -1
  26. package/dist/device/motion.js +4 -10
  27. package/dist/device/motion.js.map +1 -1
  28. package/dist/device/plug.d.ts.map +1 -1
  29. package/dist/device/plug.js +4 -10
  30. package/dist/device/plug.js.map +1 -1
  31. package/dist/irdevice/airconditioner.d.ts +22 -22
  32. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  33. package/dist/irdevice/airconditioner.js +47 -50
  34. package/dist/irdevice/airconditioner.js.map +1 -1
  35. package/dist/irdevice/airpurifier.d.ts +12 -9
  36. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  37. package/dist/irdevice/airpurifier.js +23 -26
  38. package/dist/irdevice/airpurifier.js.map +1 -1
  39. package/dist/irdevice/camera.d.ts +10 -7
  40. package/dist/irdevice/camera.d.ts.map +1 -1
  41. package/dist/irdevice/camera.js +14 -17
  42. package/dist/irdevice/camera.js.map +1 -1
  43. package/dist/irdevice/fan.d.ts +12 -9
  44. package/dist/irdevice/fan.d.ts.map +1 -1
  45. package/dist/irdevice/fan.js +32 -35
  46. package/dist/irdevice/fan.js.map +1 -1
  47. package/dist/irdevice/light.d.ts +10 -7
  48. package/dist/irdevice/light.d.ts.map +1 -1
  49. package/dist/irdevice/light.js +16 -19
  50. package/dist/irdevice/light.js.map +1 -1
  51. package/dist/irdevice/other.d.ts +12 -9
  52. package/dist/irdevice/other.d.ts.map +1 -1
  53. package/dist/irdevice/other.js +21 -24
  54. package/dist/irdevice/other.js.map +1 -1
  55. package/dist/irdevice/tv.d.ts +13 -10
  56. package/dist/irdevice/tv.d.ts.map +1 -1
  57. package/dist/irdevice/tv.js +28 -31
  58. package/dist/irdevice/tv.js.map +1 -1
  59. package/dist/irdevice/vacuumcleaner.d.ts +10 -7
  60. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  61. package/dist/irdevice/vacuumcleaner.js +16 -19
  62. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  63. package/dist/irdevice/waterheater.d.ts +10 -7
  64. package/dist/irdevice/waterheater.d.ts.map +1 -1
  65. package/dist/irdevice/waterheater.js +19 -22
  66. package/dist/irdevice/waterheater.js.map +1 -1
  67. package/dist/platform.d.ts.map +1 -1
  68. package/dist/platform.js +5 -5
  69. package/dist/platform.js.map +1 -1
  70. package/dist/settings.d.ts +1 -0
  71. package/dist/settings.d.ts.map +1 -1
  72. package/dist/settings.js.map +1 -1
  73. package/package.json +4 -4
  74. package/src/device/bot.ts +40 -20
  75. package/src/device/colorbulb.ts +22 -44
  76. package/src/device/contact.ts +4 -12
  77. package/src/device/curtain.ts +13 -28
  78. package/src/device/humidifier.ts +9 -30
  79. package/src/device/lock.ts +4 -10
  80. package/src/device/meter.ts +4 -10
  81. package/src/device/motion.ts +4 -12
  82. package/src/device/plug.ts +4 -10
  83. package/src/irdevice/airconditioner.ts +57 -60
  84. package/src/irdevice/airpurifier.ts +33 -36
  85. package/src/irdevice/camera.ts +22 -25
  86. package/src/irdevice/fan.ts +43 -46
  87. package/src/irdevice/light.ts +26 -29
  88. package/src/irdevice/other.ts +29 -32
  89. package/src/irdevice/tv.ts +45 -50
  90. package/src/irdevice/vacuumcleaner.ts +24 -27
  91. package/src/irdevice/waterheater.ts +27 -30
  92. package/src/platform.ts +9 -9
  93. package/src/settings.ts +1 -0
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
10
  */
11
11
  export class AirConditioner {
12
12
  // Services
13
- service!: Service;
13
+ coolerService!: Service;
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
@@ -76,7 +76,7 @@ export class AirConditioner {
76
76
 
77
77
  // get the Television service if it exists, otherwise create a new Television service
78
78
  // you can create multiple services for each accessory
79
- (this.service = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
79
+ (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
80
80
  `${accessory.displayName} Air Conditioner`;
81
81
 
82
82
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -85,12 +85,12 @@ export class AirConditioner {
85
85
 
86
86
  // set the service name, this is what is displayed as the default name on the Home app
87
87
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
88
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
88
+ this.coolerService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
89
89
 
90
90
  // handle on / off events using the Active characteristic
91
- this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
91
+ this.coolerService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
92
92
 
93
- this.service
93
+ this.coolerService
94
94
  .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
95
95
  .setProps({
96
96
  minValue: 0,
@@ -116,7 +116,7 @@ export class AirConditioner {
116
116
  ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
117
117
  );
118
118
  }
119
- this.service
119
+ this.coolerService
120
120
  .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
121
121
  .setProps({
122
122
  validValues: this.ValidValues,
@@ -126,11 +126,11 @@ export class AirConditioner {
126
126
  })
127
127
  .onSet(this.TargetHeaterCoolerStateSet.bind(this));
128
128
 
129
- this.service.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(async () => {
129
+ this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(async () => {
130
130
  return this.CurrentHeaterCoolerStateGet();
131
131
  });
132
132
 
133
- this.service
133
+ this.coolerService
134
134
  .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
135
135
  .setProps({
136
136
  minValue: 16,
@@ -142,7 +142,7 @@ export class AirConditioner {
142
142
  })
143
143
  .onSet(this.HeatingThresholdTemperatureSet.bind(this));
144
144
 
145
- this.service
145
+ this.coolerService
146
146
  .getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
147
147
  .setProps({
148
148
  minValue: 16,
@@ -154,7 +154,7 @@ export class AirConditioner {
154
154
  })
155
155
  .onSet(this.CoolingThresholdTemperatureSet.bind(this));
156
156
 
157
- this.service
157
+ this.coolerService
158
158
  .getCharacteristic(this.platform.Characteristic.RotationSpeed)
159
159
  .setProps({
160
160
  minStep: 1,
@@ -176,7 +176,7 @@ export class AirConditioner {
176
176
  * AirConditioner: "command" "middleSpeed" "default" = fan speed to medium
177
177
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
178
178
  */
179
- async pushAirConditionerOnChanges() {
179
+ async pushAirConditionerOnChanges(): Promise<void> {
180
180
  if (this.Active !== this.platform.Characteristic.Active.ACTIVE || this.pushOn) {
181
181
  const payload = {
182
182
  commandType: 'command',
@@ -187,7 +187,7 @@ export class AirConditioner {
187
187
  }
188
188
  }
189
189
 
190
- async pushAirConditionerOffChanges() {
190
+ async pushAirConditionerOffChanges(): Promise<void> {
191
191
  const payload = {
192
192
  commandType: 'command',
193
193
  parameter: 'default',
@@ -196,7 +196,7 @@ export class AirConditioner {
196
196
  await this.pushChanges(payload);
197
197
  }
198
198
 
199
- async pushAirConditionerStatusChanges() {
199
+ async pushAirConditionerStatusChanges(): Promise<void> {
200
200
  if (!this.Busy) {
201
201
  this.Busy = true;
202
202
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
@@ -207,7 +207,7 @@ export class AirConditioner {
207
207
  this.Timeout = setTimeout(this.pushAirConditionerDetailsChanges.bind(this), 1500);
208
208
  }
209
209
 
210
- async pushAirConditionerDetailsChanges() {
210
+ async pushAirConditionerDetailsChanges(): Promise<void> {
211
211
  const payload = {
212
212
  commandType: 'command',
213
213
  command: 'setAll',
@@ -247,7 +247,7 @@ export class AirConditioner {
247
247
  await this.pushChanges(payload);
248
248
  }
249
249
 
250
- public async pushChanges(payload: payload) {
250
+ async pushChanges(payload: payload): Promise<void> {
251
251
  try {
252
252
  this.infoLog(
253
253
  `Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
@@ -269,17 +269,14 @@ export class AirConditioner {
269
269
  this.updateHomeKitCharacteristics();
270
270
  } catch (e: any) {
271
271
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
272
- if (this.deviceLogging === 'debug') {
272
+ if (this.deviceLogging.includes('debug')) {
273
273
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
274
274
  }
275
- if (this.platform.debugMode) {
276
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
277
- }
278
275
  this.apiError(e);
279
276
  }
280
277
  }
281
278
 
282
- statusCode(push: AxiosResponse<{ statusCode: number }>) {
279
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
283
280
  switch (push.data.statusCode) {
284
281
  case 151:
285
282
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -310,29 +307,29 @@ export class AirConditioner {
310
307
  }
311
308
  }
312
309
 
313
- updateHomeKitCharacteristics() {
310
+ async updateHomeKitCharacteristics(): Promise<void> {
314
311
  if (this.Active === undefined) {
315
312
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
316
313
  } else {
317
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
314
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
318
315
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
319
316
  }
320
317
  if (this.RotationSpeed === undefined) {
321
318
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
322
319
  } else {
323
- this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
320
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
324
321
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
325
322
  }
326
323
  if (this.CurrentTemperature === undefined) {
327
324
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
328
325
  } else {
329
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
326
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
330
327
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
331
328
  }
332
329
  if (this.TargetHeaterCoolerState === undefined) {
333
330
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
334
331
  } else {
335
- this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
332
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
336
333
  this.debugLog(
337
334
  `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
338
335
  );
@@ -340,7 +337,7 @@ export class AirConditioner {
340
337
  if (this.CurrentHeaterCoolerState === undefined) {
341
338
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
342
339
  } else {
343
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
340
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
344
341
  this.debugLog(
345
342
  `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
346
343
  );
@@ -348,7 +345,7 @@ export class AirConditioner {
348
345
  if (this.HeatingThresholdTemperature === undefined) {
349
346
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
350
347
  } else {
351
- this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
348
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
352
349
  this.debugLog(
353
350
  `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
354
351
  );
@@ -356,25 +353,25 @@ export class AirConditioner {
356
353
  if (this.CoolingThresholdTemperature === undefined) {
357
354
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
358
355
  } else {
359
- this.service?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
356
+ this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
360
357
  this.debugLog(
361
358
  `Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
362
359
  );
363
360
  }
364
361
  }
365
362
 
366
- public apiError(e: any) {
367
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
368
- this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
369
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
370
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
371
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
372
- this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
373
- this.service.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
363
+ async apiError(e: any): Promise<void> {
364
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
365
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
366
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
367
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
368
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
369
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
370
+ this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
374
371
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
375
372
  }
376
373
 
377
- CurrentTemperatureGet() {
374
+ async CurrentTemperatureGet(): Promise<CharacteristicValue> {
378
375
  if (this.CurrentTemperature === undefined) {
379
376
  this.CurrentTemperature = 24;
380
377
  this.CurrentTemperatureCached = this.CurrentTemperature;
@@ -386,7 +383,7 @@ export class AirConditioner {
386
383
  return this.CurrentTemperature;
387
384
  }
388
385
 
389
- RotationSpeedGet() {
386
+ async RotationSpeedGet(): Promise<number> {
390
387
  if (!this.CurrentFanSpeed) {
391
388
  this.RotationSpeed = 4;
392
389
  } else if (this.CurrentFanSpeed === 1) {
@@ -400,7 +397,7 @@ export class AirConditioner {
400
397
  return this.RotationSpeed;
401
398
  }
402
399
 
403
- RotationSpeedSet(value: CharacteristicValue) {
400
+ async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
404
401
  if (value === 4) {
405
402
  this.CurrentFanSpeed = 1;
406
403
  } else {
@@ -412,7 +409,7 @@ export class AirConditioner {
412
409
  this.pushAirConditionerStatusChanges();
413
410
  }
414
411
 
415
- ActiveSet(value: CharacteristicValue) {
412
+ async ActiveSet(value: CharacteristicValue): Promise<void> {
416
413
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
417
414
 
418
415
  this.Active = value;
@@ -432,7 +429,7 @@ export class AirConditioner {
432
429
  }
433
430
  }
434
431
 
435
- TargetHeaterCoolerStateGet() {
432
+ async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
436
433
  if (this.ValidValues === [0, 1, 2]) {
437
434
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
438
435
  this.debugLog(
@@ -457,7 +454,7 @@ export class AirConditioner {
457
454
  return this.TargetHeaterCoolerState;
458
455
  }
459
456
 
460
- TargetHeaterCoolerStateSet(value: CharacteristicValue) {
457
+ async TargetHeaterCoolerStateSet(value: CharacteristicValue): Promise<void> {
461
458
  if (this.hide_automode) {
462
459
  if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
463
460
  this.TargetHeaterCoolerStateHEAT();
@@ -488,28 +485,28 @@ export class AirConditioner {
488
485
  this.pushAirConditionerStatusChanges();
489
486
  }
490
487
 
491
- private TargetHeaterCoolerStateAUTO() {
488
+ async TargetHeaterCoolerStateAUTO(): Promise<void> {
492
489
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
493
490
  this.CurrentMode = 1;
494
491
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
495
492
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
496
493
  }
497
494
 
498
- private TargetHeaterCoolerStateCOOL() {
495
+ async TargetHeaterCoolerStateCOOL(): Promise<void> {
499
496
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
500
497
  this.CurrentMode = 2;
501
498
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
502
499
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
503
500
  }
504
501
 
505
- private TargetHeaterCoolerStateHEAT() {
502
+ async TargetHeaterCoolerStateHEAT(): Promise<void> {
506
503
  this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
507
504
  this.CurrentMode = 5;
508
505
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
509
506
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
510
507
  }
511
508
 
512
- CurrentHeaterCoolerStateGet() {
509
+ async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
513
510
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
514
511
  this.CurrentTemperatureUndefined();
515
512
  if (this.CurrentTemperature < this.CurrentTemperatureCached) {
@@ -528,7 +525,7 @@ export class AirConditioner {
528
525
  return this.CurrentHeaterCoolerState;
529
526
  }
530
527
 
531
- private HeatingThresholdTemperatureGet() {
528
+ async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
532
529
  this.CurrentTemperatureUndefined;
533
530
  this.CurrentTemperature = this.CurrentTemperatureCached;
534
531
  this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
@@ -538,7 +535,7 @@ export class AirConditioner {
538
535
  return this.HeatingThresholdTemperature;
539
536
  }
540
537
 
541
- private HeatingThresholdTemperatureSet(value: CharacteristicValue) {
538
+ async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
542
539
  this.CurrentTemperatureCached = this.CurrentTemperature;
543
540
  this.CurrentTemperature = value;
544
541
  this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
@@ -550,7 +547,7 @@ export class AirConditioner {
550
547
  this.pushAirConditionerStatusChanges();
551
548
  }
552
549
 
553
- private CoolingThresholdTemperatureGet() {
550
+ async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
554
551
  this.CurrentTemperatureUndefined;
555
552
  this.CurrentTemperature = this.CurrentTemperatureCached;
556
553
  this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
@@ -560,7 +557,7 @@ export class AirConditioner {
560
557
  return this.CoolingThresholdTemperature;
561
558
  }
562
559
 
563
- private CoolingThresholdTemperatureSet(value: CharacteristicValue) {
560
+ async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
564
561
  this.CurrentTemperatureCached = this.CurrentTemperature;
565
562
  this.CurrentTemperature = value;
566
563
  this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
@@ -572,7 +569,7 @@ export class AirConditioner {
572
569
  this.pushAirConditionerStatusChanges();
573
570
  }
574
571
 
575
- private CurrentTemperatureUndefined() {
572
+ async CurrentTemperatureUndefined(): Promise<void> {
576
573
  if (this.CurrentTemperature === undefined) {
577
574
  this.CurrentTemperature = 24;
578
575
  }
@@ -581,7 +578,7 @@ export class AirConditioner {
581
578
  }
582
579
  }
583
580
 
584
- config(device: irdevice & irDevicesConfig) {
581
+ async config(device: irdevice & irDevicesConfig): Promise<void> {
585
582
  let config = {};
586
583
  if (device.irair) {
587
584
  config = device.irair;
@@ -590,11 +587,11 @@ export class AirConditioner {
590
587
  config['logging'] = device.logging;
591
588
  }
592
589
  if (Object.entries(config).length !== 0) {
593
- this.warnLog(`Air Conditioner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
590
+ this.infoLog(`Air Conditioner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
594
591
  }
595
592
  }
596
593
 
597
- logs(device: irdevice & irDevicesConfig) {
594
+ async logs(device: irdevice & irDevicesConfig): Promise<void> {
598
595
  if (this.platform.debugMode) {
599
596
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
600
597
  this.debugLog(`Air Conditioner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -611,7 +608,7 @@ export class AirConditioner {
611
608
  }
612
609
 
613
610
 
614
- pushOnChanges(device: irdevice & irDevicesConfig) {
611
+ async pushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
615
612
  if (device.irair?.pushOn) {
616
613
  this.pushOn = true;
617
614
  } else {
@@ -622,25 +619,25 @@ export class AirConditioner {
622
619
  /**
623
620
  * Logging for Device
624
621
  */
625
- infoLog(...log: any[]) {
622
+ infoLog(...log: any[]): void {
626
623
  if (this.enablingDeviceLogging()) {
627
624
  this.platform.log.info(String(...log));
628
625
  }
629
626
  }
630
627
 
631
- warnLog(...log: any[]) {
628
+ warnLog(...log: any[]): void {
632
629
  if (this.enablingDeviceLogging()) {
633
630
  this.platform.log.warn(String(...log));
634
631
  }
635
632
  }
636
633
 
637
- errorLog(...log: any[]) {
634
+ errorLog(...log: any[]): void {
638
635
  if (this.enablingDeviceLogging()) {
639
636
  this.platform.log.error(String(...log));
640
637
  }
641
638
  }
642
639
 
643
- debugLog(...log: any[]) {
640
+ debugLog(...log: any[]): void {
644
641
  if (this.enablingDeviceLogging()) {
645
642
  if (this.deviceLogging === 'debug') {
646
643
  this.platform.log.info('[DEBUG]', String(...log));
@@ -651,6 +648,6 @@ export class AirConditioner {
651
648
  }
652
649
 
653
650
  enablingDeviceLogging(): boolean {
654
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
651
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
655
652
  }
656
653
  }
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
10
10
  */
11
11
  export class AirPurifier {
12
12
  // Services
13
- service!: Service;
13
+ airPurifierService!: Service;
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
@@ -62,7 +62,7 @@ export class AirPurifier {
62
62
 
63
63
  // get the Television service if it exists, otherwise create a new Television service
64
64
  // you can create multiple services for each accessory
65
- (this.service = accessory.getService(this.platform.Service.AirPurifier) || accessory.addService(this.platform.Service.AirPurifier)),
65
+ (this.airPurifierService = accessory.getService(this.platform.Service.AirPurifier) || accessory.addService(this.platform.Service.AirPurifier)),
66
66
  `${accessory.displayName} Air Purifier`;
67
67
 
68
68
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -71,19 +71,19 @@ export class AirPurifier {
71
71
 
72
72
  // set the service name, this is what is displayed as the default name on the Home app
73
73
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
74
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
74
+ this.airPurifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
75
75
 
76
76
  // handle on / off events using the Active characteristic
77
- this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
77
+ this.airPurifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
78
78
 
79
- this.service.getCharacteristic(this.platform.Characteristic.CurrentAirPurifierState).onGet(() => {
79
+ this.airPurifierService.getCharacteristic(this.platform.Characteristic.CurrentAirPurifierState).onGet(() => {
80
80
  return this.CurrentAirPurifierStateGet();
81
81
  });
82
82
 
83
- this.service.getCharacteristic(this.platform.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
83
+ this.airPurifierService.getCharacteristic(this.platform.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
84
84
  }
85
85
 
86
- private ActiveSet(value: CharacteristicValue) {
86
+ async ActiveSet(value: CharacteristicValue): Promise<void> {
87
87
  this.debugLog(`Air Purifier: ${this.accessory.displayName} Set Active: ${value}`);
88
88
  if (value === this.platform.Characteristic.Active.INACTIVE) {
89
89
  this.pushAirPurifierOffChanges();
@@ -95,30 +95,30 @@ export class AirPurifier {
95
95
  this.accessory.context.Active = this.ActiveCached;
96
96
  }
97
97
 
98
- private updateHomeKitCharacteristics() {
98
+ async updateHomeKitCharacteristics(): Promise<void> {
99
99
  if (this.Active === undefined) {
100
100
  this.debugLog(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
101
101
  } else {
102
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
102
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
103
103
  this.debugLog(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
104
104
  }
105
105
  if (this.CurrentAirPurifierState === undefined) {
106
106
  this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
107
107
  } else {
108
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
108
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
109
109
  this.debugLog(`Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
110
110
  }
111
111
  if (this.CurrentHeaterCoolerState === undefined) {
112
112
  this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
113
113
  } else {
114
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
114
+ this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
115
115
  this.debugLog(
116
116
  `Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
117
117
  );
118
118
  }
119
119
  }
120
120
 
121
- private TargetAirPurifierStateSet(value: CharacteristicValue) {
121
+ async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
122
122
  switch (value) {
123
123
  case this.platform.Characteristic.CurrentAirPurifierState.PURIFYING_AIR:
124
124
  this.CurrentMode = AirPurifier.PURIFYING_AIR;
@@ -134,7 +134,7 @@ export class AirPurifier {
134
134
  }
135
135
  }
136
136
 
137
- private CurrentAirPurifierStateGet() {
137
+ async CurrentAirPurifierStateGet(): Promise<number> {
138
138
  if (this.Active === 1) {
139
139
  this.CurrentAirPurifierState = this.platform.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
140
140
  } else {
@@ -154,7 +154,7 @@ export class AirPurifier {
154
154
  * AirPurifier: "command" "middleSpeed" "default" = fan speed to medium
155
155
  * AirPurifier: "command" "highSpeed" "default" = fan speed to high
156
156
  */
157
- async pushAirPurifierOnChanges() {
157
+ async pushAirPurifierOnChanges(): Promise<void> {
158
158
  if (this.Active !== 1) {
159
159
  const payload = {
160
160
  commandType: 'command',
@@ -165,7 +165,7 @@ export class AirPurifier {
165
165
  }
166
166
  }
167
167
 
168
- async pushAirPurifierOffChanges() {
168
+ async pushAirPurifierOffChanges(): Promise<void> {
169
169
  if (this.Active !== 0) {
170
170
  const payload = {
171
171
  commandType: 'command',
@@ -176,7 +176,7 @@ export class AirPurifier {
176
176
  }
177
177
  }
178
178
 
179
- async pushAirConditionerStatusChanges() {
179
+ async pushAirConditionerStatusChanges(): Promise<void> {
180
180
  if (!this.Busy) {
181
181
  this.Busy = true;
182
182
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
@@ -187,7 +187,7 @@ export class AirPurifier {
187
187
  this.Timeout = setTimeout(this.pushAirConditionerDetailsChanges.bind(this), 1500);
188
188
  }
189
189
 
190
- async pushAirConditionerDetailsChanges() {
190
+ async pushAirConditionerDetailsChanges(): Promise<void> {
191
191
  const payload = {
192
192
  commandType: 'command',
193
193
  command: 'setAll',
@@ -212,7 +212,7 @@ export class AirPurifier {
212
212
  await this.pushChanges(payload);
213
213
  }
214
214
 
215
- public async pushChanges(payload: payload) {
215
+ async pushChanges(payload: payload): Promise<void> {
216
216
  try {
217
217
  this.infoLog(
218
218
  `Air Purifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
@@ -228,19 +228,16 @@ export class AirPurifier {
228
228
  this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
229
229
  } catch (e: any) {
230
230
  this.errorLog(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
231
- if (this.deviceLogging === 'debug') {
231
+ if (this.deviceLogging.includes('debug')) {
232
232
  this.errorLog(
233
233
  `Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
234
234
  );
235
235
  }
236
- if (this.platform.debugMode) {
237
- this.errorLog(`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
238
- }
239
236
  this.apiError(e);
240
237
  }
241
238
  }
242
239
 
243
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
240
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
244
241
  switch (push.data.statusCode) {
245
242
  case 151:
246
243
  this.errorLog(`Air Purifier: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -271,15 +268,15 @@ export class AirPurifier {
271
268
  }
272
269
  }
273
270
 
274
- public apiError(e: any) {
275
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
276
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
277
- this.service.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
278
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
271
+ async apiError(e: any): Promise<void> {
272
+ this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
273
+ this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
274
+ this.airPurifierService.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
275
+ this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
279
276
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
280
277
  }
281
278
 
282
- config(device: irdevice & irDevicesConfig) {
279
+ async config(device: irdevice & irDevicesConfig): Promise<void> {
283
280
  let config = {};
284
281
  if (device.irpur) {
285
282
  config = device.irpur;
@@ -288,11 +285,11 @@ export class AirPurifier {
288
285
  config['logging'] = device.logging;
289
286
  }
290
287
  if (Object.entries(config).length !== 0) {
291
- this.warnLog(`Air Purifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
288
+ this.infoLog(`Air Purifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
292
289
  }
293
290
  }
294
291
 
295
- logs(device: irdevice & irDevicesConfig) {
292
+ async logs(device: irdevice & irDevicesConfig): Promise<void> {
296
293
  if (this.platform.debugMode) {
297
294
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
298
295
  this.debugLog(`Air Purifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -311,25 +308,25 @@ export class AirPurifier {
311
308
  /**
312
309
  * Logging for Device
313
310
  */
314
- infoLog(...log: any[]) {
311
+ infoLog(...log: any[]): void {
315
312
  if (this.enablingDeviceLogging()) {
316
313
  this.platform.log.info(String(...log));
317
314
  }
318
315
  }
319
316
 
320
- warnLog(...log: any[]) {
317
+ warnLog(...log: any[]): void {
321
318
  if (this.enablingDeviceLogging()) {
322
319
  this.platform.log.warn(String(...log));
323
320
  }
324
321
  }
325
322
 
326
- errorLog(...log: any[]) {
323
+ errorLog(...log: any[]): void {
327
324
  if (this.enablingDeviceLogging()) {
328
325
  this.platform.log.error(String(...log));
329
326
  }
330
327
  }
331
328
 
332
- debugLog(...log: any[]) {
329
+ debugLog(...log: any[]): void {
333
330
  if (this.enablingDeviceLogging()) {
334
331
  if (this.deviceLogging === 'debug') {
335
332
  this.platform.log.info('[DEBUG]', String(...log));
@@ -340,6 +337,6 @@ export class AirPurifier {
340
337
  }
341
338
 
342
339
  enablingDeviceLogging(): boolean {
343
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
340
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
344
341
  }
345
342
  }