@switchbot/homebridge-switchbot 1.4.1-beta.5 → 1.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.
@@ -16,11 +16,17 @@ export class AirConditioner {
16
16
  Active!: CharacteristicValue;
17
17
  ActiveCached!: CharacteristicValue;
18
18
  RotationSpeed!: CharacteristicValue;
19
- LastTemperature!: CharacteristicValue;
19
+ RotationSpeedCached!: CharacteristicValue;
20
20
  CurrentTemperature!: CharacteristicValue;
21
21
  CurrentTemperatureCached!: CharacteristicValue;
22
- TargetHeaterCoolerState?: CharacteristicValue;
22
+ TargetHeaterCoolerState!: CharacteristicValue;
23
+ TargetHeaterCoolerStateCached!: CharacteristicValue;
23
24
  CurrentHeaterCoolerState!: CharacteristicValue;
25
+ CurrentHeaterCoolerStateCached!: CharacteristicValue;
26
+ HeatingThresholdTemperature!: CharacteristicValue;
27
+ HeatingThresholdTemperatureCached!: CharacteristicValue;
28
+ CoolingThresholdTemperature!: CharacteristicValue;
29
+ CoolingThresholdTemperatureCached!: CharacteristicValue;
24
30
 
25
31
  // Others
26
32
  state!: string;
@@ -35,6 +41,7 @@ export class AirConditioner {
35
41
 
36
42
  // Config
37
43
  deviceLogging!: string;
44
+ hide_automode?: boolean;
38
45
 
39
46
  constructor(
40
47
  private readonly platform: SwitchBotPlatform,
@@ -53,6 +60,13 @@ export class AirConditioner {
53
60
  } else {
54
61
  this.CurrentTemperature = this.accessory.context.CurrentTemperature;
55
62
  }
63
+ if (device.irair?.hide_automode) {
64
+ this.hide_automode = device.irair?.hide_automode;
65
+ this.accessory.context.hide_automode = this.hide_automode;
66
+ } else {
67
+ this.hide_automode = device.irair?.hide_automode;
68
+ this.accessory.context.hide_automode = this.hide_automode;
69
+ }
56
70
 
57
71
  // set accessory information
58
72
  accessory
@@ -85,25 +99,59 @@ export class AirConditioner {
85
99
  maxValue: 100,
86
100
  minStep: 0.01,
87
101
  })
88
- .onGet((value: CharacteristicValue) => {
89
- return this.CurrentTemperatureGet(value);
102
+ .onGet(() => {
103
+ return this.CurrentTemperatureGet();
90
104
  });
91
105
 
92
- if (device.irair?.hide_automode) {
106
+ if (this.hide_automode) {
107
+ this.TargetHeaterCoolerState = 1 || 2;
93
108
  this.ValidValues = [1, 2];
109
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},`
110
+ + ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
94
111
  } else {
112
+ this.TargetHeaterCoolerState = 0 || 1 || 2;
95
113
  this.ValidValues = [0, 1, 2];
114
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} ValidValues: ${JSON.stringify(this.ValidValues)},`
115
+ + ` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
96
116
  }
97
117
  this.service
98
118
  .getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
99
119
  .setProps({
100
120
  validValues: this.ValidValues,
101
121
  })
122
+ .onGet(async () => {
123
+ return this.TargetHeaterCoolerStateGet();
124
+ })
102
125
  .onSet(this.TargetHeaterCoolerStateSet.bind(this));
103
126
 
104
- this.service.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(async () => {
105
- return this.CurrentHeaterCoolerStateGet();
106
- });
127
+ this.service.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
128
+ .onGet(async () => {
129
+ return this.CurrentHeaterCoolerStateGet();
130
+ });
131
+
132
+ this.service
133
+ .getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
134
+ .setProps({
135
+ minValue: 16,
136
+ maxValue: 30,
137
+ minStep: 1,
138
+ })
139
+ .onGet(() => {
140
+ return this.HeatingThresholdTemperatureGet();
141
+ })
142
+ .onSet(this.HeatingThresholdTemperatureSet.bind(this));
143
+
144
+ this.service
145
+ .getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
146
+ .setProps({
147
+ minValue: 16,
148
+ maxValue: 30,
149
+ minStep: 1,
150
+ })
151
+ .onGet(() => {
152
+ return this.CoolingThresholdTemperatureGet();
153
+ })
154
+ .onSet(this.CoolingThresholdTemperatureSet.bind(this));
107
155
 
108
156
  this.service
109
157
  .getCharacteristic(this.platform.Characteristic.RotationSpeed)
@@ -128,119 +176,6 @@ export class AirConditioner {
128
176
  }
129
177
  }
130
178
 
131
- private RotationSpeedSet(value: CharacteristicValue) {
132
- if (value === 4) {
133
- this.CurrentFanSpeed = 1;
134
- } else {
135
- this.CurrentFanSpeed = Number(value) + 1;
136
- }
137
- this.pushAirConditionerStatusChanges();
138
- this.RotationSpeed = this.CurrentFanSpeed || 1;
139
- }
140
-
141
- private RotationSpeedGet() {
142
- if (!this.CurrentFanSpeed || this.CurrentFanSpeed === 1) {
143
- this.RotationSpeed = 4;
144
- } else {
145
- this.RotationSpeed = this.CurrentFanSpeed - 1;
146
- }
147
- return this.RotationSpeed;
148
- }
149
-
150
- private ActiveSet(value: CharacteristicValue) {
151
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
152
-
153
- if (value === this.platform.Characteristic.Active.INACTIVE) {
154
- this.pushAirConditionerOffChanges();
155
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
156
- } else {
157
- this.pushAirConditionerOnChanges();
158
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
159
- }
160
- this.Active = value;
161
- this.ActiveCached = this.Active;
162
- this.accessory.context.Active = this.ActiveCached;
163
- }
164
-
165
- private updateHomeKitCharacteristics() {
166
- if (this.Active === undefined) {
167
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
168
- } else {
169
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
170
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
171
- }
172
- if (this.RotationSpeed === undefined) {
173
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
174
- } else {
175
- this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
176
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
177
- }
178
- if (this.CurrentTemperature === undefined) {
179
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
180
- } else {
181
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
182
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
183
- }
184
- if (this.TargetHeaterCoolerState === undefined) {
185
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
186
- } else {
187
- this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
188
- this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
189
- + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
190
- }
191
- if (this.CurrentHeaterCoolerState === undefined) {
192
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
193
- } else {
194
- this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
195
- this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
196
- + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
197
- }
198
- }
199
-
200
- private CurrentTemperatureGet(value: CharacteristicValue) {
201
- value = Number(this.CurrentTemperature) || 24;
202
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} Trigger Get CurrentTemperature: ${value}`);
203
-
204
- this.service
205
- .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
206
- .updateValue(value);
207
-
208
- return value;
209
- }
210
-
211
- private TargetHeaterCoolerStateSet(value: CharacteristicValue) {
212
- switch (value) {
213
- case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
214
- this.CurrentMode = AirConditioner.MODE_HEAT;
215
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} (Set) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
216
- break;
217
- case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
218
- this.CurrentMode = AirConditioner.MODE_COOL;
219
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} (Set) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
220
- break;
221
- case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
222
- this.CurrentMode = AirConditioner.MODE_AUTO;
223
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} (Set) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
224
- }
225
- this.pushAirConditionerStatusChanges();
226
- }
227
-
228
- private CurrentHeaterCoolerStateGet() {
229
- if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
230
- if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
231
- this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
232
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} (Get) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
233
- } else {
234
- this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
235
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} (Get) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
236
- }
237
- } else {
238
- this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
239
- this.debugLog(`Air Conditioner: ${this.accessory.displayName} (Get) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
240
- }
241
- return this.CurrentHeaterCoolerState;
242
- }
243
-
244
179
  /**
245
180
  * Pushes the requested changes to the SwitchBot API
246
181
  * deviceType commandType Command command parameter Description
@@ -250,7 +185,7 @@ export class AirConditioner {
250
185
  * AirConditioner: "command" "middleSpeed" "default" = fan speed to medium
251
186
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
252
187
  */
253
- async pushAirConditionerOnChanges() {
188
+ /*async pushAirConditionerOnChanges() {
254
189
  if (this.Active !== this.platform.Characteristic.Active.ACTIVE) {
255
190
  const payload = {
256
191
  commandType: 'command',
@@ -259,17 +194,15 @@ export class AirConditioner {
259
194
  } as any;
260
195
  await this.pushChanges(payload);
261
196
  }
262
- }
197
+ }*/
263
198
 
264
199
  async pushAirConditionerOffChanges() {
265
- if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
266
- const payload = {
267
- commandType: 'command',
268
- parameter: 'default',
269
- command: 'turnOff',
270
- } as any;
271
- await this.pushChanges(payload);
272
- }
200
+ const payload = {
201
+ commandType: 'command',
202
+ parameter: 'default',
203
+ command: 'turnOff',
204
+ } as any;
205
+ await this.pushChanges(payload);
273
206
  }
274
207
 
275
208
  async pushAirConditionerStatusChanges() {
@@ -289,28 +222,31 @@ export class AirConditioner {
289
222
  command: 'setAll',
290
223
  } as any;
291
224
 
292
- if (this.CurrentTemperature === undefined) {
293
- this.CurrentTemperature = 24;
294
- }
225
+ this.CurrentTemperatureUndefined();
295
226
  if (this.CurrentMode === undefined) {
296
227
  this.CurrentMode = 1;
297
228
  }
298
229
  if (this.CurrentFanSpeed === undefined) {
299
230
  this.CurrentFanSpeed = 1;
300
231
  }
301
- this.Active = this.platform.Characteristic.Active.ACTIVE;
302
232
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
303
233
  this.state = 'on';
304
234
  } else {
305
235
  this.state = 'off';
306
236
  }
237
+ if (this.CurrentMode === 1) {
238
+ this.CurrentTemperature = 25;
239
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
240
+ + ` CurrentTemperature: ${this.CurrentTemperature}`);
241
+ }
307
242
  payload.parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
308
243
 
309
244
 
310
245
  if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
311
- if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
246
+ this.CurrentTemperatureUndefined();
247
+ if (this.CurrentTemperature < this.CurrentTemperatureCached) {
312
248
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
313
- } else {
249
+ } else if (this.CurrentTemperature > this.CurrentTemperatureCached) {
314
250
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
315
251
  }
316
252
  } else {
@@ -327,10 +263,16 @@ export class AirConditioner {
327
263
 
328
264
  // Make the API request
329
265
  const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
330
- this.errorLog(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
266
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
331
267
  this.statusCode(push);
332
268
  this.CurrentTemperatureCached = this.CurrentTemperature;
333
269
  this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
270
+ this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
271
+ this.HeatingThresholdTemperatureCached = this.CurrentTemperatureCached;
272
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
273
+ this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
274
+ this.CoolingThresholdTemperatureCached = this.CurrentTemperatureCached;
275
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
334
276
  this.updateHomeKitCharacteristics();
335
277
  } catch (e: any) {
336
278
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
@@ -346,7 +288,7 @@ export class AirConditioner {
346
288
  }
347
289
  }
348
290
 
349
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
291
+ statusCode(push: AxiosResponse<{ statusCode: number; }>) {
350
292
  switch (push.data.statusCode) {
351
293
  case 151:
352
294
  this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -375,6 +317,55 @@ export class AirConditioner {
375
317
  }
376
318
  }
377
319
 
320
+ updateHomeKitCharacteristics() {
321
+ if (this.Active === undefined) {
322
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
323
+ } else {
324
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
325
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
326
+ }
327
+ if (this.RotationSpeed === undefined) {
328
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
329
+ } else {
330
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
331
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
332
+ }
333
+ if (this.CurrentTemperature === undefined) {
334
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
335
+ } else {
336
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
337
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
338
+ }
339
+ if (this.TargetHeaterCoolerState === undefined) {
340
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
341
+ } else {
342
+ this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
343
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
344
+ + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
345
+ }
346
+ if (this.CurrentHeaterCoolerState === undefined) {
347
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
348
+ } else {
349
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
350
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
351
+ + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
352
+ }
353
+ if (this.HeatingThresholdTemperature === undefined) {
354
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
355
+ } else {
356
+ this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
357
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
358
+ + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
359
+ }
360
+ if (this.CoolingThresholdTemperature === undefined) {
361
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
362
+ } else {
363
+ this.service?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
364
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
365
+ + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
366
+ }
367
+ }
368
+
378
369
  public apiError(e: any) {
379
370
  this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
380
371
  this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
@@ -382,9 +373,200 @@ export class AirConditioner {
382
373
  this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
383
374
  this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
384
375
  this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
376
+ this.service.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
385
377
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
386
378
  }
387
379
 
380
+ CurrentTemperatureGet() {
381
+ if (this.CurrentTemperature === undefined) {
382
+ this.CurrentTemperature = 24;
383
+ this.CurrentTemperatureCached = this.CurrentTemperature;
384
+ } else {
385
+ this.CurrentTemperatureCached = this.CurrentTemperature;
386
+ }
387
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
388
+ this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
389
+ return this.CurrentTemperature;
390
+ }
391
+
392
+ RotationSpeedGet() {
393
+ if (!this.CurrentFanSpeed) {
394
+ this.RotationSpeed = 4;
395
+ } else if (this.CurrentFanSpeed === 1) {
396
+ this.RotationSpeed = 4;
397
+ } else {
398
+ this.RotationSpeed = this.CurrentFanSpeed - 1;
399
+ }
400
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
401
+ this.RotationSpeedCached = this.RotationSpeed;
402
+ this.accessory.context.RotationSpeed = this.RotationSpeedCached;
403
+ return this.RotationSpeed;
404
+ }
405
+
406
+ RotationSpeedSet(value: CharacteristicValue) {
407
+ if (value === 4) {
408
+ this.CurrentFanSpeed = 1;
409
+ } else {
410
+ this.CurrentFanSpeed = Number(value) + 1;
411
+ }
412
+ this.RotationSpeed = this.CurrentFanSpeed;
413
+ this.RotationSpeedCached = this.RotationSpeed;
414
+ this.accessory.context.RotationSpeed = this.RotationSpeedCached;
415
+ this.pushAirConditionerStatusChanges();
416
+ }
417
+
418
+ ActiveSet(value: CharacteristicValue) {
419
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
420
+
421
+ this.Active = value;
422
+ this.ActiveCached = this.Active;
423
+ this.accessory.context.Active = this.ActiveCached;
424
+
425
+ if (value === this.platform.Characteristic.Active.INACTIVE) {
426
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
427
+ this.pushAirConditionerOffChanges();
428
+ } else {
429
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
430
+ this.pushAirConditionerStatusChanges();
431
+ }
432
+ }
433
+
434
+ TargetHeaterCoolerStateGet() {
435
+ if (this.ValidValues === [0, 1, 2]) {
436
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
437
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (AUTO) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},`
438
+ + ` ValidValues: ${this.ValidValues}`);
439
+ } else if (this.ValidValues === [1, 2]) {
440
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL
441
+ || this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
442
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (COOL/HEAT) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},`
443
+ + ` ValidValues: ${this.ValidValues}`);
444
+ } else {
445
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},`
446
+ + ` ValidValues: ${this.ValidValues}`);
447
+ }
448
+ this.TargetHeaterCoolerStateCached = this.TargetHeaterCoolerState;
449
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
450
+ return this.TargetHeaterCoolerState;
451
+ }
452
+
453
+ TargetHeaterCoolerStateSet(value: CharacteristicValue) {
454
+ if (this.hide_automode) {
455
+ if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
456
+ this.TargetHeaterCoolerStateHEAT();
457
+ } else if (value === this.platform.Characteristic.TargetHeaterCoolerState.COOL) {
458
+ this.TargetHeaterCoolerStateCOOL();
459
+ } else {
460
+ this.errorLog(`Air Conditioner: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},`
461
+ + ` hide_automode: ${this.hide_automode} `);
462
+ }
463
+ } else {
464
+ if (value === this.platform.Characteristic.TargetHeaterCoolerState.AUTO) {
465
+ this.TargetHeaterCoolerStateAUTO();
466
+ } else if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
467
+ this.TargetHeaterCoolerStateHEAT();
468
+ } else if (value === this.platform.Characteristic.TargetHeaterCoolerState.COOL) {
469
+ this.TargetHeaterCoolerStateCOOL();
470
+ } else {
471
+ this.errorLog(`Air Conditioner: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},`
472
+ + ` hide_automode: ${this.hide_automode} `);
473
+ }
474
+ }
475
+ this.TargetHeaterCoolerStateCached = this.TargetHeaterCoolerState;
476
+ this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
477
+ this.pushAirConditionerStatusChanges();
478
+ }
479
+
480
+ private TargetHeaterCoolerStateAUTO() {
481
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
482
+ this.CurrentMode = 1;
483
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
484
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
485
+ }
486
+
487
+ private TargetHeaterCoolerStateCOOL() {
488
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
489
+ this.CurrentMode = 2;
490
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
491
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
492
+ }
493
+
494
+ private TargetHeaterCoolerStateHEAT() {
495
+ this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
496
+ this.CurrentMode = 5;
497
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
498
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
499
+ }
500
+
501
+ CurrentHeaterCoolerStateGet() {
502
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
503
+ this.CurrentTemperatureUndefined();
504
+ if (this.CurrentTemperature < this.CurrentTemperatureCached) {
505
+ this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
506
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (COOLLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
507
+ } else if (this.CurrentTemperature > this.CurrentTemperatureCached) {
508
+ this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
509
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
510
+ }
511
+ } else {
512
+ this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
513
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
514
+ }
515
+ this.CurrentHeaterCoolerStateCached = this.CurrentHeaterCoolerState;
516
+ this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerStateCached;
517
+ return this.CurrentHeaterCoolerState;
518
+ }
519
+
520
+ private HeatingThresholdTemperatureGet() {
521
+ this.CurrentTemperatureUndefined;
522
+ this.CurrentTemperature = this.CurrentTemperatureCached;
523
+ this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
524
+ this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
525
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
526
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
527
+ return this.HeatingThresholdTemperature;
528
+ }
529
+
530
+ private HeatingThresholdTemperatureSet(value: CharacteristicValue) {
531
+ this.CurrentTemperatureCached = this.CurrentTemperature;
532
+ this.CurrentTemperature = value;
533
+ this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
534
+ this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
535
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},`
536
+ + ` CurrentTemperatureCached: ${this.CurrentTemperatureCached}`);
537
+ this.pushAirConditionerStatusChanges();
538
+ }
539
+
540
+
541
+ private CoolingThresholdTemperatureGet() {
542
+ this.CurrentTemperatureUndefined;
543
+ this.CurrentTemperature = this.CurrentTemperatureCached;
544
+ this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
545
+ this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
546
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
547
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
548
+ return this.CoolingThresholdTemperature;
549
+ }
550
+
551
+ private CoolingThresholdTemperatureSet(value: CharacteristicValue) {
552
+ this.CurrentTemperatureCached = this.CurrentTemperature;
553
+ this.CurrentTemperature = value;
554
+ this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
555
+ this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
556
+ this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},`
557
+ + ` CurrentTemperatureCached: ${this.CurrentTemperatureCached}`);
558
+ this.pushAirConditionerStatusChanges();
559
+ }
560
+
561
+ private CurrentTemperatureUndefined() {
562
+ if (this.CurrentTemperature === undefined) {
563
+ this.CurrentTemperature = 24;
564
+ }
565
+ if (this.CurrentTemperatureCached === undefined) {
566
+ this.CurrentTemperature = 30;
567
+ }
568
+ }
569
+
388
570
  /**
389
571
  * Logging for Device
390
572
  */