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