@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24

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 (150) hide show
  1. package/config.schema.json +23 -2
  2. package/dist/device/blindtilt.d.ts +21 -98
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +332 -785
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +25 -75
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +566 -778
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +13 -71
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +168 -606
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +13 -78
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +218 -655
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +14 -69
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +196 -553
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +17 -90
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +324 -810
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +58 -0
  27. package/dist/device/device.d.ts.map +1 -0
  28. package/dist/device/device.js +629 -0
  29. package/dist/device/device.js.map +1 -0
  30. package/dist/device/hub.d.ts +15 -63
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +223 -610
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +10 -69
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +192 -595
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +11 -68
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +156 -599
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +10 -72
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +204 -591
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +15 -66
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +199 -566
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +13 -67
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +152 -592
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +13 -68
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +151 -599
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +13 -73
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +129 -540
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +9 -61
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +71 -476
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +11 -66
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +122 -471
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/device/waterdetector.d.ts +9 -66
  71. package/dist/device/waterdetector.d.ts.map +1 -1
  72. package/dist/device/waterdetector.js +105 -478
  73. package/dist/device/waterdetector.js.map +1 -1
  74. package/dist/irdevice/airconditioner.d.ts +5 -36
  75. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  76. package/dist/irdevice/airconditioner.js +228 -337
  77. package/dist/irdevice/airconditioner.js.map +1 -1
  78. package/dist/irdevice/airpurifier.d.ts +5 -34
  79. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  80. package/dist/irdevice/airpurifier.js +19 -267
  81. package/dist/irdevice/airpurifier.js.map +1 -1
  82. package/dist/irdevice/camera.d.ts +5 -34
  83. package/dist/irdevice/camera.d.ts.map +1 -1
  84. package/dist/irdevice/camera.js +13 -261
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +5 -34
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js +13 -260
  89. package/dist/irdevice/fan.js.map +1 -1
  90. package/dist/irdevice/irdevice.d.ts +39 -0
  91. package/dist/irdevice/irdevice.d.ts.map +1 -0
  92. package/dist/irdevice/irdevice.js +502 -0
  93. package/dist/irdevice/irdevice.js.map +1 -0
  94. package/dist/irdevice/light.d.ts +5 -34
  95. package/dist/irdevice/light.d.ts.map +1 -1
  96. package/dist/irdevice/light.js +13 -267
  97. package/dist/irdevice/light.js.map +1 -1
  98. package/dist/irdevice/other.d.ts +18 -48
  99. package/dist/irdevice/other.d.ts.map +1 -1
  100. package/dist/irdevice/other.js +349 -551
  101. package/dist/irdevice/other.js.map +1 -1
  102. package/dist/irdevice/tv.d.ts +7 -40
  103. package/dist/irdevice/tv.d.ts.map +1 -1
  104. package/dist/irdevice/tv.js +79 -325
  105. package/dist/irdevice/tv.js.map +1 -1
  106. package/dist/irdevice/vacuumcleaner.d.ts +6 -36
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +38 -288
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts +6 -36
  111. package/dist/irdevice/waterheater.d.ts.map +1 -1
  112. package/dist/irdevice/waterheater.js +39 -291
  113. package/dist/irdevice/waterheater.js.map +1 -1
  114. package/dist/settings.d.ts +15 -2
  115. package/dist/settings.d.ts.map +1 -1
  116. package/dist/utils.d.ts +68 -0
  117. package/dist/utils.d.ts.map +1 -1
  118. package/dist/utils.js +71 -0
  119. package/dist/utils.js.map +1 -1
  120. package/package.json +8 -8
  121. package/src/device/blindtilt.ts +356 -809
  122. package/src/device/bot.ts +601 -865
  123. package/src/device/ceilinglight.ts +182 -628
  124. package/src/device/colorbulb.ts +235 -683
  125. package/src/device/contact.ts +220 -575
  126. package/src/device/curtain.ts +344 -836
  127. package/src/device/device.ts +655 -0
  128. package/src/device/hub.ts +246 -636
  129. package/src/device/humidifier.ts +224 -645
  130. package/src/device/iosensor.ts +181 -625
  131. package/src/device/lightstrip.ts +230 -622
  132. package/src/device/lock.ts +236 -607
  133. package/src/device/meter.ts +177 -616
  134. package/src/device/meterplus.ts +175 -624
  135. package/src/device/motion.ts +147 -563
  136. package/src/device/plug.ts +81 -505
  137. package/src/device/robotvacuumcleaner.ts +139 -494
  138. package/src/device/waterdetector.ts +126 -506
  139. package/src/irdevice/airconditioner.ts +228 -353
  140. package/src/irdevice/airpurifier.ts +23 -282
  141. package/src/irdevice/camera.ts +18 -277
  142. package/src/irdevice/fan.ts +18 -275
  143. package/src/irdevice/irdevice.ts +518 -0
  144. package/src/irdevice/light.ts +18 -283
  145. package/src/irdevice/other.ts +394 -621
  146. package/src/irdevice/tv.ts +97 -344
  147. package/src/irdevice/vacuumcleaner.ts +46 -310
  148. package/src/irdevice/waterheater.ts +47 -315
  149. package/src/settings.ts +20 -3
  150. package/src/utils.ts +71 -0
@@ -1,24 +1,22 @@
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * airconditioners.ts: @switchbot/homebridge-switchbot.
4
+ */
1
5
  import { request } from 'undici';
6
+ import { irdeviceBase } from './irdevice.js';
2
7
  import { Devices } from '../settings.js';
3
8
  /**
4
9
  * Platform Accessory
5
10
  * An instance of this class is created for each accessory your platform registers
6
11
  * Each accessory may expose multiple services of different service types.
7
12
  */
8
- export class AirConditioner {
13
+ export class AirConditioner extends irdeviceBase {
9
14
  platform;
10
- accessory;
11
- device;
12
- api;
13
- log;
14
- config;
15
- hap;
16
15
  // Services
17
16
  coolerService;
18
17
  // Characteristic Values
19
18
  Active;
20
19
  RotationSpeed;
21
- FirmwareRevision;
22
20
  CurrentTemperature;
23
21
  ThresholdTemperature;
24
22
  CurrentRelativeHumidity;
@@ -35,49 +33,98 @@ export class AirConditioner {
35
33
  static MODE_COOL;
36
34
  static MODE_HEAT;
37
35
  // Config
38
- deviceLogging;
39
36
  hide_automode;
40
37
  set_max_heat;
41
38
  set_min_heat;
42
39
  set_max_cool;
43
40
  set_min_cool;
44
- disablePushOn;
45
- disablePushOff;
46
41
  meter;
47
- disablePushDetail;
48
42
  valid12 = [1, 2];
49
43
  valid012 = [0, 1, 2];
50
44
  constructor(platform, accessory, device) {
45
+ super(platform, accessory, device);
51
46
  this.platform = platform;
52
- this.accessory = accessory;
53
- this.device = device;
54
- this.api = this.platform.api;
55
- this.log = this.platform.log;
56
- this.config = this.platform.config;
57
- this.hap = this.api.hap;
58
- // default placeholders
59
- this.deviceLogs(device);
60
- this.deviceContext();
61
- this.disablePushOnChanges(device);
62
- this.disablePushOffChanges(device);
63
- this.disablePushDetailChanges(device);
64
- this.deviceConfig(device);
65
- // set accessory information
66
- accessory
67
- .getService(this.hap.Service.AccessoryInformation)
68
- .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
69
- .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
70
- .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
71
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
47
+ if (this.Active === undefined) {
48
+ this.Active = this.hap.Characteristic.Active.INACTIVE;
49
+ }
50
+ else if (this.Active) {
51
+ this.Active;
52
+ }
53
+ else {
54
+ this.Active = this.accessory.context.Active;
55
+ }
56
+ if (this.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
57
+ this.CurrentTemperature = 24;
58
+ }
59
+ else {
60
+ this.CurrentTemperature = this.CurrentTemperature || this.accessory.context.CurrentTemperature;
61
+ }
62
+ if (this.ThresholdTemperature === undefined && this.accessory.context.ThresholdTemperature === undefined) {
63
+ this.ThresholdTemperature = 24;
64
+ }
65
+ else {
66
+ this.ThresholdTemperature = this.ThresholdTemperature || this.accessory.context.ThresholdTemperature;
67
+ }
68
+ if (this.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
69
+ this.RotationSpeed = 4;
70
+ }
71
+ else {
72
+ this.RotationSpeed = this.RotationSpeed || this.accessory.context.RotationSpeed;
73
+ }
74
+ if (this.device.irair?.hide_automode) {
75
+ this.hide_automode = this.device.irair?.hide_automode;
76
+ this.accessory.context.hide_automode = this.hide_automode;
77
+ }
78
+ else {
79
+ this.hide_automode = this.device.irair?.hide_automode;
80
+ this.accessory.context.hide_automode = this.hide_automode;
81
+ }
82
+ if (this.device.irair?.set_max_heat) {
83
+ this.set_max_heat = this.device.irair?.set_max_heat;
84
+ this.accessory.context.set_max_heat = this.set_max_heat;
85
+ }
86
+ else {
87
+ this.set_max_heat = 35;
88
+ this.accessory.context.set_max_heat = this.set_max_heat;
89
+ }
90
+ if (this.device.irair?.set_min_heat) {
91
+ this.set_min_heat = this.device.irair?.set_min_heat;
92
+ this.accessory.context.set_min_heat = this.set_min_heat;
93
+ }
94
+ else {
95
+ this.set_min_heat = 0;
96
+ this.accessory.context.set_min_heat = this.set_min_heat;
97
+ }
98
+ if (this.device.irair?.set_max_cool) {
99
+ this.set_max_cool = this.device.irair?.set_max_cool;
100
+ this.accessory.context.set_max_cool = this.set_max_cool;
101
+ }
102
+ else {
103
+ this.set_max_cool = 35;
104
+ this.accessory.context.set_max_cool = this.set_max_cool;
105
+ }
106
+ if (this.device.irair?.set_min_cool) {
107
+ this.set_min_cool = this.device.irair?.set_min_cool;
108
+ this.accessory.context.set_min_cool = this.set_min_cool;
109
+ }
110
+ else {
111
+ this.set_min_cool = 0;
112
+ this.accessory.context.set_min_cool = this.set_min_cool;
113
+ }
114
+ if (this.meter) {
115
+ if (this.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
116
+ this.CurrentRelativeHumidity = 0;
117
+ }
118
+ else {
119
+ this.CurrentRelativeHumidity = this.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
120
+ }
121
+ }
72
122
  // get the Television service if it exists, otherwise create a new Television service
73
123
  // you can create multiple services for each accessory
74
124
  const coolerService = `${accessory.displayName} ${device.remoteType}`;
75
125
  (this.coolerService = accessory.getService(this.hap.Service.HeaterCooler)
76
126
  || accessory.addService(this.hap.Service.HeaterCooler)), coolerService;
77
127
  this.coolerService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
78
- if (!this.coolerService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
79
- this.coolerService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
80
- }
81
128
  // handle on / off events using the Active characteristic
82
129
  this.coolerService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
83
130
  this.coolerService.getCharacteristic(this.hap.Characteristic.CurrentTemperature).onGet(this.CurrentTemperatureGet.bind(this));
@@ -207,7 +254,81 @@ export class AirConditioner {
207
254
  }
208
255
  async UpdateCurrentHeaterCoolerState() {
209
256
  if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
210
- await this.deviceContext();
257
+ if (this.Active === undefined) {
258
+ this.Active = this.hap.Characteristic.Active.INACTIVE;
259
+ }
260
+ else if (this.Active) {
261
+ this.Active;
262
+ }
263
+ else {
264
+ this.Active = this.accessory.context.Active;
265
+ }
266
+ if (this.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
267
+ this.CurrentTemperature = 24;
268
+ }
269
+ else {
270
+ this.CurrentTemperature = this.CurrentTemperature || this.accessory.context.CurrentTemperature;
271
+ }
272
+ if (this.ThresholdTemperature === undefined && this.accessory.context.ThresholdTemperature === undefined) {
273
+ this.ThresholdTemperature = 24;
274
+ }
275
+ else {
276
+ this.ThresholdTemperature = this.ThresholdTemperature || this.accessory.context.ThresholdTemperature;
277
+ }
278
+ if (this.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
279
+ this.RotationSpeed = 4;
280
+ }
281
+ else {
282
+ this.RotationSpeed = this.RotationSpeed || this.accessory.context.RotationSpeed;
283
+ }
284
+ if (this.device.irair?.hide_automode) {
285
+ this.hide_automode = this.device.irair?.hide_automode;
286
+ this.accessory.context.hide_automode = this.hide_automode;
287
+ }
288
+ else {
289
+ this.hide_automode = this.device.irair?.hide_automode;
290
+ this.accessory.context.hide_automode = this.hide_automode;
291
+ }
292
+ if (this.device.irair?.set_max_heat) {
293
+ this.set_max_heat = this.device.irair?.set_max_heat;
294
+ this.accessory.context.set_max_heat = this.set_max_heat;
295
+ }
296
+ else {
297
+ this.set_max_heat = 35;
298
+ this.accessory.context.set_max_heat = this.set_max_heat;
299
+ }
300
+ if (this.device.irair?.set_min_heat) {
301
+ this.set_min_heat = this.device.irair?.set_min_heat;
302
+ this.accessory.context.set_min_heat = this.set_min_heat;
303
+ }
304
+ else {
305
+ this.set_min_heat = 0;
306
+ this.accessory.context.set_min_heat = this.set_min_heat;
307
+ }
308
+ if (this.device.irair?.set_max_cool) {
309
+ this.set_max_cool = this.device.irair?.set_max_cool;
310
+ this.accessory.context.set_max_cool = this.set_max_cool;
311
+ }
312
+ else {
313
+ this.set_max_cool = 35;
314
+ this.accessory.context.set_max_cool = this.set_max_cool;
315
+ }
316
+ if (this.device.irair?.set_min_cool) {
317
+ this.set_min_cool = this.device.irair?.set_min_cool;
318
+ this.accessory.context.set_min_cool = this.set_min_cool;
319
+ }
320
+ else {
321
+ this.set_min_cool = 0;
322
+ this.accessory.context.set_min_cool = this.set_min_cool;
323
+ }
324
+ if (this.meter) {
325
+ if (this.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
326
+ this.CurrentRelativeHumidity = 0;
327
+ }
328
+ else {
329
+ this.CurrentRelativeHumidity = this.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
330
+ }
331
+ }
211
332
  if (this.ThresholdTemperature < this.CurrentTemperature &&
212
333
  this.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.HEAT) {
213
334
  this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
@@ -382,219 +503,6 @@ export class AirConditioner {
382
503
  }
383
504
  }
384
505
  async ThresholdTemperatureGet() {
385
- await this.deviceContext();
386
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get ThresholdTemperature: ${this.ThresholdTemperature}`);
387
- return this.ThresholdTemperature;
388
- }
389
- async ThresholdTemperatureSet(value) {
390
- this.ThresholdTemperature = value;
391
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.ThresholdTemperature},` +
392
- ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
393
- this.pushAirConditionerStatusChanges();
394
- }
395
- async updateHomeKitCharacteristics() {
396
- // Active
397
- if (this.Active === undefined) {
398
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
399
- }
400
- else {
401
- this.accessory.context.Active = this.Active;
402
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
403
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
404
- }
405
- // RotationSpeed
406
- if (this.RotationSpeed === undefined) {
407
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
408
- }
409
- else {
410
- this.accessory.context.RotationSpeed = this.RotationSpeed;
411
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.RotationSpeed);
412
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
413
- }
414
- // CurrentTemperature
415
- if (this.CurrentTemperature === undefined) {
416
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
417
- }
418
- else {
419
- this.accessory.context.CurrentTemperature = this.CurrentTemperature;
420
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
421
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
422
- }
423
- // CurrentRelativeHumidity
424
- if (this.meter) {
425
- if (this.CurrentRelativeHumidity === undefined) {
426
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
427
- }
428
- else {
429
- this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
430
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
431
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
432
- }
433
- }
434
- // TargetHeaterCoolerState
435
- if (this.TargetHeaterCoolerState === undefined) {
436
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
437
- }
438
- else {
439
- this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
440
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
441
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
442
- }
443
- // CurrentHeaterCoolerState
444
- if (this.CurrentHeaterCoolerState === undefined) {
445
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
446
- }
447
- else {
448
- this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
449
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
450
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` +
451
- ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
452
- }
453
- // ThresholdTemperature
454
- if (this.ThresholdTemperature === undefined) {
455
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ThresholdTemperature: ${this.ThresholdTemperature}`);
456
- }
457
- else {
458
- this.accessory.context.ThresholdTemperature = this.ThresholdTemperature;
459
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.ThresholdTemperature);
460
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.ThresholdTemperature);
461
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`);
462
- }
463
- }
464
- async disablePushOnChanges(device) {
465
- if (device.disablePushOn === undefined) {
466
- this.disablePushOn = false;
467
- }
468
- else {
469
- this.disablePushOn = device.disablePushOn;
470
- }
471
- }
472
- async disablePushOffChanges(device) {
473
- if (device.disablePushOff === undefined) {
474
- this.disablePushOff = false;
475
- }
476
- else {
477
- this.disablePushOff = device.disablePushOff;
478
- }
479
- }
480
- async disablePushDetailChanges(device) {
481
- if (device.disablePushDetail === undefined) {
482
- this.disablePushDetail = false;
483
- }
484
- else {
485
- this.disablePushDetail = device.disablePushDetail;
486
- }
487
- }
488
- async commandType() {
489
- let commandType;
490
- if (this.device.customize) {
491
- commandType = 'customize';
492
- }
493
- else {
494
- commandType = 'command';
495
- }
496
- return commandType;
497
- }
498
- async commandOn() {
499
- let command;
500
- if (this.device.customize && this.device.customOn) {
501
- command = this.device.customOn;
502
- }
503
- else {
504
- command = 'turnOn';
505
- }
506
- return command;
507
- }
508
- async commandOff() {
509
- let command;
510
- if (this.device.customize && this.device.customOff) {
511
- command = this.device.customOff;
512
- }
513
- else {
514
- command = 'turnOff';
515
- }
516
- return command;
517
- }
518
- async statusCode(statusCode) {
519
- switch (statusCode) {
520
- case 151:
521
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
522
- break;
523
- case 152:
524
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
525
- break;
526
- case 160:
527
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
528
- break;
529
- case 161:
530
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
531
- break;
532
- case 171:
533
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
534
- `Hub: ${this.device.hubDeviceId}`);
535
- break;
536
- case 190:
537
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
538
- ` Or command format is invalid, statusCode: ${statusCode}`);
539
- break;
540
- case 100:
541
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
542
- break;
543
- case 200:
544
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
545
- break;
546
- case 400:
547
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
548
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
549
- break;
550
- case 401:
551
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
552
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
553
- break;
554
- case 403:
555
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
556
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
557
- break;
558
- case 404:
559
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
560
- + `statusCode: ${statusCode}`);
561
- break;
562
- case 406:
563
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
564
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
565
- break;
566
- case 415:
567
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
568
- + `header that is not supported by the server, statusCode: ${statusCode}`);
569
- break;
570
- case 422:
571
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
572
- + `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
573
- break;
574
- case 429:
575
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
576
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
577
- break;
578
- case 500:
579
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
580
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
581
- break;
582
- default:
583
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
584
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
585
- }
586
- }
587
- async apiError({ e }) {
588
- this.coolerService.updateCharacteristic(this.hap.Characteristic.Active, e);
589
- this.coolerService.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
590
- this.coolerService.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
591
- this.coolerService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
592
- this.coolerService.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, e);
593
- this.coolerService.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
594
- this.coolerService.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, e);
595
- this.coolerService.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, e);
596
- }
597
- async deviceContext() {
598
506
  if (this.Active === undefined) {
599
507
  this.Active = this.hap.Characteristic.Active.INACTIVE;
600
508
  }
@@ -670,110 +578,93 @@ export class AirConditioner {
670
578
  this.CurrentRelativeHumidity = this.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
671
579
  }
672
580
  }
673
- if (this.FirmwareRevision === undefined) {
674
- this.FirmwareRevision = this.platform.version;
675
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
676
- }
581
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get ThresholdTemperature: ${this.ThresholdTemperature}`);
582
+ return this.ThresholdTemperature;
677
583
  }
678
- async deviceConfig(device) {
679
- let config = {};
680
- if (device.irair) {
681
- config = device.irair;
682
- }
683
- if (device.logging !== undefined) {
684
- config['logging'] = device.logging;
685
- }
686
- if (device.connectionType !== undefined) {
687
- config['connectionType'] = device.connectionType;
688
- }
689
- if (device.external !== undefined) {
690
- config['external'] = device.external;
691
- }
692
- if (device.customOn !== undefined) {
693
- config['customOn'] = device.customOn;
694
- }
695
- if (device.customOff !== undefined) {
696
- config['customOff'] = device.customOff;
697
- }
698
- if (device.customize !== undefined) {
699
- config['customize'] = device.customize;
700
- }
701
- if (device.disablePushOn !== undefined) {
702
- config['disablePushOn'] = device.disablePushOn;
703
- }
704
- if (device.disablePushOff !== undefined) {
705
- config['disablePushOff'] = device.disablePushOff;
706
- }
707
- if (device.disablePushDetail !== undefined) {
708
- config['disablePushDetail'] = device.disablePushDetail;
584
+ async ThresholdTemperatureSet(value) {
585
+ this.ThresholdTemperature = value;
586
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.ThresholdTemperature},` +
587
+ ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`);
588
+ this.pushAirConditionerStatusChanges();
589
+ }
590
+ async updateHomeKitCharacteristics() {
591
+ // Active
592
+ if (this.Active === undefined) {
593
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
709
594
  }
710
- if (Object.entries(config).length !== 0) {
711
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
595
+ else {
596
+ this.accessory.context.Active = this.Active;
597
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
598
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
712
599
  }
713
- }
714
- async deviceLogs(device) {
715
- if (this.platform.debugMode) {
716
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
717
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
600
+ // RotationSpeed
601
+ if (this.RotationSpeed === undefined) {
602
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
718
603
  }
719
- else if (device.logging) {
720
- this.deviceLogging = this.accessory.context.logging = device.logging;
721
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
604
+ else {
605
+ this.accessory.context.RotationSpeed = this.RotationSpeed;
606
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.RotationSpeed);
607
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
722
608
  }
723
- else if (this.platform.config.options?.logging) {
724
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
725
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
609
+ // CurrentTemperature
610
+ if (this.CurrentTemperature === undefined) {
611
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
726
612
  }
727
613
  else {
728
- this.deviceLogging = this.accessory.context.logging = 'standard';
729
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
614
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
615
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
616
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
730
617
  }
731
- }
732
- /**
733
- * Logging for Device
734
- */
735
- successLog(...log) {
736
- if (this.enablingDeviceLogging()) {
737
- this.platform.log.success(String(...log));
618
+ // CurrentRelativeHumidity
619
+ if (this.meter) {
620
+ if (this.CurrentRelativeHumidity === undefined) {
621
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
622
+ }
623
+ else {
624
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
625
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
626
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
627
+ }
738
628
  }
739
- }
740
- infoLog(...log) {
741
- if (this.enablingDeviceLogging()) {
742
- this.platform.log.info(String(...log));
629
+ // TargetHeaterCoolerState
630
+ if (this.TargetHeaterCoolerState === undefined) {
631
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
743
632
  }
744
- }
745
- warnLog(...log) {
746
- if (this.enablingDeviceLogging()) {
747
- this.platform.log.warn(String(...log));
633
+ else {
634
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
635
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
636
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
748
637
  }
749
- }
750
- debugWarnLog(...log) {
751
- if (this.enablingDeviceLogging() && this.deviceLogging?.includes('debug')) {
752
- this.platform.log.warn('[DEBUG]', String(...log));
638
+ // CurrentHeaterCoolerState
639
+ if (this.CurrentHeaterCoolerState === undefined) {
640
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
753
641
  }
754
- }
755
- errorLog(...log) {
756
- if (this.enablingDeviceLogging()) {
757
- this.platform.log.error(String(...log));
642
+ else {
643
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
644
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
645
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` +
646
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
758
647
  }
759
- }
760
- debugErrorLog(...log) {
761
- if (this.enablingDeviceLogging() && this.deviceLogging?.includes('debug')) {
762
- this.platform.log.error('[DEBUG]', String(...log));
648
+ // ThresholdTemperature
649
+ if (this.ThresholdTemperature === undefined) {
650
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ThresholdTemperature: ${this.ThresholdTemperature}`);
763
651
  }
764
- }
765
- debugLog(...log) {
766
- if (this.enablingDeviceLogging()) {
767
- if (this.deviceLogging === 'debug') {
768
- this.platform.log.info('[DEBUG]', String(...log));
769
- }
770
- else {
771
- this.platform.log.debug(String(...log));
772
- }
652
+ else {
653
+ this.accessory.context.ThresholdTemperature = this.ThresholdTemperature;
654
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.ThresholdTemperature);
655
+ this.coolerService?.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.ThresholdTemperature);
656
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`);
773
657
  }
774
658
  }
775
- enablingDeviceLogging() {
776
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
659
+ async apiError({ e }) {
660
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.Active, e);
661
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
662
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
663
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
664
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, e);
665
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
666
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, e);
667
+ this.coolerService.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, e);
777
668
  }
778
669
  }
779
670
  //# sourceMappingURL=airconditioner.js.map