@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.40

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