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

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