homebridge-gree-ac 2.1.6 → 2.2.0-beta.1

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.
@@ -21,6 +21,8 @@ class GreeAirConditioner {
21
21
  this.deviceConfig = deviceConfig;
22
22
  this.tsAccessoryMac = tsAccessoryMac;
23
23
  this.tsAccessory = null;
24
+ this.powerPending = -1;
25
+ this.modePending = -1;
24
26
  // device communication functions
25
27
  this.handleMessage = (msg, rinfo) => {
26
28
  if (this.accessory.context.device.address === rinfo.address) {
@@ -52,7 +54,7 @@ class GreeAirConditioner {
52
54
  this.key = pack.key;
53
55
  this.initAccessory();
54
56
  this.accessory.bound = true;
55
- this.platform.log.info(`[${this.getDeviceLabel()}] Device is bound -> ${pack.mac}`);
57
+ this.platform.log.success(`[${this.getDeviceLabel()}] Device is bound -> ${pack.mac}`);
56
58
  this.platform.log.debug(`[${this.getDeviceLabel()}] Device key -> ${this.key}`);
57
59
  this.requestDeviceStatus();
58
60
  setInterval(this.requestDeviceStatus.bind(this), this.deviceConfig.statusUpdateInterval * 1000); // statusUpdateInterval in seconds
@@ -72,6 +74,12 @@ class GreeAirConditioner {
72
74
  else {
73
75
  this.status[col] = pack.dat[i];
74
76
  }
77
+ if (col === commands_1.default.power.code && pack.dat[i] === this.powerPending) {
78
+ this.powerPending = -1;
79
+ }
80
+ if (col === commands_1.default.mode.code && pack.dat[i] === this.modePending) {
81
+ this.modePending = -1;
82
+ }
75
83
  });
76
84
  this.platform.log.debug(`[${this.getDeviceLabel()}] Device status -> %j`, this.status);
77
85
  if (!pack.cols.includes(commands_1.default.temperature.code) || invalidTempFromDevice) {
@@ -91,7 +99,7 @@ class GreeAirConditioner {
91
99
  break;
92
100
  case 'res': // package type is response
93
101
  if (this.accessory.bound) {
94
- this.platform.log.debug(`[${this.getDeviceLabel()}] Device response`);
102
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Device response`, pack.opt, pack.p || pack.val);
95
103
  const updatedParams = [];
96
104
  pack.opt.forEach((opt, i) => {
97
105
  const value = pack.p !== undefined ? pack.p[i] : pack.val[i];
@@ -102,10 +110,17 @@ class GreeAirConditioner {
102
110
  updatedParams.push(`${cmd}: ${oldval} -> ${newval}`);
103
111
  }
104
112
  this.status[opt] = value;
113
+ if (opt === commands_1.default.power.code && value === this.powerPending) {
114
+ this.powerPending = -1;
115
+ }
116
+ if (opt === commands_1.default.mode.code && value === this.modePending) {
117
+ this.modePending = -1;
118
+ }
105
119
  });
106
120
  if (updatedParams.length > 0) {
107
121
  this.platform.log.info(`[${this.getDeviceLabel()}] Device updated (%j)`, updatedParams);
108
122
  }
123
+ this.updateStatus(pack.opt);
109
124
  }
110
125
  break;
111
126
  default:
@@ -173,7 +188,7 @@ class GreeAirConditioner {
173
188
  }
174
189
  // All platform, accessory and service initialization is made in initAccessory function
175
190
  initAccessory() {
176
- var _a, _b, _c;
191
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
177
192
  // register accessory in homebridge by api if not registered before
178
193
  if (!this.accessory.registered) {
179
194
  this.platform.log.debug(`[${this.getDeviceLabel()}] Registering new accessory in homebridge:`, this.accessory.context.device.mac, this.accessory.UUID);
@@ -196,6 +211,18 @@ class GreeAirConditioner {
196
211
  if (this.tsAccessoryMac) {
197
212
  this.tsAccessory = new tsAccessory_1.GreeAirConditionerTS(this.platform, this.platform.getAccessory(this.accessory.context.device.mac + '_ts'));
198
213
  }
214
+ // init TargetHeaterCoolerState default value
215
+ if (!this.accessory.context.TargetHeaterCoolerState) {
216
+ this.accessory.context.TargetHeaterCoolerState =
217
+ ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
218
+ this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
219
+ }
220
+ // init HeaterCoolerRotationSpeed default value
221
+ if (this.accessory.context.HeaterCoolerRotationSpeed === undefined) {
222
+ this.accessory.context.HeaterCoolerRotationSpeed =
223
+ ((_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.RotationSpeed).value) ||
224
+ ((_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minValue) || 0;
225
+ }
199
226
  // set accessory information
200
227
  this.accessory.getService(this.platform.Service.AccessoryInformation)
201
228
  .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.accessory.context.device.hid && this.accessory.context.device.hid.lastIndexOf('V') >= 0 &&
@@ -207,28 +234,61 @@ class GreeAirConditioner {
207
234
  this.HeaterCooler = this.accessory.getService(this.platform.Service.HeaterCooler);
208
235
  if (!this.HeaterCooler) {
209
236
  this.platform.log.debug(`[${this.getDeviceLabel()}] HeaterCooler service doesn't exist - adding service`);
210
- this.HeaterCooler = this.accessory.addService(this.platform.Service.HeaterCooler, this.accessory.displayName, undefined);
237
+ this.HeaterCooler = this.accessory.addService(this.platform.Service.HeaterCooler, this.accessory.displayName);
211
238
  // set static characeristics
212
239
  this.initCharacteristics();
213
240
  }
214
241
  }
215
242
  // TemperatureSensor service
243
+ // we don't use subtype because we add only one service with this type
244
+ const tss = this.accessory.getService(this.platform.Service.TemperatureSensor);
216
245
  if (this.deviceConfig.temperatureSensor === settings_1.TS_TYPE.child) {
217
- this.platform.log.debug(`[${this.getDeviceLabel()}] Add Temperature Sensor child service`);
218
- this.TemperatureSensor = this.accessory.getService(this.platform.Service.TemperatureSensor) ||
219
- this.accessory.addService(this.platform.Service.TemperatureSensor, 'Temperature Sensor - ' + this.accessory.displayName, undefined);
220
- this.TemperatureSensor.displayName = 'Temperature Sensor - ' + this.accessory.displayName;
246
+ if (tss) {
247
+ this.TemperatureSensor = tss;
248
+ }
249
+ else {
250
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Add Temperature Sensor child service`);
251
+ this.TemperatureSensor =
252
+ this.accessory.addService(this.platform.Service.TemperatureSensor, 'Temperature Sensor ' + this.HeaterCooler.displayName);
253
+ }
221
254
  }
222
255
  else {
223
- const ts = this.accessory.getService(this.platform.Service.TemperatureSensor);
224
- this.platform.log.debug(`[${this.getDeviceLabel()}] Temperature Sensor child service not allowed`, (ts === null || ts === void 0 ? void 0 : ts.displayName) !== undefined ? '(' + (ts === null || ts === void 0 ? void 0 : ts.displayName) + ')' : '');
225
- if (ts !== undefined) {
226
- this.platform.log.debug(`[${this.getDeviceLabel()}] Remove Temperature Sensor child service (%s)`, ts.displayName);
227
- this.accessory.removeService(ts);
256
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Temperature Sensor child service not allowed`, (tss === null || tss === void 0 ? void 0 : tss.displayName) !== undefined ? '(' + (tss === null || tss === void 0 ? void 0 : tss.displayName) + ')' : '');
257
+ if (tss !== undefined) {
258
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Remove Temperature Sensor child service (%s)`, tss.displayName);
259
+ this.accessory.removeService(tss);
260
+ }
261
+ }
262
+ // Fan service
263
+ // we don't use subtype because we add only one service with this type
264
+ const fs = this.accessory.getService(this.platform.Service.Fanv2);
265
+ if (this.deviceConfig.fanControlEnabled) {
266
+ if (fs) {
267
+ this.Fan = fs;
268
+ }
269
+ else {
270
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Add Fan child service`);
271
+ this.Fan =
272
+ this.accessory.addService(this.platform.Service.Fanv2, 'Fan ' + this.HeaterCooler.displayName);
273
+ // set static characeristics
274
+ (_e = this.Fan) === null || _e === void 0 ? void 0 : _e.getCharacteristic(this.platform.Characteristic.RotationSpeed).setProps({
275
+ minValue: 0,
276
+ maxValue: 100,
277
+ minStep: 100 / (this.deviceConfig.speedSteps + 1)
278
+ });
279
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Fan RotationSpeed - minValue: %s, maxValue: %s, minStep: %s`, (_g = (_f = this.Fan) === null || _f === void 0 ? void 0 : _f.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minValue) === null || _g === void 0 ? void 0 : _g.toString(), (_j = (_h = this.Fan) === null || _h === void 0 ? void 0 : _h.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) === null || _j === void 0 ? void 0 : _j.toString(), (_l = (_k = this.Fan) === null || _k === void 0 ? void 0 : _k.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minStep) === null || _l === void 0 ? void 0 : _l.toString());
280
+ }
281
+ }
282
+ else {
283
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Fan child service not allowed`, (fs === null || fs === void 0 ? void 0 : fs.displayName) !== undefined ? '(' + (fs === null || fs === void 0 ? void 0 : fs.displayName) + ')' : '');
284
+ if (fs !== undefined) {
285
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Remove Fan child service (%s)`, fs.displayName);
286
+ this.accessory.removeService(fs);
228
287
  }
229
288
  }
230
289
  this.HeaterCooler.setPrimaryService(true);
231
- (_b = this.TemperatureSensor) === null || _b === void 0 ? void 0 : _b.setPrimaryService(false);
290
+ (_m = this.TemperatureSensor) === null || _m === void 0 ? void 0 : _m.setPrimaryService(false);
291
+ (_o = this.Fan) === null || _o === void 0 ? void 0 : _o.setPrimaryService(false);
232
292
  this.platform.api.updatePlatformAccessories([this.accessory]);
233
293
  // each service must implement at-minimum the "required characteristics" for the given service type
234
294
  // see https://developers.homebridge.io/#/service/HeaterCooler
@@ -236,17 +296,20 @@ class GreeAirConditioner {
236
296
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active)
237
297
  .onSet(this.setActive.bind(this))
238
298
  .onGet(this.getActive.bind(this));
299
+ (_p = this.Fan) === null || _p === void 0 ? void 0 : _p.getCharacteristic(this.platform.Characteristic.Active).onSet(this.setFanActive.bind(this)).onGet(this.getFanActive.bind(this));
239
300
  // register handlers for the Current Heater-Cooler State Characteristic
240
301
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
241
302
  .onGet(this.getCurrentHeaterCoolerState.bind(this));
303
+ // register handlers for the Current Fan State Characteristic
304
+ (_q = this.Fan) === null || _q === void 0 ? void 0 : _q.getCharacteristic(this.platform.Characteristic.CurrentFanState).onGet(this.getCurrentFanState.bind(this));
242
305
  // register handlers for the Target Heater-Cooler State Characteristic
243
306
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
244
307
  .onGet(this.getTargetHeaterCoolerState.bind(this))
245
308
  .onSet(this.setTargetHeaterCoolerState.bind(this));
246
309
  // register handlers for the Current Temperature Characteristic
247
310
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
248
- .onGet(this.getCurrentTemperature.bind(this, 'Heater Cooler'));
249
- (_c = this.TemperatureSensor) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this, 'Temperature Sensor'));
311
+ .onGet(this.getCurrentTemperature.bind(this, 'Heater-Cooler'));
312
+ (_r = this.TemperatureSensor) === null || _r === void 0 ? void 0 : _r.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this, 'Temperature Sensor'));
250
313
  // register handlers for the Cooling Threshold Temperature Characteristic
251
314
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
252
315
  .onGet(this.getTargetTemperature.bind(this, 'CoolingThresholdTemperature'))
@@ -263,10 +326,15 @@ class GreeAirConditioner {
263
326
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.SwingMode)
264
327
  .onGet(this.getSwingMode.bind(this))
265
328
  .onSet(this.setSwingMode.bind(this));
329
+ (_s = this.Fan) === null || _s === void 0 ? void 0 : _s.getCharacteristic(this.platform.Characteristic.SwingMode).onGet(this.getSwingMode.bind(this)).onSet(this.setSwingMode.bind(this));
266
330
  // register handlers for the Rotation Speed Characteristic
267
331
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.RotationSpeed)
268
332
  .onGet(this.getRotationSpeed.bind(this))
269
333
  .onSet(this.setRotationSpeed.bind(this));
334
+ (_t = this.Fan) === null || _t === void 0 ? void 0 : _t.getCharacteristic(this.platform.Characteristic.RotationSpeed).onGet(this.getFanRotationSpeed.bind(this)).onSet(this.setFanRotationSpeed.bind(this));
335
+ // register handlers for the Name Characteristic
336
+ this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Name)
337
+ .onGet(this.getName.bind(this));
270
338
  }
271
339
  // this function is a callback to check the status of binding after timeout period has ellapsed
272
340
  checkBindingStatus(bindNo) {
@@ -296,9 +364,24 @@ class GreeAirConditioner {
296
364
  * These are sent when the user changes the state of an accessory
297
365
  */
298
366
  async setActive(value) {
367
+ var _a, _b;
299
368
  const powerValue = (value === this.platform.Characteristic.Active.ACTIVE);
300
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set Active ->`, powerValue ? 'ACTIVE' : 'INACTIVE');
369
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler Active ->`, powerValue ? 'ACTIVE' : 'INACTIVE');
301
370
  this.power = powerValue;
371
+ if (powerValue &&
372
+ ((_a = this.Fan) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.Active).value) === this.platform.Characteristic.Active.ACTIVE) {
373
+ (_b = this.Fan) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.platform.Characteristic.Active.INACTIVE);
374
+ }
375
+ }
376
+ async setFanActive(value) {
377
+ var _a, _b;
378
+ const powerValue = (value === this.platform.Characteristic.Active.ACTIVE);
379
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Fan Active ->`, powerValue ? 'ACTIVE' : 'INACTIVE');
380
+ this.fanpower = powerValue;
381
+ if (powerValue &&
382
+ ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.Active).value) === this.platform.Characteristic.Active.ACTIVE) {
383
+ (_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.platform.Characteristic.Active.INACTIVE);
384
+ }
302
385
  }
303
386
  async setTargetHeaterCoolerState(value) {
304
387
  let modeValue = commands_1.default.mode.value.auto;
@@ -315,6 +398,8 @@ class GreeAirConditioner {
315
398
  }
316
399
  this.platform.log.debug(`[${this.getDeviceLabel()}] Set TargetHeaterCoolerState ->`, logValue);
317
400
  this.mode = modeValue;
401
+ this.accessory.context.TargetHeaterCoolerState = value;
402
+ this.platform.api.updatePlatformAccessories([this.accessory]);
318
403
  }
319
404
  async setTargetTemperature(value) {
320
405
  this.platform.log.debug(`[${this.getDeviceLabel()}] Set ThresholdTemperature ->`, value);
@@ -331,62 +416,108 @@ class GreeAirConditioner {
331
416
  this.platform.log.debug(`[${this.getDeviceLabel()}] Set SwingMode ->`, logValue);
332
417
  this.swingMode = (value === this.platform.Characteristic.SwingMode.SWING_ENABLED) ?
333
418
  commands_1.default.swingVertical.value.full : (this.deviceConfig.overrideDefaultVerticalSwing === settings_1.OVERRIDE_DEFAULT_SWING.always) ?
334
- this.deviceConfig.defaultVerticalSwing : commands_1.default.swingVertical.value.default;
419
+ this.deviceConfig.defaultVerticalSwing || settings_1.DEFAULT_DEVICE_CONFIG.defaultVerticalSwing : commands_1.default.swingVertical.value.default;
335
420
  }
336
421
  async setRotationSpeed(value) {
422
+ var _a;
423
+ const maxSpeed = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) ||
424
+ this.deviceConfig.speedSteps + 3;
337
425
  switch (value) {
426
+ case 0: // inactive -> rotation speed change not needed
427
+ return;
338
428
  case 1: // quiet
339
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (quiet)');
429
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (quiet)');
340
430
  this.quietMode = commands_1.default.quietMode.value.on;
341
431
  break;
342
432
  case 2: // auto
343
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
433
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
344
434
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto) + ')');
345
435
  this.speed = commands_1.default.speed.value.auto;
346
436
  break;
347
437
  case 3: // low
348
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
438
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
349
439
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low) + ')');
350
440
  this.speed = commands_1.default.speed.value.low;
351
441
  break;
352
442
  case 4: // mediumLow / medium
353
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (' +
354
- this.getKeyName(commands_1.default.speed.value, (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium) + ')');
355
- this.speed = (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium;
443
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (' +
444
+ this.getKeyName(commands_1.default.speed.value, (maxSpeed === 8) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium) + ')');
445
+ this.speed = (maxSpeed === 8) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium;
356
446
  break;
357
447
  case 5: // medium / high
358
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (' +
359
- this.getKeyName(commands_1.default.speed.value, (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high) + ')');
360
- this.speed = (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high;
448
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (' +
449
+ this.getKeyName(commands_1.default.speed.value, (maxSpeed === 8) ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high) + ')');
450
+ this.speed = (maxSpeed === 8) ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high;
361
451
  break;
362
452
  case 6: // mediumHigh / powerful
363
- if (this.deviceConfig.speedSteps === 5) {
453
+ if (maxSpeed === 8) {
364
454
  // mediumHigh
365
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
455
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
366
456
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.mediumHigh) + ')');
367
457
  this.speed = commands_1.default.speed.value.mediumHigh;
368
458
  }
369
459
  else {
370
460
  // powerful
371
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (powerful)');
461
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (powerful)');
372
462
  this.powerfulMode = commands_1.default.powerfulMode.value.on;
373
463
  }
374
464
  break;
375
465
  case 7: // high
376
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
466
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
377
467
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high) + ')');
378
468
  this.speed = commands_1.default.speed.value.high;
379
469
  break;
380
470
  case 8: // powerful
381
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (powerful)');
471
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (powerful)');
382
472
  this.powerfulMode = commands_1.default.powerfulMode.value.on;
383
473
  break;
384
474
  default: // auto
385
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
475
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
386
476
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto) + ')');
387
477
  this.speed = commands_1.default.speed.value.auto;
388
478
  break;
389
479
  }
480
+ this.accessory.context.HeaterCoolerRotationSpeed = value;
481
+ this.platform.api.updatePlatformAccessories([this.accessory]);
482
+ }
483
+ async setFanRotationSpeed(value) {
484
+ var _a, _b;
485
+ if (value !== 0 &&
486
+ ((_a = this.Fan) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.Active).value) !== this.platform.Characteristic.Active.ACTIVE) {
487
+ (_b = this.Fan) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.Active).setValue(this.platform.Characteristic.Active.ACTIVE);
488
+ }
489
+ let logMsg = `[${this.getDeviceLabel()}] Set Fan RotationSpeed -> ${Math.round(value)}%`;
490
+ switch (Math.round(value)) {
491
+ case 0: // inactive -> rotation speed change not needed
492
+ return;
493
+ case 17: // low - 5 step model
494
+ case 25: // low - 3 step model
495
+ logMsg += ` (${this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low)})`;
496
+ this.speed = commands_1.default.speed.value.low;
497
+ break;
498
+ case 33: // mediumLow
499
+ logMsg += ` (${this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.mediumLow)})`;
500
+ this.speed = commands_1.default.speed.value.mediumLow;
501
+ break;
502
+ case 50: // medium
503
+ logMsg += ` (${this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.medium)}) - ${Math.round(value)}%`;
504
+ this.speed = commands_1.default.speed.value.medium;
505
+ break;
506
+ case 67: // mediumHigh
507
+ logMsg += ` (${this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.mediumHigh)}) - ${Math.round(value)}%`;
508
+ this.speed = commands_1.default.speed.value.mediumHigh;
509
+ break;
510
+ case 75: // high - 3 step model
511
+ case 83: // high - 5 step model
512
+ logMsg += ` (${this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high)}) - ${Math.round(value)}%`;
513
+ this.speed = commands_1.default.speed.value.high;
514
+ break;
515
+ default: // auto
516
+ logMsg += ` (${this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto)}) - ${Math.round(value)}%`;
517
+ this.speed = commands_1.default.speed.value.auto;
518
+ break;
519
+ }
520
+ this.platform.log.debug(logMsg);
390
521
  }
391
522
  /**
392
523
  * Handle the "GET" requests from HomeKit
@@ -405,10 +536,14 @@ class GreeAirConditioner {
405
536
  * throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
406
537
  */
407
538
  async getActive() {
408
- const currentPower = this.power;
409
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get Active ->`, currentPower ? 'ACTIVE' : 'INACTIVE');
410
- return currentPower ?
411
- this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
539
+ const currentPower = this.power && [commands_1.default.mode.value.cool, commands_1.default.mode.value.heat, commands_1.default.mode.value.auto].includes(this.mode);
540
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler Active ->`, currentPower ? 'ACTIVE' : 'INACTIVE');
541
+ return currentPower ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
542
+ }
543
+ async getFanActive() {
544
+ const currentPower = this.power && this.mode === commands_1.default.mode.value.fan;
545
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Fan Active ->`, currentPower ? 'ACTIVE' : 'INACTIVE');
546
+ return currentPower ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE;
412
547
  }
413
548
  async getCurrentHeaterCoolerState() {
414
549
  if (this.power) {
@@ -419,10 +554,6 @@ class GreeAirConditioner {
419
554
  case commands_1.default.mode.value.heat:
420
555
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> HEATING`);
421
556
  return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
422
- case commands_1.default.mode.value.fan:
423
- case commands_1.default.mode.value.dry:
424
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> IDLE`);
425
- return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
426
557
  case commands_1.default.mode.value.auto:
427
558
  if (this.currentTemperature > this.status[commands_1.default.targetTemperature.code]) {
428
559
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> COOLING`);
@@ -439,6 +570,14 @@ class GreeAirConditioner {
439
570
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> INACTIVE`);
440
571
  return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
441
572
  }
573
+ async getCurrentFanState() {
574
+ if (this.power && this.mode === commands_1.default.mode.value.fan) {
575
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentFanState -> BLOWING_AIR`);
576
+ return this.platform.Characteristic.CurrentFanState.BLOWING_AIR;
577
+ }
578
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentFanState -> INACTIVE`);
579
+ return this.platform.Characteristic.CurrentFanState.INACTIVE;
580
+ }
442
581
  async getTargetHeaterCoolerState() {
443
582
  switch (this.mode) {
444
583
  case commands_1.default.mode.value.cool:
@@ -447,9 +586,23 @@ class GreeAirConditioner {
447
586
  case commands_1.default.mode.value.heat:
448
587
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> HEAT`);
449
588
  return this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
589
+ case commands_1.default.mode.value.auto:
590
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> AUTO`);
591
+ return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
592
+ }
593
+ // not in heating-cooling mode (e.g. fan mode)
594
+ switch (this.accessory.context.TargetHeaterCoolerState) {
595
+ case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
596
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> COOL`);
597
+ break;
598
+ case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
599
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> HEAT`);
600
+ break;
601
+ case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
602
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> AUTO`);
603
+ break;
450
604
  }
451
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> AUTO`);
452
- return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
605
+ return this.accessory.context.TargetHeaterCoolerState;
453
606
  }
454
607
  async getCurrentTemperature(service) {
455
608
  const currentValue = this.currentTemperature;
@@ -482,13 +635,16 @@ class GreeAirConditioner {
482
635
  return this.platform.Characteristic.SwingMode.SWING_ENABLED;
483
636
  }
484
637
  async getRotationSpeed() {
638
+ var _a;
639
+ const maxSpeed = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) ||
640
+ this.deviceConfig.speedSteps + 3;
485
641
  if (this.quietMode === commands_1.default.quietMode.value.on) {
486
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get RotationSpeed -> 1 (quiet)`);
642
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler RotationSpeed -> 1 (quiet)`);
487
643
  return 1;
488
644
  }
489
645
  if (this.powerfulMode === commands_1.default.powerfulMode.value.on) {
490
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get RotationSpeed ->`, (this.deviceConfig.speedSteps + 3) + ' (powerful)');
491
- return this.deviceConfig.speedSteps + 3;
646
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler RotationSpeed -> ${maxSpeed} (powerful)`);
647
+ return maxSpeed;
492
648
  }
493
649
  let value = 2; // default to auto
494
650
  let logValue = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
@@ -499,27 +655,63 @@ class GreeAirConditioner {
499
655
  break;
500
656
  case commands_1.default.speed.value.mediumLow:
501
657
  value = 4;
502
- logValue = this.getKeyName(commands_1.default.speed.value, (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium);
658
+ logValue = this.getKeyName(commands_1.default.speed.value, (maxSpeed === 8) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium);
503
659
  break;
504
660
  case commands_1.default.speed.value.medium:
505
- value = (this.deviceConfig.speedSteps === 5) ? 5 : 4;
661
+ value = (maxSpeed === 8) ? 5 : 4;
506
662
  logValue = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.medium);
507
663
  break;
508
664
  case commands_1.default.speed.value.mediumHigh:
509
- value = (this.deviceConfig.speedSteps === 5) ? 6 : 4;
510
- logValue = this.getKeyName(commands_1.default.speed.value, (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.mediumHigh : commands_1.default.speed.value.medium);
665
+ value = (maxSpeed === 8) ? 6 : 4;
666
+ logValue = this.getKeyName(commands_1.default.speed.value, (maxSpeed === 8) ? commands_1.default.speed.value.mediumHigh : commands_1.default.speed.value.medium);
511
667
  break;
512
668
  case commands_1.default.speed.value.high:
513
- value = (this.deviceConfig.speedSteps === 5) ? 7 : 5;
669
+ value = (maxSpeed === 8) ? 7 : 5;
514
670
  logValue = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
515
671
  break;
516
672
  }
517
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get RotationSpeed ->`, value + ' (' + logValue + ')');
673
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler RotationSpeed ->`, value + ' (' + logValue + ')');
518
674
  return value;
519
675
  }
676
+ async getFanRotationSpeed() {
677
+ var _a;
678
+ const minStep = ((_a = this.Fan) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minStep) ||
679
+ 100 / (this.deviceConfig.speedSteps + 1);
680
+ let value = 100; // default to auto
681
+ let logValueName = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
682
+ switch (this.speed) {
683
+ case commands_1.default.speed.value.low:
684
+ value = minStep;
685
+ logValueName = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low);
686
+ break;
687
+ case commands_1.default.speed.value.mediumLow:
688
+ value = 2 * minStep;
689
+ logValueName = this.getKeyName(commands_1.default.speed.value, (minStep !== 25) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium);
690
+ break;
691
+ case commands_1.default.speed.value.medium:
692
+ value = (minStep !== 25 ? 3 : 2) * minStep;
693
+ logValueName = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.medium);
694
+ break;
695
+ case commands_1.default.speed.value.mediumHigh:
696
+ value = (minStep !== 25 ? 4 : 2) * minStep;
697
+ logValueName = this.getKeyName(commands_1.default.speed.value, (minStep !== 25) ? commands_1.default.speed.value.mediumHigh : commands_1.default.speed.value.medium);
698
+ break;
699
+ case commands_1.default.speed.value.high:
700
+ value = (minStep !== 25 ? 5 : 3) * minStep;
701
+ logValueName = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
702
+ break;
703
+ }
704
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Fan RotationSpeed -> ${Math.round(value)}% (${logValueName})`);
705
+ return value;
706
+ }
707
+ async getName() {
708
+ //this.platform.api.updatePlatformAccessories([this.accessory]);
709
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Name ->`, this.accessory.displayName);
710
+ return this.accessory.displayName;
711
+ }
520
712
  // helper functions
521
713
  getDeviceLabel() {
522
- return `${this.accessory.displayName} -- ${this.accessory.context.device.address}:${this.accessory.context.device.port}`;
714
+ return `${this.accessory.displayName} -- ${this.accessory.context.device.address}`;
523
715
  }
524
716
  getCols() {
525
717
  if (!this.cols) {
@@ -594,7 +786,7 @@ class GreeAirConditioner {
594
786
  let targetValue;
595
787
  const heatingTargetValue = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).value) || 25;
596
788
  const coolingTargetValue = ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).value) || 25;
597
- switch (this.status[commands_1.default.mode.code]) {
789
+ switch (this.mode) {
598
790
  case commands_1.default.mode.value.heat:
599
791
  targetValue = heatingTargetValue;
600
792
  break;
@@ -632,69 +824,381 @@ class GreeAirConditioner {
632
824
  return (this.status[commands_1.default.power.code] === commands_1.default.power.value.on);
633
825
  }
634
826
  set power(value) {
635
- var _a;
636
- if (value === this.power) {
827
+ var _a, _b, _c, _d, _e;
828
+ if ((value === this.power && [commands_1.default.mode.value.cool, commands_1.default.mode.value.heat, commands_1.default.mode.value.auto].includes(this.mode)) ||
829
+ this.powerPending !== -1 || this.modePending !== -1) {
830
+ this.platform.log.debug(`[${this.getDeviceLabel()}] power -> no change (${this.power}, ${this.powerPending}, ${this.mode},`, `${this.modePending})`);
831
+ return;
832
+ }
833
+ if (!value && ![commands_1.default.mode.value.cool, commands_1.default.mode.value.heat, commands_1.default.mode.value.auto].includes(this.mode)) {
834
+ this.platform.log.debug(`[${this.getDeviceLabel()}] power -> set inactive but no power off (${this.mode})`);
637
835
  return;
638
836
  }
639
837
  const powerValue = value ? commands_1.default.power.value.on : commands_1.default.power.value.off;
640
838
  const command = { [commands_1.default.power.code]: powerValue };
641
839
  let logValue = 'power -> ' + this.getKeyName(commands_1.default.power.value, powerValue);
642
840
  if (powerValue === commands_1.default.power.value.on) {
643
- switch ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) {
841
+ switch (((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
842
+ this.accessory.context.TargetHeaterCoolerState) {
644
843
  case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
645
- if (this.status[commands_1.default.mode.code] !== commands_1.default.mode.value.cool) {
844
+ if (this.mode !== commands_1.default.mode.value.cool) {
646
845
  command[commands_1.default.mode.code] = commands_1.default.mode.value.cool;
647
- logValue += ', mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.cool);
846
+ logValue += (logValue ? ', ' : '') + 'mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.cool);
648
847
  if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.off) !== commands_1.default.xFan.value.on) {
649
848
  // turn on xFan in Cool mode if xFan is enabled for this device
650
- logValue += ', xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.on);
849
+ logValue += (logValue ? ', ' : '') + 'xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.on);
651
850
  command[commands_1.default.xFan.code] = commands_1.default.xFan.value.on;
652
851
  }
653
852
  }
654
853
  break;
655
854
  case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
656
- if (this.status[commands_1.default.mode.code] !== commands_1.default.mode.value.heat) {
855
+ if (this.mode !== commands_1.default.mode.value.heat) {
657
856
  command[commands_1.default.mode.code] = commands_1.default.mode.value.heat;
658
- logValue += ', mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.heat);
857
+ logValue += (logValue ? ', ' : '') + 'mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.heat);
858
+ if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.on) !== commands_1.default.xFan.value.off) {
859
+ // turn off xFan in unsupported modes (only Cool and Dry modes support xFan)
860
+ logValue += (logValue ? ', ' : '') + 'xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.off);
861
+ command[commands_1.default.xFan.code] = commands_1.default.xFan.value.off;
862
+ }
659
863
  }
660
864
  break;
661
865
  case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
662
- if (this.status[commands_1.default.mode.code] !== commands_1.default.mode.value.auto) {
866
+ if (this.mode !== commands_1.default.mode.value.auto) {
663
867
  command[commands_1.default.mode.code] = commands_1.default.mode.value.auto;
664
- logValue += ', mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.auto);
868
+ logValue += (logValue ? ', ' : '') + 'mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.auto);
869
+ if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.on) !== commands_1.default.xFan.value.off) {
870
+ // turn off xFan in unsupported modes (only Cool and Dry modes support xFan)
871
+ logValue += (logValue ? ', ' : '') + 'xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.off);
872
+ command[commands_1.default.xFan.code] = commands_1.default.xFan.value.off;
873
+ }
665
874
  }
666
875
  break;
667
876
  }
668
877
  if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
669
- settings_1.OVERRIDE_DEFAULT_SWING.never) && this.swingMode !== undefined) {
670
- const value = (this.swingMode === commands_1.default.swingVertical.value.default) ? this.deviceConfig.defaultVerticalSwing : this.swingMode;
878
+ settings_1.DEFAULT_DEVICE_CONFIG.overrideDefaultVerticalSwing) && this.swingMode === commands_1.default.swingVertical.value.default) {
879
+ const value = this.deviceConfig.defaultVerticalSwing || settings_1.DEFAULT_DEVICE_CONFIG.defaultVerticalSwing;
671
880
  command[commands_1.default.swingVertical.code] = value;
672
- logValue += ', swingVertical -> ' + this.getKeyName(commands_1.default.swingVertical.value, value);
881
+ logValue += (logValue ? ', ' : '') + 'swingVertical -> ' + this.getKeyName(commands_1.default.swingVertical.value, value);
882
+ }
883
+ if (this.accessory.context.HeaterCoolerRotationSpeed !== 0) {
884
+ // restore rotation speed on power on
885
+ const maxSpeed = ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) ||
886
+ this.deviceConfig.speedSteps + 3;
887
+ switch (this.accessory.context.HeaterCoolerRotationSpeed) {
888
+ case 1: // quiet
889
+ if ([this.platform.Characteristic.TargetHeaterCoolerState.COOL, this.platform.Characteristic.TargetHeaterCoolerState.HEAT]
890
+ .includes(((_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
891
+ this.accessory.context.TargetHeaterCoolerState)) {
892
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.on;
893
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.on);
894
+ }
895
+ else {
896
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
897
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
898
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
899
+ }
900
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
901
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
902
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
903
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.low;
904
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low);
905
+ break;
906
+ case 2: // auto
907
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
908
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
909
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
910
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
911
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
912
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
913
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
914
+ }
915
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.auto;
916
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
917
+ break;
918
+ case 3: // low
919
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
920
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
921
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
922
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
923
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
924
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
925
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
926
+ }
927
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.low;
928
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low);
929
+ break;
930
+ case 4: // mediumLow / medium
931
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
932
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
933
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
934
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
935
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
936
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
937
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
938
+ }
939
+ command[commands_1.default.speed.code] = maxSpeed === 8 ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium;
940
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, command[commands_1.default.speed.code]);
941
+ break;
942
+ case 5: // medium / high
943
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
944
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
945
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
946
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
947
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
948
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
949
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
950
+ }
951
+ command[commands_1.default.speed.code] = maxSpeed === 8 ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high;
952
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, command[commands_1.default.speed.code]);
953
+ break;
954
+ case 6: // mediumHigh / powerful
955
+ if (maxSpeed === 8) {
956
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
957
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
958
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
959
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
960
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
961
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
962
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
963
+ }
964
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.mediumHigh;
965
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.mediumHigh);
966
+ }
967
+ else {
968
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
969
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
970
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
971
+ if ([this.platform.Characteristic.TargetHeaterCoolerState.COOL, this.platform.Characteristic.TargetHeaterCoolerState.HEAT]
972
+ .includes(((_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
973
+ this.accessory.context.TargetHeaterCoolerState)) {
974
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.on;
975
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
976
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.on);
977
+ }
978
+ else {
979
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
980
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
981
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
982
+ }
983
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
984
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
985
+ }
986
+ break;
987
+ case 7: // high
988
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
989
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
990
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
991
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
992
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
993
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
994
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
995
+ }
996
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
997
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
998
+ break;
999
+ case 8: // powerful
1000
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1001
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1002
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1003
+ if ([this.platform.Characteristic.TargetHeaterCoolerState.COOL, this.platform.Characteristic.TargetHeaterCoolerState.HEAT]
1004
+ .includes(((_e = this.HeaterCooler) === null || _e === void 0 ? void 0 : _e.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
1005
+ this.accessory.context.TargetHeaterCoolerState)) {
1006
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.on;
1007
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1008
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.on);
1009
+ }
1010
+ else {
1011
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1012
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1013
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1014
+ }
1015
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
1016
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
1017
+ break;
1018
+ }
673
1019
  }
674
1020
  }
675
1021
  this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
676
1022
  this.sendCommand(command);
677
1023
  }
1024
+ set fanpower(value) {
1025
+ if (this.powerPending !== -1 || this.modePending !== -1) {
1026
+ this.platform.log.debug(`[${this.getDeviceLabel()}] fanpower -> no change (${this.powerPending}, ${this.modePending})`);
1027
+ return;
1028
+ }
1029
+ if (!value && this.mode !== commands_1.default.mode.value.fan) {
1030
+ this.platform.log.debug(`[${this.getDeviceLabel()}] fanpower -> set inactive but no power off (${this.mode})`);
1031
+ return;
1032
+ }
1033
+ const powerValue = value ? commands_1.default.power.value.on : commands_1.default.power.value.off;
1034
+ const command = {};
1035
+ let logValue = '';
1036
+ if (value !== this.power) {
1037
+ command[commands_1.default.power.code] = powerValue;
1038
+ logValue += (logValue ? ', ' : '') + 'power -> ' + this.getKeyName(commands_1.default.power.value, powerValue);
1039
+ if (powerValue === commands_1.default.power.value.on) {
1040
+ if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
1041
+ settings_1.DEFAULT_DEVICE_CONFIG.overrideDefaultVerticalSwing) && this.swingMode === commands_1.default.swingVertical.value.default) {
1042
+ const value = this.deviceConfig.defaultVerticalSwing || settings_1.DEFAULT_DEVICE_CONFIG.defaultVerticalSwing;
1043
+ command[commands_1.default.swingVertical.code] = value;
1044
+ logValue += (logValue ? ', ' : '') + 'swingVertical -> ' + this.getKeyName(commands_1.default.swingVertical.value, value);
1045
+ }
1046
+ }
1047
+ }
1048
+ if (powerValue === commands_1.default.power.value.on && this.mode !== commands_1.default.mode.value.fan) {
1049
+ command[commands_1.default.mode.code] = commands_1.default.mode.value.fan;
1050
+ logValue += (logValue ? ', ' : '') + 'mode -> ' + this.getKeyName(commands_1.default.mode.value, commands_1.default.mode.value.fan);
1051
+ }
1052
+ if (logValue) {
1053
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1054
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1055
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1056
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1057
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1058
+ this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
1059
+ this.sendCommand(command);
1060
+ }
1061
+ }
678
1062
  get mode() {
679
1063
  return this.status[commands_1.default.mode.code] || commands_1.default.mode.value.auto;
680
1064
  }
681
1065
  set mode(value) {
682
- if (value === this.mode) {
1066
+ var _a;
1067
+ if (value === this.mode || this.modePending !== -1) {
1068
+ this.platform.log.debug(`[${this.getDeviceLabel()}] mode -> no change (${value}, ${this.modePending})`);
683
1069
  return;
684
1070
  }
685
1071
  let logValue = 'mode -> ' + this.getKeyName(commands_1.default.mode.value, value);
686
1072
  const command = { [commands_1.default.mode.code]: value };
687
1073
  if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.off) !== commands_1.default.xFan.value.on &&
688
- (value === commands_1.default.mode.value.cool || value === commands_1.default.mode.value.dry)) {
1074
+ [commands_1.default.mode.value.cool, commands_1.default.mode.value.dry].includes(value)) {
689
1075
  // turn on xFan in Cool and Dry mode if xFan is enabled for this device
690
1076
  logValue += ', xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.on);
691
1077
  command[commands_1.default.xFan.code] = commands_1.default.xFan.value.on;
692
1078
  }
693
- if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
694
- settings_1.OVERRIDE_DEFAULT_SWING.never) && this.swingMode !== undefined) {
695
- const value = (this.swingMode === commands_1.default.swingVertical.value.default) ? this.deviceConfig.defaultVerticalSwing : this.swingMode;
696
- command[commands_1.default.swingVertical.code] = value;
697
- logValue += ', swingVertical -> ' + this.getKeyName(commands_1.default.swingVertical.value, value);
1079
+ else if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.on) !== commands_1.default.xFan.value.off &&
1080
+ ![commands_1.default.mode.value.cool, commands_1.default.mode.value.dry].includes(value)) {
1081
+ // turn off xFan in unsupported modes (only Cool and Dry modes support xFan)
1082
+ logValue += ', xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.off);
1083
+ command[commands_1.default.xFan.code] = commands_1.default.xFan.value.off;
1084
+ }
1085
+ if (this.accessory.context.HeaterCoolerRotationSpeed !== 0 &&
1086
+ [commands_1.default.mode.value.cool, commands_1.default.mode.value.heat, commands_1.default.mode.value.auto].includes(value)) {
1087
+ // restore rotation speed on mode change
1088
+ const maxSpeed = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) ||
1089
+ this.deviceConfig.speedSteps + 3;
1090
+ switch (this.accessory.context.HeaterCoolerRotationSpeed) {
1091
+ case 1: // quiet
1092
+ command[commands_1.default.quietMode.code] = value === commands_1.default.mode.value.auto ? commands_1.default.quietMode.value.off :
1093
+ commands_1.default.quietMode.value.on;
1094
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, value === commands_1.default.mode.value.auto ? commands_1.default.quietMode.value.off : commands_1.default.quietMode.value.on);
1095
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1096
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1097
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1098
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.low;
1099
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low);
1100
+ break;
1101
+ case 2: // auto
1102
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
1103
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1104
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1105
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1106
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1107
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1108
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1109
+ }
1110
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.auto;
1111
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
1112
+ break;
1113
+ case 3: // low
1114
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
1115
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1116
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1117
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1118
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1119
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1120
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1121
+ }
1122
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.low;
1123
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low);
1124
+ break;
1125
+ case 4: // mediumLow / medium
1126
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
1127
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1128
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1129
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1130
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1131
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1132
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1133
+ }
1134
+ command[commands_1.default.speed.code] = maxSpeed === 8 ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium;
1135
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, command[commands_1.default.speed.code]);
1136
+ break;
1137
+ case 5: // medium / high
1138
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
1139
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1140
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1141
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1142
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1143
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1144
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1145
+ }
1146
+ command[commands_1.default.speed.code] = maxSpeed === 8 ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high;
1147
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, command[commands_1.default.speed.code]);
1148
+ break;
1149
+ case 6: // mediumHigh / powerful
1150
+ if (maxSpeed === 8) {
1151
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
1152
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1153
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1154
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1155
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1156
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1157
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1158
+ }
1159
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.mediumHigh;
1160
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.mediumHigh);
1161
+ }
1162
+ else {
1163
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1164
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1165
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1166
+ command[commands_1.default.powerfulMode.code] = value === commands_1.default.mode.value.auto ? commands_1.default.powerfulMode.value.off :
1167
+ commands_1.default.powerfulMode.value.on;
1168
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1169
+ this.getKeyName(commands_1.default.powerfulMode.value, value === commands_1.default.mode.value.auto ? commands_1.default.powerfulMode.value.off :
1170
+ commands_1.default.powerfulMode.value.on);
1171
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
1172
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
1173
+ }
1174
+ break;
1175
+ case 7: // high
1176
+ if (this.quietMode !== commands_1.default.quietMode.value.off || this.powerfulMode !== commands_1.default.powerfulMode.value.off) {
1177
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1178
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1179
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1180
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1181
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1182
+ this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1183
+ }
1184
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
1185
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
1186
+ break;
1187
+ case 8: // powerful
1188
+ if ([commands_1.default.mode.value.cool, commands_1.default.mode.value.heat].includes(value)) {
1189
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1190
+ logValue += (logValue ? ', ' : '') + 'quietMode -> ' +
1191
+ this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1192
+ command[commands_1.default.powerfulMode.code] = value === commands_1.default.mode.value.auto ? commands_1.default.powerfulMode.value.off :
1193
+ commands_1.default.powerfulMode.value.on;
1194
+ logValue += (logValue ? ', ' : '') + 'powerfulMode -> ' +
1195
+ this.getKeyName(commands_1.default.powerfulMode.value, value === commands_1.default.mode.value.auto ? commands_1.default.powerfulMode.value.off :
1196
+ commands_1.default.powerfulMode.value.on);
1197
+ }
1198
+ command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
1199
+ logValue += (logValue ? ', ' : '') + 'speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
1200
+ break;
1201
+ }
698
1202
  }
699
1203
  this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
700
1204
  this.sendCommand(command);
@@ -706,7 +1210,7 @@ class GreeAirConditioner {
706
1210
  var _a, _b, _c, _d, _e, _f, _g, _h;
707
1211
  let minValue = this.deviceConfig.minimumTargetTemperature;
708
1212
  let maxValue = this.deviceConfig.maximumTargetTemperature;
709
- switch (this.status[commands_1.default.mode.code]) {
1213
+ switch (this.mode) {
710
1214
  case commands_1.default.mode.value.cool:
711
1215
  minValue = Math.max(this.deviceConfig.minimumTargetTemperature, ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.minValue) || 10);
712
1216
  maxValue = Math.min(this.deviceConfig.maximumTargetTemperature, ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.maxValue) || 35);
@@ -724,6 +1228,7 @@ class GreeAirConditioner {
724
1228
  set targetTemperature(value) {
725
1229
  var _a;
726
1230
  if (value === this.targetTemperature) {
1231
+ this.platform.log.debug(`[${this.getDeviceLabel()}] targetTemperature -> no change (${value})`);
727
1232
  return;
728
1233
  }
729
1234
  const tempValue = this.calcDeviceTargetTemp(value);
@@ -753,6 +1258,7 @@ class GreeAirConditioner {
753
1258
  }
754
1259
  set units(value) {
755
1260
  if (value === this.units) {
1261
+ this.platform.log.debug(`[${this.getDeviceLabel()}] units -> no change (${value})`);
756
1262
  return;
757
1263
  }
758
1264
  const command = { [commands_1.default.units.code]: value };
@@ -777,6 +1283,7 @@ class GreeAirConditioner {
777
1283
  }
778
1284
  set swingMode(value) {
779
1285
  if (value === this.swingMode) {
1286
+ this.platform.log.debug(`[${this.getDeviceLabel()}] swingMode -> no change (${value})`);
780
1287
  return;
781
1288
  }
782
1289
  const command = { [commands_1.default.swingVertical.code]: value };
@@ -787,7 +1294,8 @@ class GreeAirConditioner {
787
1294
  return this.status[commands_1.default.speed.code] || commands_1.default.speed.value.auto;
788
1295
  }
789
1296
  set speed(value) {
790
- if (value === this.speed) {
1297
+ if (value === this.speed && this.quietMode === commands_1.default.quietMode.value.off && this.powerfulMode === commands_1.default.powerfulMode.value.off) {
1298
+ this.platform.log.debug(`[${this.getDeviceLabel()}] speed -> no change (${value}, ${this.quietMode}, ${this.powerfulMode})`);
791
1299
  return;
792
1300
  }
793
1301
  const command = { [commands_1.default.speed.code]: value };
@@ -802,54 +1310,78 @@ class GreeAirConditioner {
802
1310
  return this.status[commands_1.default.quietMode.code] || commands_1.default.quietMode.value.off;
803
1311
  }
804
1312
  set quietMode(value) {
805
- if (value === this.quietMode) {
1313
+ var _a;
1314
+ if (value === this.quietMode || value !== commands_1.default.quietMode.value.on) {
1315
+ this.platform.log.debug(`[${this.getDeviceLabel()}] quietMode -> not turning on (${value})`);
806
1316
  return;
807
1317
  }
808
- const command = { [commands_1.default.quietMode.code]: value };
809
- let logValue = 'quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, value);
1318
+ let logValue = '';
1319
+ const command = {};
1320
+ if ([this.platform.Characteristic.TargetHeaterCoolerState.COOL, this.platform.Characteristic.TargetHeaterCoolerState.HEAT]
1321
+ .includes(((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
1322
+ this.accessory.context.TargetHeaterCoolerState)) {
1323
+ command[commands_1.default.quietMode.code] = value;
1324
+ logValue += 'quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, value);
1325
+ }
1326
+ else {
1327
+ // quiet mode is supported only in heating and cooling mode
1328
+ command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
1329
+ logValue += 'quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
1330
+ }
810
1331
  if (value === commands_1.default.quietMode.value.on) {
811
1332
  command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
812
1333
  logValue += ', powerfulMode -> ' + this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
813
1334
  command[commands_1.default.speed.code] = commands_1.default.speed.value.low;
814
1335
  logValue += ', speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low);
1336
+ this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
1337
+ this.sendCommand(command);
815
1338
  }
816
- else {
817
- command[commands_1.default.speed.code] = commands_1.default.speed.value.auto;
818
- logValue += ', speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
819
- }
820
- this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
821
- this.sendCommand(command);
822
1339
  }
823
1340
  get powerfulMode() {
824
1341
  return this.status[commands_1.default.powerfulMode.code] || commands_1.default.powerfulMode.value.off;
825
1342
  }
826
1343
  set powerfulMode(value) {
827
- if (value === this.powerfulMode) {
1344
+ var _a;
1345
+ if (value === this.powerfulMode || value !== commands_1.default.powerfulMode.value.on) {
1346
+ this.platform.log.debug(`[${this.getDeviceLabel()}] powerfulMode -> not turning on (${value})`);
828
1347
  return;
829
1348
  }
830
- let logValue = 'powerfulMode -> ' + this.getKeyName(commands_1.default.powerfulMode.value, value);
831
- const command = { [commands_1.default.powerfulMode.code]: value };
1349
+ let logValue = '';
1350
+ const command = {};
1351
+ if ([this.platform.Characteristic.TargetHeaterCoolerState.COOL, this.platform.Characteristic.TargetHeaterCoolerState.HEAT]
1352
+ .includes(((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).value) ||
1353
+ this.accessory.context.TargetHeaterCoolerState)) {
1354
+ command[commands_1.default.powerfulMode.code] = value;
1355
+ logValue += 'powerfulMode -> ' + this.getKeyName(commands_1.default.powerfulMode.value, value);
1356
+ }
1357
+ else {
1358
+ // powerful mode is supported only in heating and cooling mode
1359
+ command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
1360
+ logValue += 'powerfulMode -> ' + this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
1361
+ }
832
1362
  if (value === commands_1.default.powerfulMode.value.on) {
833
1363
  command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
834
1364
  logValue += ', quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
835
1365
  command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
836
1366
  logValue += ', speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
1367
+ this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
1368
+ this.sendCommand(command);
837
1369
  }
838
- else {
839
- command[commands_1.default.speed.code] = commands_1.default.speed.value.auto;
840
- logValue += ', speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
841
- }
842
- this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
843
- this.sendCommand(command);
844
1370
  }
845
1371
  updateStatus(props) {
846
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
1372
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
847
1373
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus -> %j`, props);
848
- // Active
849
- if (props.includes(commands_1.default.power.code)) {
850
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Active) ->`, this.power ? 'ACTIVE' : 'INACTIVE');
851
- (_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.power ?
852
- this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE);
1374
+ const hcActive = this.power && [commands_1.default.mode.value.cool, commands_1.default.mode.value.heat, commands_1.default.mode.value.auto].includes(this.mode);
1375
+ const fanActive = this.power && this.mode === commands_1.default.mode.value.fan;
1376
+ // Heater-Cooler Active
1377
+ if (props.includes(commands_1.default.power.code) || props.includes(commands_1.default.mode.code)) {
1378
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Heater-Cooler Active) ->`, hcActive ? 'ACTIVE' : 'INACTIVE');
1379
+ (_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.Active).updateValue(hcActive ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE);
1380
+ }
1381
+ // Fan Active
1382
+ if (this.Fan && (props.includes(commands_1.default.power.code) || props.includes(commands_1.default.mode.code))) {
1383
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Fan Active) ->`, fanActive ? 'ACTIVE' : 'INACTIVE');
1384
+ (_b = this.Fan) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.Active).updateValue(fanActive ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE);
853
1385
  }
854
1386
  // Current Heater-Cooler State
855
1387
  if (props.includes(commands_1.default.mode.code)) {
@@ -857,16 +1389,11 @@ class GreeAirConditioner {
857
1389
  switch (this.mode) {
858
1390
  case commands_1.default.mode.value.cool:
859
1391
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Heater-Cooler State) -> COOLING`);
860
- (_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.COOLING);
1392
+ (_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.COOLING);
861
1393
  break;
862
1394
  case commands_1.default.mode.value.heat:
863
1395
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Heater-Cooler State) -> HEATING`);
864
- (_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.HEATING);
865
- break;
866
- case commands_1.default.mode.value.fan:
867
- case commands_1.default.mode.value.dry:
868
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Heater-Cooler State) -> IDLE`);
869
- (_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.IDLE);
1396
+ (_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.HEATING);
870
1397
  break;
871
1398
  case commands_1.default.mode.value.auto:
872
1399
  if (this.currentTemperature > this.targetTemperature + 1.5) {
@@ -889,57 +1416,79 @@ class GreeAirConditioner {
889
1416
  (_h = this.HeaterCooler) === null || _h === void 0 ? void 0 : _h.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE);
890
1417
  }
891
1418
  }
1419
+ // Current Fan State
1420
+ if (this.Fan && props.includes(commands_1.default.mode.code)) {
1421
+ if (this.power && this.mode === commands_1.default.mode.value.fan) {
1422
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Fan State) -> BLOWING_AIR`);
1423
+ (_j = this.Fan) === null || _j === void 0 ? void 0 : _j.getCharacteristic(this.platform.Characteristic.CurrentFanState).updateValue(this.platform.Characteristic.CurrentFanState.BLOWING_AIR);
1424
+ }
1425
+ else {
1426
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Fan State) -> INACTIVE`);
1427
+ (_k = this.Fan) === null || _k === void 0 ? void 0 : _k.getCharacteristic(this.platform.Characteristic.CurrentFanState).updateValue(this.platform.Characteristic.CurrentFanState.INACTIVE);
1428
+ }
1429
+ }
892
1430
  // Target Heater-Cooler State
893
- if (props.includes(commands_1.default.mode.code) && this.power) {
1431
+ if (props.includes(commands_1.default.mode.code) && this.power &&
1432
+ [commands_1.default.mode.value.cool, commands_1.default.mode.value.heat, commands_1.default.mode.value.auto].includes(this.mode)) {
894
1433
  switch (this.mode) {
895
1434
  case commands_1.default.mode.value.cool:
896
1435
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Target Heater-Cooler State) -> COOL`);
897
- (_j = this.HeaterCooler) === null || _j === void 0 ? void 0 : _j.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).updateValue(this.platform.Characteristic.TargetHeaterCoolerState.COOL);
1436
+ (_l = this.HeaterCooler) === null || _l === void 0 ? void 0 : _l.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).updateValue(this.platform.Characteristic.TargetHeaterCoolerState.COOL);
1437
+ this.accessory.context.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
898
1438
  break;
899
1439
  case commands_1.default.mode.value.heat:
900
1440
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Target Heater-Cooler State) -> HEAT`);
901
- (_k = this.HeaterCooler) === null || _k === void 0 ? void 0 : _k.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).updateValue(this.platform.Characteristic.TargetHeaterCoolerState.HEAT);
1441
+ (_m = this.HeaterCooler) === null || _m === void 0 ? void 0 : _m.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).updateValue(this.platform.Characteristic.TargetHeaterCoolerState.HEAT);
1442
+ this.accessory.context.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
902
1443
  break;
903
- default:
1444
+ case commands_1.default.mode.value.auto:
904
1445
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Target Heater-Cooler State) -> AUTO`);
905
- (_l = this.HeaterCooler) === null || _l === void 0 ? void 0 : _l.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).updateValue(this.platform.Characteristic.TargetHeaterCoolerState.AUTO);
1446
+ (_o = this.HeaterCooler) === null || _o === void 0 ? void 0 : _o.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState).updateValue(this.platform.Characteristic.TargetHeaterCoolerState.AUTO);
1447
+ this.accessory.context.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
1448
+ break;
906
1449
  }
1450
+ this.platform.api.updatePlatformAccessories([this.accessory]);
907
1451
  }
908
1452
  // Current Temperature
909
1453
  if (props.includes(commands_1.default.temperature.code)) {
910
1454
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Temperature) ->`, this.currentTemperature);
911
- (_m = this.HeaterCooler) === null || _m === void 0 ? void 0 : _m.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
912
- (_o = this.TemperatureSensor) === null || _o === void 0 ? void 0 : _o.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
913
- (_p = this.tsAccessory) === null || _p === void 0 ? void 0 : _p.setCurrentTemperature(this.currentTemperature);
914
- (_q = this.tsAccessory) === null || _q === void 0 ? void 0 : _q.TemperatureSensor.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
1455
+ (_p = this.HeaterCooler) === null || _p === void 0 ? void 0 : _p.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
1456
+ (_q = this.TemperatureSensor) === null || _q === void 0 ? void 0 : _q.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
1457
+ (_r = this.tsAccessory) === null || _r === void 0 ? void 0 : _r.setCurrentTemperature(this.currentTemperature);
1458
+ (_s = this.tsAccessory) === null || _s === void 0 ? void 0 : _s.TemperatureSensor.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
915
1459
  }
916
1460
  else if (props.includes(commands_1.default.targetTemperature.code) && this.TemperatureSensor === undefined) {
917
1461
  // temperature is not accessible -> targetTemperature is saved as currentTemperature
918
1462
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Temperature) ->`, this.currentTemperature);
919
- (_r = this.HeaterCooler) === null || _r === void 0 ? void 0 : _r.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
1463
+ (_t = this.HeaterCooler) === null || _t === void 0 ? void 0 : _t.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
920
1464
  }
921
1465
  // Cooling Threshold Temperature
922
1466
  if (props.includes(commands_1.default.targetTemperature.code) && this.power &&
923
1467
  (this.mode === commands_1.default.mode.value.cool || this.mode === commands_1.default.mode.value.auto)) {
924
1468
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Cooling Threshold Temperature) ->`, this.targetTemperature);
925
- (_s = this.HeaterCooler) === null || _s === void 0 ? void 0 : _s.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).updateValue(this.targetTemperature);
1469
+ (_u = this.HeaterCooler) === null || _u === void 0 ? void 0 : _u.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).updateValue(this.targetTemperature);
926
1470
  }
927
1471
  // Heating Threshold Temperature
928
1472
  if (props.includes(commands_1.default.targetTemperature.code) && this.power &&
929
1473
  (this.mode === commands_1.default.mode.value.heat || this.mode === commands_1.default.mode.value.auto)) {
930
1474
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Heating Threshold Temperature) ->`, this.targetTemperature);
931
- (_t = this.HeaterCooler) === null || _t === void 0 ? void 0 : _t.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).updateValue(this.targetTemperature);
1475
+ (_v = this.HeaterCooler) === null || _v === void 0 ? void 0 : _v.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).updateValue(this.targetTemperature);
932
1476
  }
933
1477
  // Temperature Display Units
934
1478
  if (props.includes(commands_1.default.units.code)) {
935
1479
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Temperature Display Units) ->`, this.units === commands_1.default.units.value.celsius ? 'CELSIUS' : 'FAHRENHEIT');
936
- (_u = this.HeaterCooler) === null || _u === void 0 ? void 0 : _u.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits).updateValue(this.units === commands_1.default.units.value.celsius ?
1480
+ (_w = this.HeaterCooler) === null || _w === void 0 ? void 0 : _w.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits).updateValue(this.units === commands_1.default.units.value.celsius ?
937
1481
  this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS : this.platform.Characteristic.TemperatureDisplayUnits.FAHRENHEIT);
938
1482
  }
939
1483
  // Swing Mode
940
1484
  if (props.includes(commands_1.default.swingVertical.code) && this.power) {
941
1485
  let swing = this.platform.Characteristic.SwingMode.SWING_ENABLED;
942
1486
  let logValue = 'ENABLED';
1487
+ if ([commands_1.default.swingVertical.value.full, commands_1.default.swingVertical.value.swingHigher,
1488
+ commands_1.default.swingVertical.value.swingHighest, commands_1.default.swingVertical.value.swingLower, commands_1.default.swingVertical.value.swingLowest,
1489
+ commands_1.default.swingVertical.value.swingMiddle].includes(this.swingMode)) {
1490
+ logValue += ` (type: ${this.getKeyName(commands_1.default.swingVertical.value, this.swingMode)})`;
1491
+ }
943
1492
  switch (this.swingMode) {
944
1493
  case commands_1.default.swingVertical.value.default:
945
1494
  case commands_1.default.swingVertical.value.fixedHighest:
@@ -948,58 +1497,79 @@ class GreeAirConditioner {
948
1497
  case commands_1.default.swingVertical.value.fixedLower:
949
1498
  case commands_1.default.swingVertical.value.fixedLowest:
950
1499
  swing = this.platform.Characteristic.SwingMode.SWING_DISABLED;
951
- logValue = 'DISABLED';
952
- if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
953
- settings_1.OVERRIDE_DEFAULT_SWING.never)) {
954
- logValue += ' (' + this.getKeyName(commands_1.default.swingVertical.value, this.swingMode) + ')';
955
- }
1500
+ logValue = `DISABLED (position: ${this.getKeyName(commands_1.default.swingVertical.value, this.swingMode)})`;
956
1501
  break;
957
1502
  }
958
1503
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Swing Mode) ->`, logValue);
959
- (_v = this.HeaterCooler) === null || _v === void 0 ? void 0 : _v.getCharacteristic(this.platform.Characteristic.SwingMode).updateValue(swing);
1504
+ (_x = this.HeaterCooler) === null || _x === void 0 ? void 0 : _x.getCharacteristic(this.platform.Characteristic.SwingMode).updateValue(swing);
960
1505
  }
961
- // Rotation Speed
962
- if (this.power) {
963
- let logValue = '2 (auto)';
1506
+ // Heater-Cooler Rotation Speed
1507
+ if (hcActive) {
1508
+ const maxSpeed = ((_y = this.HeaterCooler) === null || _y === void 0 ? void 0 : _y.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) ||
1509
+ this.deviceConfig.speedSteps + 3;
964
1510
  if (props.includes(commands_1.default.quietMode.code) && this.quietMode === commands_1.default.quietMode.value.on) {
965
1511
  // quietMode -> on
966
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Rotation Speed) -> 1 (quiet)`);
967
- (_w = this.HeaterCooler) === null || _w === void 0 ? void 0 : _w.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(1);
1512
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Heater-Cooler Rotation Speed) -> 1 (quiet)`);
1513
+ (_z = this.HeaterCooler) === null || _z === void 0 ? void 0 : _z.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(1);
1514
+ this.accessory.context.HeaterCoolerRotationSpeed = 1;
968
1515
  }
969
1516
  else if (props.includes(commands_1.default.powerfulMode.code) && this.powerfulMode === commands_1.default.powerfulMode.value.on) {
970
1517
  // powerfulMode -> on
971
- logValue = `${this.deviceConfig.speedSteps + 3} (powerful)`;
972
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Rotation Speed) ->`, logValue);
973
- (_x = this.HeaterCooler) === null || _x === void 0 ? void 0 : _x.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(this.deviceConfig.speedSteps + 3);
1518
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Heater-Cooler Rotation Speed) ->`, `${maxSpeed.toString()} (powerful)`);
1519
+ (_0 = this.HeaterCooler) === null || _0 === void 0 ? void 0 : _0.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(maxSpeed);
1520
+ this.accessory.context.HeaterCoolerRotationSpeed = maxSpeed;
974
1521
  }
975
1522
  else if (props.includes(commands_1.default.speed.code)) {
976
- // speed
977
1523
  let speedValue = 2; // default: auto
978
1524
  switch (this.speed) {
979
1525
  case commands_1.default.speed.value.low:
980
- logValue = '3 (low)';
981
1526
  speedValue = 3;
982
1527
  break;
983
1528
  case commands_1.default.speed.value.mediumLow:
984
- logValue = '4 (mediumLow)';
985
1529
  speedValue = 4;
986
1530
  break;
987
1531
  case commands_1.default.speed.value.medium:
988
- logValue = ((this.deviceConfig.speedSteps === 5) ? '5' : '4') + ' (medium)';
989
- speedValue = (this.deviceConfig.speedSteps === 5) ? 5 : 4;
1532
+ speedValue = (maxSpeed === 8) ? 5 : 4;
990
1533
  break;
991
1534
  case commands_1.default.speed.value.mediumHigh:
992
- logValue = ((this.deviceConfig.speedSteps === 5) ? '6' : '4') + ' (mediumHigh)';
993
- speedValue = (this.deviceConfig.speedSteps === 5) ? 6 : 4;
1535
+ speedValue = (maxSpeed === 8) ? 6 : 4;
994
1536
  break;
995
1537
  case commands_1.default.speed.value.high:
996
- logValue = ((this.deviceConfig.speedSteps === 5) ? '7' : '5') + ' (high)';
997
- speedValue = (this.deviceConfig.speedSteps === 5) ? 7 : 5;
1538
+ speedValue = (maxSpeed === 8) ? 7 : 5;
998
1539
  break;
999
1540
  }
1000
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Rotation Speed) ->`, logValue);
1001
- (_y = this.HeaterCooler) === null || _y === void 0 ? void 0 : _y.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(speedValue);
1541
+ const speedName = this.getKeyName(commands_1.default.speed.value, this.speed);
1542
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Heater-Cooler Rotation Speed) ->`, `${speedValue.toString()} (${speedName})`);
1543
+ (_1 = this.HeaterCooler) === null || _1 === void 0 ? void 0 : _1.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(speedValue);
1544
+ this.accessory.context.HeaterCoolerRotationSpeed = speedValue;
1002
1545
  }
1546
+ this.platform.api.updatePlatformAccessories([this.accessory]);
1547
+ }
1548
+ // Fan Rotation Speed
1549
+ if (fanActive) {
1550
+ const minStep = ((_2 = this.Fan) === null || _2 === void 0 ? void 0 : _2.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minStep) ||
1551
+ 100 / (this.deviceConfig.speedSteps + 1);
1552
+ let fanSpeedValue = 100; // default: auto
1553
+ switch (this.speed) {
1554
+ case commands_1.default.speed.value.low:
1555
+ fanSpeedValue = minStep;
1556
+ break;
1557
+ case commands_1.default.speed.value.mediumLow:
1558
+ fanSpeedValue = 2 * minStep;
1559
+ break;
1560
+ case commands_1.default.speed.value.medium:
1561
+ fanSpeedValue = (minStep !== 25 ? 3 : 2) * minStep;
1562
+ break;
1563
+ case commands_1.default.speed.value.mediumHigh:
1564
+ fanSpeedValue = (minStep !== 25 ? 4 : 2) * minStep;
1565
+ break;
1566
+ case commands_1.default.speed.value.high:
1567
+ fanSpeedValue = (minStep !== 25 ? 5 : 3) * minStep;
1568
+ break;
1569
+ }
1570
+ const speedName = this.getKeyName(commands_1.default.speed.value, this.speed);
1571
+ this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Fan Rotation Speed) ->`, `${Math.round(fanSpeedValue)}% (${speedName})`);
1572
+ (_3 = this.Fan) === null || _3 === void 0 ? void 0 : _3.getCharacteristic(this.platform.Characteristic.RotationSpeed).updateValue(fanSpeedValue);
1003
1573
  }
1004
1574
  }
1005
1575
  sendMessage(message) {
@@ -1062,6 +1632,12 @@ class GreeAirConditioner {
1062
1632
  opt: keys,
1063
1633
  p: values,
1064
1634
  };
1635
+ if (keys.includes(commands_1.default.power.code)) {
1636
+ this.powerPending = values[keys.indexOf(commands_1.default.power.code)];
1637
+ }
1638
+ if (keys.includes(commands_1.default.mode.code)) {
1639
+ this.modePending = values[keys.indexOf(commands_1.default.mode.code)];
1640
+ }
1065
1641
  this.sendMessage(message);
1066
1642
  }
1067
1643
  requestDeviceStatus() {