@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.0

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