@switchbot/homebridge-switchbot 3.5.0-beta.7 → 3.5.0-beta.70

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 +120 -17
  4. package/dist/device/blindtilt.d.ts +23 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +425 -778
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +26 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +803 -837
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +14 -68
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +241 -606
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +14 -75
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +283 -658
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +15 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +254 -545
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +19 -88
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +412 -806
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +59 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +711 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +51 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +540 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +16 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +261 -616
  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 +240 -594
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +11 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +196 -600
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +11 -69
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +281 -586
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +16 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +252 -560
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +14 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +191 -593
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +14 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +180 -593
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +13 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +188 -532
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +9 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +96 -458
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +12 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +202 -521
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +10 -63
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +146 -475
  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 +324 -452
  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 +93 -307
  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 +39 -281
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +10 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +113 -341
  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 +330 -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 +87 -335
  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 +19 -6
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +310 -172
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +62 -19
  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 +19 -15
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +462 -817
  143. package/src/device/bot.ts +862 -931
  144. package/src/device/ceilinglight.ts +259 -633
  145. package/src/device/colorbulb.ts +300 -688
  146. package/src/device/contact.ts +288 -571
  147. package/src/device/curtain.ts +441 -838
  148. package/src/device/device.ts +734 -0
  149. package/src/device/fan.ts +596 -0
  150. package/src/device/hub.ts +299 -645
  151. package/src/device/humidifier.ts +274 -647
  152. package/src/device/iosensor.ts +233 -626
  153. package/src/device/lightstrip.ts +309 -620
  154. package/src/device/lock.ts +292 -601
  155. package/src/device/meter.ts +228 -619
  156. package/src/device/meterplus.ts +216 -619
  157. package/src/device/motion.ts +218 -559
  158. package/src/device/plug.ts +111 -490
  159. package/src/device/robotvacuumcleaner.ts +228 -550
  160. package/src/device/waterdetector.ts +169 -501
  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 +350 -477
  165. package/src/irdevice/airpurifier.ts +120 -330
  166. package/src/irdevice/camera.ts +53 -301
  167. package/src/irdevice/fan.ts +130 -360
  168. package/src/irdevice/irdevice.ts +346 -0
  169. package/src/irdevice/light.ts +157 -412
  170. package/src/irdevice/other.ts +507 -648
  171. package/src/irdevice/tv.ts +117 -367
  172. package/src/irdevice/vacuumcleaner.ts +59 -311
  173. package/src/irdevice/waterheater.ts +61 -320
  174. package/src/platform.ts +355 -219
  175. package/src/settings.ts +116 -611
  176. package/src/utils.ts +642 -1
  177. 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
- }
90
-
91
- // handle on / off events using the Active characteristic
92
- this.coolerService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
58
+ super(platform, accessory, device);
93
59
 
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
  /**
@@ -157,10 +183,10 @@ export class AirConditioner {
157
183
  */
158
184
  async pushAirConditionerOnChanges(): Promise<void> {
159
185
  this.debugLog(
160
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.Active},` +
186
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.HeaterCooler.Active},` +
161
187
  ` disablePushOn: ${this.disablePushOn}`,
162
188
  );
163
- if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
189
+ if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
164
190
  const commandType: string = await this.commandType();
165
191
  const command: string = await this.commandOn();
166
192
  const bodyChange = JSON.stringify({
@@ -174,10 +200,10 @@ export class AirConditioner {
174
200
 
175
201
  async pushAirConditionerOffChanges(): Promise<void> {
176
202
  this.debugLog(
177
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.Active},` +
203
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.HeaterCooler.Active},` +
178
204
  ` disablePushOff: ${this.disablePushOff}`,
179
205
  );
180
- if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
206
+ if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
181
207
  const commandType: string = await this.commandType();
182
208
  const command: string = await this.commandOff();
183
209
  const bodyChange = JSON.stringify({
@@ -191,12 +217,12 @@ export class AirConditioner {
191
217
 
192
218
  async pushAirConditionerStatusChanges(): Promise<void> {
193
219
  this.debugLog(
194
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},` +
220
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.HeaterCooler.Active},` +
195
221
  ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
196
222
  );
197
223
  if (!this.Busy) {
198
224
  this.Busy = true;
199
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
225
+ this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
200
226
  }
201
227
  clearTimeout(this.Timeout);
202
228
 
@@ -206,7 +232,7 @@ export class AirConditioner {
206
232
 
207
233
  async pushAirConditionerDetailsChanges(): Promise<void> {
208
234
  this.debugLog(
209
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},` +
235
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.HeaterCooler.Active},` +
210
236
  ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
211
237
  );
212
238
  //await this.deviceContext();
@@ -216,20 +242,20 @@ export class AirConditioner {
216
242
  if (this.CurrentFanSpeed === undefined) {
217
243
  this.CurrentFanSpeed = 1;
218
244
  }
219
- if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
245
+ if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
220
246
  this.state = 'on';
221
247
  } else {
222
248
  this.state = 'off';
223
249
  }
224
250
  if (this.CurrentMode === 1) {
225
251
  // Remove or make configurable?
226
- this.ThresholdTemperature = 25;
252
+ this.HeaterCooler.ThresholdTemperature = 25;
227
253
  this.debugLog(
228
254
  `${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},` +
229
- ` ThresholdTemperature: ${this.ThresholdTemperature}`,
255
+ ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`,
230
256
  );
231
257
  }
232
- const parameter = `${this.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
258
+ const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
233
259
 
234
260
  await this.UpdateCurrentHeaterCoolerState();
235
261
  const bodyChange = JSON.stringify({
@@ -242,19 +268,91 @@ export class AirConditioner {
242
268
  }
243
269
 
244
270
  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;
271
+ if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
272
+
273
+ if (this.HeaterCooler.Active === undefined) {
274
+ this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE;
275
+ } else if (this.HeaterCooler.Active) {
276
+ this.HeaterCooler.Active;
277
+ } else {
278
+ this.HeaterCooler.Active = this.accessory.context.Active;
279
+ }
280
+
281
+ if (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
282
+ this.HeaterCooler.CurrentTemperature = 24;
283
+ } else {
284
+ this.HeaterCooler.CurrentTemperature = this.HeaterCooler.CurrentTemperature || this.accessory.context.CurrentTemperature;
285
+ }
286
+
287
+ if (this.HeaterCooler.ThresholdTemperature === undefined && this.accessory.context.ThresholdTemperature === undefined) {
288
+ this.HeaterCooler.ThresholdTemperature = 24;
289
+ } else {
290
+ this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature || this.accessory.context.ThresholdTemperature;
291
+ }
292
+
293
+ if (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
294
+ this.HeaterCooler.RotationSpeed = 4;
295
+ } else {
296
+ this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed;
297
+ }
298
+
299
+ if (this.device.irair?.hide_automode) {
300
+ this.hide_automode = this.device.irair?.hide_automode;
301
+ this.accessory.context.hide_automode = this.hide_automode;
302
+ } else {
303
+ this.hide_automode = this.device.irair?.hide_automode;
304
+ this.accessory.context.hide_automode = this.hide_automode;
305
+ }
306
+
307
+ if (this.device.irair?.set_max_heat) {
308
+ this.set_max_heat = this.device.irair?.set_max_heat;
309
+ this.accessory.context.set_max_heat = this.set_max_heat;
310
+ } else {
311
+ this.set_max_heat = 35;
312
+ this.accessory.context.set_max_heat = this.set_max_heat;
313
+ }
314
+ if (this.device.irair?.set_min_heat) {
315
+ this.set_min_heat = this.device.irair?.set_min_heat;
316
+ this.accessory.context.set_min_heat = this.set_min_heat;
317
+ } else {
318
+ this.set_min_heat = 0;
319
+ this.accessory.context.set_min_heat = this.set_min_heat;
320
+ }
321
+
322
+ if (this.device.irair?.set_max_cool) {
323
+ this.set_max_cool = this.device.irair?.set_max_cool;
324
+ this.accessory.context.set_max_cool = this.set_max_cool;
325
+ } else {
326
+ this.set_max_cool = 35;
327
+ this.accessory.context.set_max_cool = this.set_max_cool;
328
+ }
329
+ if (this.device.irair?.set_min_cool) {
330
+ this.set_min_cool = this.device.irair?.set_min_cool;
331
+ this.accessory.context.set_min_cool = this.set_min_cool;
332
+ } else {
333
+ this.set_min_cool = 0;
334
+ this.accessory.context.set_min_cool = this.set_min_cool;
335
+ }
336
+
337
+ if (this.meter) {
338
+ if (this.HumiditySensor!.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
339
+ this.HumiditySensor!.CurrentRelativeHumidity = 0;
340
+ } else {
341
+ this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity
342
+ || this.accessory.context.CurrentRelativeHumidity;
343
+ }
344
+ }
345
+ if (this.HeaterCooler.ThresholdTemperature < this.HeaterCooler.CurrentTemperature &&
346
+ this.HeaterCooler.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.HEAT) {
347
+ this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
348
+ } else if (this.HeaterCooler.ThresholdTemperature > this.HeaterCooler.CurrentTemperature &&
349
+ this.HeaterCooler.TargetHeaterCoolerState !== this.hap.Characteristic.TargetHeaterCoolerState.COOL) {
350
+ this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
253
351
  } else {
254
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
352
+ this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
255
353
  }
256
354
  } else {
257
- this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
355
+ this.HeaterCooler.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
258
356
  }
259
357
  }
260
358
 
@@ -273,8 +371,10 @@ export class AirConditioner {
273
371
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
274
372
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
275
373
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
276
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
374
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
277
375
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
376
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
377
+ + ` request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
278
378
  this.updateHomeKitCharacteristics();
279
379
  } else {
280
380
  this.statusCode(statusCode);
@@ -309,9 +409,9 @@ export class AirConditioner {
309
409
  );
310
410
  }
311
411
 
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;
412
+ this.HeaterCooler.CurrentTemperature = this.accessory.context.CurrentTemperature || 24;
413
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
414
+ return this.HeaterCooler.CurrentTemperature;
315
415
  }
316
416
 
317
417
  async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
@@ -323,19 +423,20 @@ export class AirConditioner {
323
423
  );
324
424
  }
325
425
 
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;
426
+ this.HumiditySensor!.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity || 0;
427
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get`
428
+ + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
429
+ return this.HumiditySensor!.CurrentRelativeHumidity as CharacteristicValue;
329
430
  }
330
431
 
331
432
  async RotationSpeedGet(): Promise<number> {
332
433
  if (!this.CurrentFanSpeed || this.CurrentFanSpeed === 1) {
333
- this.RotationSpeed = 4;
434
+ this.HeaterCooler.RotationSpeed = 4;
334
435
  } else {
335
- this.RotationSpeed = this.CurrentFanSpeed - 1;
436
+ this.HeaterCooler.RotationSpeed = this.CurrentFanSpeed - 1;
336
437
  }
337
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
338
- return this.RotationSpeed;
438
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
439
+ return this.HeaterCooler.RotationSpeed;
339
440
  }
340
441
 
341
442
  async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
@@ -344,37 +445,35 @@ export class AirConditioner {
344
445
  } else {
345
446
  this.CurrentFanSpeed = Number(value) + 1;
346
447
  }
347
- this.RotationSpeed = value;
448
+ this.HeaterCooler.RotationSpeed = value;
348
449
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` +
349
- `Set RotationSpeed: ${this.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
450
+ `Set RotationSpeed: ${this.HeaterCooler.RotationSpeed}, CurrentFanSpeed: ${this.CurrentFanSpeed}`);
350
451
  this.pushAirConditionerStatusChanges();
351
452
  }
352
453
 
353
454
  async ActiveSet(value: CharacteristicValue): Promise<void> {
354
455
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
355
456
 
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}`);
457
+ this.HeaterCooler.Active = value;
458
+ if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE) {
459
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.HeaterCooler.Active}`);
359
460
  if (this.disablePushOn) {
360
461
  this.pushAirConditionerStatusChanges();
361
462
  } else {
362
463
  this.pushAirConditionerOnChanges();
363
464
  }
364
465
  } else {
365
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
466
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.HeaterCooler.Active}`);
366
467
  this.pushAirConditionerOffChanges();
367
468
  }
368
469
  }
369
470
 
370
471
  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;
472
+ const targetState = this.HeaterCooler.TargetHeaterCoolerState || this.accessory.context.TargetHeaterCoolerState;
473
+ this.HeaterCooler.TargetHeaterCoolerState = this.ValidValues.includes(targetState) ? targetState : this.ValidValues[0];
474
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get (${this.getTargetHeaterCoolerStateName()}) TargetHeaterCoolerState:`
475
+ + ` ${this.HeaterCooler.TargetHeaterCoolerState}, ValidValues: ${this.ValidValues}, hide_automode: ${this.hide_automode}`);
476
+ return this.HeaterCooler.TargetHeaterCoolerState;
378
477
  }
379
478
 
380
479
  async TargetHeaterCoolerStateSet(value: CharacteristicValue): Promise<void> {
@@ -386,7 +485,7 @@ export class AirConditioner {
386
485
  this.TargetHeaterCoolerStateCOOL();
387
486
  } else {
388
487
  this.errorLog(
389
- `${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
488
+ `${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState},` +
390
489
  ` hide_automode: ${this.hide_automode} `,
391
490
  );
392
491
  }
@@ -394,23 +493,26 @@ export class AirConditioner {
394
493
  }
395
494
 
396
495
  async TargetHeaterCoolerStateAUTO(): Promise<void> {
397
- this.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO;
496
+ this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.AUTO;
398
497
  this.CurrentMode = 1;
399
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
498
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO)`
499
+ + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
400
500
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
401
501
  }
402
502
 
403
503
  async TargetHeaterCoolerStateCOOL(): Promise<void> {
404
- this.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL;
504
+ this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.COOL;
405
505
  this.CurrentMode = 2;
406
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
506
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL)`
507
+ + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
407
508
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
408
509
  }
409
510
 
410
511
  async TargetHeaterCoolerStateHEAT(): Promise<void> {
411
- this.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT;
512
+ this.HeaterCooler.TargetHeaterCoolerState = this.hap.Characteristic.TargetHeaterCoolerState.HEAT;
412
513
  this.CurrentMode = 5;
413
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
514
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT)`
515
+ + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
414
516
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
415
517
  }
416
518
 
@@ -418,15 +520,15 @@ export class AirConditioner {
418
520
  await this.UpdateCurrentHeaterCoolerState();
419
521
  this.debugLog(
420
522
  `${this.device.remoteType}: ${this.accessory.displayName}` +
421
- ` Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
523
+ ` Get (${this.getTargetHeaterCoolerStateName()}) CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`,
422
524
  );
423
525
 
424
- return this.CurrentHeaterCoolerState;
526
+ return this.HeaterCooler.CurrentHeaterCoolerState;
425
527
  }
426
528
 
427
529
 
428
530
  private getTargetHeaterCoolerStateName(): string {
429
- switch (this.TargetHeaterCoolerState) {
531
+ switch (this.HeaterCooler.TargetHeaterCoolerState) {
430
532
  case this.hap.Characteristic.TargetHeaterCoolerState.AUTO:
431
533
  return 'AUTO';
432
534
  case this.hap.Characteristic.TargetHeaterCoolerState.HEAT:
@@ -434,20 +536,55 @@ export class AirConditioner {
434
536
  case this.hap.Characteristic.TargetHeaterCoolerState.COOL:
435
537
  return 'COOL';
436
538
  default:
437
- return this.TargetHeaterCoolerState.toString();
539
+ return this.HeaterCooler.TargetHeaterCoolerState.toString();
438
540
  }
439
541
  }
440
542
 
441
543
  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;
544
+
545
+ if (this.HeaterCooler.Active === undefined) {
546
+ this.HeaterCooler.Active = this.hap.Characteristic.Active.INACTIVE;
547
+ } else if (this.HeaterCooler.Active) {
548
+ this.HeaterCooler.Active;
549
+ } else {
550
+ this.HeaterCooler.Active = this.accessory.context.Active;
551
+ }
552
+
553
+ if (this.HeaterCooler.CurrentTemperature === undefined && this.accessory.context.CurrentTemperature === undefined) {
554
+ this.HeaterCooler.CurrentTemperature = 24;
555
+ } else {
556
+ this.HeaterCooler.CurrentTemperature = this.HeaterCooler.CurrentTemperature || this.accessory.context.CurrentTemperature;
557
+ }
558
+
559
+ if (this.HeaterCooler.ThresholdTemperature === undefined && this.accessory.context.ThresholdTemperature === undefined) {
560
+ this.HeaterCooler.ThresholdTemperature = 24;
561
+ } else {
562
+ this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature || this.accessory.context.ThresholdTemperature;
563
+ }
564
+
565
+ if (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
566
+ this.HeaterCooler.RotationSpeed = 4;
567
+ } else {
568
+ this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed;
569
+ }
570
+
571
+ await this.getAirConditionerConfigSettings(this.accessory, this.device);
572
+
573
+ if (this.meter) {
574
+ if (this.HumiditySensor!.CurrentRelativeHumidity === undefined && this.accessory.context.CurrentRelativeHumidity === undefined) {
575
+ this.HumiditySensor!.CurrentRelativeHumidity = 0;
576
+ } else {
577
+ this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
578
+ }
579
+ }
580
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
581
+ return this.HeaterCooler.ThresholdTemperature;
445
582
  }
446
583
 
447
584
  async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
448
- this.ThresholdTemperature = value;
585
+ this.HeaterCooler.ThresholdTemperature = value;
449
586
  this.debugLog(
450
- `${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.ThresholdTemperature},` +
587
+ `${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature},` +
451
588
  ` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`,
452
589
  );
453
590
  this.pushAirConditionerStatusChanges();
@@ -455,391 +592,127 @@ export class AirConditioner {
455
592
 
456
593
  async updateHomeKitCharacteristics(): Promise<void> {
457
594
  // Active
458
- if (this.Active === undefined) {
459
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
595
+ if (this.HeaterCooler.Active === undefined) {
596
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.HeaterCooler.Active}`);
460
597
  } 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}`);
598
+ this.accessory.context.Active = this.HeaterCooler.Active;
599
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HeaterCooler.Active);
600
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HeaterCooler.Active}`);
464
601
  }
465
602
  // RotationSpeed
466
- if (this.RotationSpeed === undefined) {
467
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
603
+ if (this.HeaterCooler.RotationSpeed === undefined) {
604
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
468
605
  } 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}`);
606
+ this.accessory.context.RotationSpeed = this.HeaterCooler.RotationSpeed;
607
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.HeaterCooler.RotationSpeed);
608
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
609
+ + ` RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
472
610
  }
473
611
  // CurrentTemperature
474
- if (this.CurrentTemperature === undefined) {
475
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
612
+ if (this.HeaterCooler.CurrentTemperature === undefined) {
613
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
476
614
  } 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}`);
615
+ this.accessory.context.CurrentTemperature = this.HeaterCooler.CurrentTemperature;
616
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.HeaterCooler.CurrentTemperature);
617
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
618
+ + ` CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
480
619
  }
481
620
  // CurrentRelativeHumidity
482
621
  if (this.meter) {
483
- if (this.CurrentRelativeHumidity === undefined) {
484
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
622
+ if (this.HumiditySensor!.CurrentRelativeHumidity === undefined) {
623
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
624
+ + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
485
625
  } else {
486
- this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
487
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
626
+ this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity;
627
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
628
+ this.HumiditySensor!.CurrentRelativeHumidity);
488
629
  this.debugLog(
489
- `${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
630
+ `${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
631
+ + ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`,
490
632
  );
491
633
  }
492
634
  }
493
635
  // TargetHeaterCoolerState
494
- if (this.TargetHeaterCoolerState === undefined) {
495
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
636
+ if (this.HeaterCooler.TargetHeaterCoolerState === undefined) {
637
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
496
638
  } 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
- );
639
+ this.accessory.context.TargetHeaterCoolerState = this.HeaterCooler.TargetHeaterCoolerState;
640
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, this.HeaterCooler.TargetHeaterCoolerState);
641
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
642
+ + ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
502
643
  }
503
644
  // CurrentHeaterCoolerState
504
- if (this.CurrentHeaterCoolerState === undefined) {
505
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
645
+ if (this.HeaterCooler.CurrentHeaterCoolerState === undefined) {
646
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
647
+ + ` CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
506
648
  } else {
507
- this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
508
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
649
+ this.accessory.context.CurrentHeaterCoolerState = this.HeaterCooler.CurrentHeaterCoolerState;
650
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.HeaterCooler.CurrentHeaterCoolerState);
509
651
  this.debugLog(
510
652
  `${this.device.remoteType}: ${this.accessory.displayName}` +
511
- ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
653
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`,
512
654
  );
513
655
  }
514
656
  // ThresholdTemperature
515
- if (this.ThresholdTemperature === undefined) {
516
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ThresholdTemperature: ${this.ThresholdTemperature}`);
657
+ if (this.HeaterCooler.ThresholdTemperature === undefined) {
658
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
517
659
  } else {
518
- this.accessory.context.ThresholdTemperature = this.ThresholdTemperature;
519
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.ThresholdTemperature);
520
- this.coolerService?.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.ThresholdTemperature);
521
- this.debugLog(
522
- `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`,
523
- );
524
- }
525
- }
526
-
527
- async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
528
- if (device.disablePushOn === undefined) {
529
- this.disablePushOn = false;
530
- } else {
531
- this.disablePushOn = device.disablePushOn;
532
- }
533
- }
534
-
535
- async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
536
- if (device.disablePushOff === undefined) {
537
- this.disablePushOff = false;
538
- } else {
539
- this.disablePushOff = device.disablePushOff;
540
- }
541
- }
542
-
543
- async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
544
- if (device.disablePushDetail === undefined) {
545
- this.disablePushDetail = false;
546
- } else {
547
- this.disablePushDetail = device.disablePushDetail;
548
- }
549
- }
550
-
551
- async commandType(): Promise<string> {
552
- let commandType: string;
553
- if (this.device.customize) {
554
- commandType = 'customize';
555
- } else {
556
- commandType = 'command';
557
- }
558
- return commandType;
559
- }
560
-
561
- async commandOn(): Promise<string> {
562
- let command: string;
563
- if (this.device.customize && this.device.customOn) {
564
- command = this.device.customOn;
565
- } else {
566
- command = 'turnOn';
567
- }
568
- return command;
569
- }
570
-
571
- async commandOff(): Promise<string> {
572
- let command: string;
573
- if (this.device.customize && this.device.customOff) {
574
- command = this.device.customOff;
575
- } else {
576
- command = 'turnOff';
577
- }
578
- return command;
579
- }
580
-
581
- async statusCode(statusCode: number): Promise<void> {
582
- switch (statusCode) {
583
- case 151:
584
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
585
- break;
586
- case 152:
587
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
588
- break;
589
- case 160:
590
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
591
- break;
592
- case 161:
593
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
594
- break;
595
- case 171:
596
- this.errorLog(
597
- `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
598
- `Hub: ${this.device.hubDeviceId}`,
599
- );
600
- break;
601
- case 190:
602
- this.errorLog(
603
- `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
604
- ` Or command format is invalid, statusCode: ${statusCode}`,
605
- );
606
- break;
607
- case 100:
608
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
609
- break;
610
- case 200:
611
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
612
- break;
613
- case 400:
614
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
615
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
616
- break;
617
- case 401:
618
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
619
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
620
- break;
621
- case 403:
622
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
623
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
624
- break;
625
- case 404:
626
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
627
- + `statusCode: ${statusCode}`);
628
- break;
629
- case 406:
630
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
631
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
632
- break;
633
- case 415:
634
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
635
- + `header that is not supported by the server, statusCode: ${statusCode}`);
636
- break;
637
- case 422:
638
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
639
- + `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
640
- break;
641
- case 429:
642
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
643
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
644
- break;
645
- case 500:
646
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
647
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
648
- break;
649
- default:
650
- this.infoLog(
651
- `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
652
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
653
- );
660
+ this.accessory.context.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature;
661
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
662
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
663
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
664
+ + ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
654
665
  }
655
666
  }
656
667
 
657
668
  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);
669
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
670
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
671
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
672
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
673
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, e);
674
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
675
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, e);
676
+ this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, e);
666
677
  }
667
678
 
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
-
679
+ async getAirConditionerConfigSettings(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
695
680
  if (this.device.irair?.hide_automode) {
696
- this.hide_automode = this.device.irair?.hide_automode;
697
- this.accessory.context.hide_automode = this.hide_automode;
681
+ this.hide_automode = device.irair?.hide_automode;
682
+ accessory.context.hide_automode = this.hide_automode;
698
683
  } else {
699
- this.hide_automode = this.device.irair?.hide_automode;
700
- this.accessory.context.hide_automode = this.hide_automode;
684
+ this.hide_automode = device.irair?.hide_automode;
685
+ accessory.context.hide_automode = this.hide_automode;
701
686
  }
702
687
 
703
688
  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;
689
+ this.set_max_heat = device.irair?.set_max_heat;
690
+ accessory.context.set_max_heat = this.set_max_heat;
706
691
  } else {
707
692
  this.set_max_heat = 35;
708
- this.accessory.context.set_max_heat = this.set_max_heat;
693
+ accessory.context.set_max_heat = this.set_max_heat;
709
694
  }
710
695
  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;
696
+ this.set_min_heat = device.irair?.set_min_heat;
697
+ accessory.context.set_min_heat = this.set_min_heat;
713
698
  } else {
714
699
  this.set_min_heat = 0;
715
- this.accessory.context.set_min_heat = this.set_min_heat;
700
+ accessory.context.set_min_heat = this.set_min_heat;
716
701
  }
717
702
 
718
703
  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;
704
+ this.set_max_cool = device.irair?.set_max_cool;
705
+ accessory.context.set_max_cool = this.set_max_cool;
721
706
  } else {
722
707
  this.set_max_cool = 35;
723
- this.accessory.context.set_max_cool = this.set_max_cool;
708
+ accessory.context.set_max_cool = this.set_max_cool;
724
709
  }
725
710
  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;
711
+ this.set_min_cool = device.irair?.set_min_cool;
712
+ accessory.context.set_min_cool = this.set_min_cool;
728
713
  } else {
729
714
  this.set_min_cool = 0;
730
- this.accessory.context.set_min_cool = this.set_min_cool;
715
+ accessory.context.set_min_cool = this.set_min_cool;
731
716
  }
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));
829
- }
830
- }
831
-
832
- debugLog(...log: any[]): void {
833
- if (this.enablingDeviceLogging()) {
834
- if (this.deviceLogging === 'debug') {
835
- this.platform.log.info('[DEBUG]', String(...log));
836
- } else {
837
- this.platform.log.debug(String(...log));
838
- }
839
- }
840
- }
841
-
842
- enablingDeviceLogging(): boolean {
843
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
844
717
  }
845
718
  }