homebridge-gree-ac 2.1.7 → 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) {
@@ -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,12 @@ 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));
270
335
  // register handlers for the Name Characteristic
271
336
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Name)
272
337
  .onGet(this.getName.bind(this));
@@ -299,9 +364,24 @@ class GreeAirConditioner {
299
364
  * These are sent when the user changes the state of an accessory
300
365
  */
301
366
  async setActive(value) {
367
+ var _a, _b;
302
368
  const powerValue = (value === this.platform.Characteristic.Active.ACTIVE);
303
- 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');
304
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
+ }
305
385
  }
306
386
  async setTargetHeaterCoolerState(value) {
307
387
  let modeValue = commands_1.default.mode.value.auto;
@@ -318,6 +398,8 @@ class GreeAirConditioner {
318
398
  }
319
399
  this.platform.log.debug(`[${this.getDeviceLabel()}] Set TargetHeaterCoolerState ->`, logValue);
320
400
  this.mode = modeValue;
401
+ this.accessory.context.TargetHeaterCoolerState = value;
402
+ this.platform.api.updatePlatformAccessories([this.accessory]);
321
403
  }
322
404
  async setTargetTemperature(value) {
323
405
  this.platform.log.debug(`[${this.getDeviceLabel()}] Set ThresholdTemperature ->`, value);
@@ -334,62 +416,108 @@ class GreeAirConditioner {
334
416
  this.platform.log.debug(`[${this.getDeviceLabel()}] Set SwingMode ->`, logValue);
335
417
  this.swingMode = (value === this.platform.Characteristic.SwingMode.SWING_ENABLED) ?
336
418
  commands_1.default.swingVertical.value.full : (this.deviceConfig.overrideDefaultVerticalSwing === settings_1.OVERRIDE_DEFAULT_SWING.always) ?
337
- 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;
338
420
  }
339
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;
340
425
  switch (value) {
426
+ case 0: // inactive -> rotation speed change not needed
427
+ return;
341
428
  case 1: // quiet
342
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (quiet)');
429
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (quiet)');
343
430
  this.quietMode = commands_1.default.quietMode.value.on;
344
431
  break;
345
432
  case 2: // auto
346
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
433
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
347
434
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto) + ')');
348
435
  this.speed = commands_1.default.speed.value.auto;
349
436
  break;
350
437
  case 3: // low
351
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
438
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
352
439
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.low) + ')');
353
440
  this.speed = commands_1.default.speed.value.low;
354
441
  break;
355
442
  case 4: // mediumLow / medium
356
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (' +
357
- this.getKeyName(commands_1.default.speed.value, (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.mediumLow : commands_1.default.speed.value.medium) + ')');
358
- 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;
359
446
  break;
360
447
  case 5: // medium / high
361
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (' +
362
- this.getKeyName(commands_1.default.speed.value, (this.deviceConfig.speedSteps === 5) ? commands_1.default.speed.value.medium : commands_1.default.speed.value.high) + ')');
363
- 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;
364
451
  break;
365
452
  case 6: // mediumHigh / powerful
366
- if (this.deviceConfig.speedSteps === 5) {
453
+ if (maxSpeed === 8) {
367
454
  // mediumHigh
368
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
455
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
369
456
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.mediumHigh) + ')');
370
457
  this.speed = commands_1.default.speed.value.mediumHigh;
371
458
  }
372
459
  else {
373
460
  // powerful
374
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (powerful)');
461
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (powerful)');
375
462
  this.powerfulMode = commands_1.default.powerfulMode.value.on;
376
463
  }
377
464
  break;
378
465
  case 7: // high
379
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
466
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
380
467
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high) + ')');
381
468
  this.speed = commands_1.default.speed.value.high;
382
469
  break;
383
470
  case 8: // powerful
384
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value + ' (powerful)');
471
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value + ' (powerful)');
385
472
  this.powerfulMode = commands_1.default.powerfulMode.value.on;
386
473
  break;
387
474
  default: // auto
388
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set RotationSpeed ->`, value +
475
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Set Heater-Cooler RotationSpeed ->`, value +
389
476
  ' (' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto) + ')');
390
477
  this.speed = commands_1.default.speed.value.auto;
391
478
  break;
392
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);
393
521
  }
394
522
  /**
395
523
  * Handle the "GET" requests from HomeKit
@@ -408,10 +536,14 @@ class GreeAirConditioner {
408
536
  * throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
409
537
  */
410
538
  async getActive() {
411
- const currentPower = this.power;
412
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get Active ->`, currentPower ? 'ACTIVE' : 'INACTIVE');
413
- return currentPower ?
414
- 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;
415
547
  }
416
548
  async getCurrentHeaterCoolerState() {
417
549
  if (this.power) {
@@ -422,10 +554,6 @@ class GreeAirConditioner {
422
554
  case commands_1.default.mode.value.heat:
423
555
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> HEATING`);
424
556
  return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
425
- case commands_1.default.mode.value.fan:
426
- case commands_1.default.mode.value.dry:
427
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> IDLE`);
428
- return this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
429
557
  case commands_1.default.mode.value.auto:
430
558
  if (this.currentTemperature > this.status[commands_1.default.targetTemperature.code]) {
431
559
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> COOLING`);
@@ -442,6 +570,14 @@ class GreeAirConditioner {
442
570
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> INACTIVE`);
443
571
  return this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
444
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
+ }
445
581
  async getTargetHeaterCoolerState() {
446
582
  switch (this.mode) {
447
583
  case commands_1.default.mode.value.cool:
@@ -450,9 +586,23 @@ class GreeAirConditioner {
450
586
  case commands_1.default.mode.value.heat:
451
587
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> HEAT`);
452
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;
453
604
  }
454
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get TargetHeaterCoolerState -> AUTO`);
455
- return this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
605
+ return this.accessory.context.TargetHeaterCoolerState;
456
606
  }
457
607
  async getCurrentTemperature(service) {
458
608
  const currentValue = this.currentTemperature;
@@ -485,13 +635,16 @@ class GreeAirConditioner {
485
635
  return this.platform.Characteristic.SwingMode.SWING_ENABLED;
486
636
  }
487
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;
488
641
  if (this.quietMode === commands_1.default.quietMode.value.on) {
489
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get RotationSpeed -> 1 (quiet)`);
642
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler RotationSpeed -> 1 (quiet)`);
490
643
  return 1;
491
644
  }
492
645
  if (this.powerfulMode === commands_1.default.powerfulMode.value.on) {
493
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get RotationSpeed ->`, (this.deviceConfig.speedSteps + 3) + ' (powerful)');
494
- return this.deviceConfig.speedSteps + 3;
646
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler RotationSpeed -> ${maxSpeed} (powerful)`);
647
+ return maxSpeed;
495
648
  }
496
649
  let value = 2; // default to auto
497
650
  let logValue = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
@@ -502,22 +655,53 @@ class GreeAirConditioner {
502
655
  break;
503
656
  case commands_1.default.speed.value.mediumLow:
504
657
  value = 4;
505
- 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);
506
659
  break;
507
660
  case commands_1.default.speed.value.medium:
508
- value = (this.deviceConfig.speedSteps === 5) ? 5 : 4;
661
+ value = (maxSpeed === 8) ? 5 : 4;
509
662
  logValue = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.medium);
510
663
  break;
511
664
  case commands_1.default.speed.value.mediumHigh:
512
- value = (this.deviceConfig.speedSteps === 5) ? 6 : 4;
513
- 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);
514
667
  break;
515
668
  case commands_1.default.speed.value.high:
516
- value = (this.deviceConfig.speedSteps === 5) ? 7 : 5;
669
+ value = (maxSpeed === 8) ? 7 : 5;
517
670
  logValue = this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.high);
518
671
  break;
519
672
  }
520
- this.platform.log.debug(`[${this.getDeviceLabel()}] Get RotationSpeed ->`, value + ' (' + logValue + ')');
673
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Get Heater-Cooler RotationSpeed ->`, value + ' (' + logValue + ')');
674
+ return value;
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})`);
521
705
  return value;
522
706
  }
523
707
  async getName() {
@@ -527,7 +711,7 @@ class GreeAirConditioner {
527
711
  }
528
712
  // helper functions
529
713
  getDeviceLabel() {
530
- return `${this.accessory.displayName} -- ${this.accessory.context.device.address}:${this.accessory.context.device.port}`;
714
+ return `${this.accessory.displayName} -- ${this.accessory.context.device.address}`;
531
715
  }
532
716
  getCols() {
533
717
  if (!this.cols) {
@@ -602,7 +786,7 @@ class GreeAirConditioner {
602
786
  let targetValue;
603
787
  const heatingTargetValue = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).value) || 25;
604
788
  const coolingTargetValue = ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).value) || 25;
605
- switch (this.status[commands_1.default.mode.code]) {
789
+ switch (this.mode) {
606
790
  case commands_1.default.mode.value.heat:
607
791
  targetValue = heatingTargetValue;
608
792
  break;
@@ -640,69 +824,381 @@ class GreeAirConditioner {
640
824
  return (this.status[commands_1.default.power.code] === commands_1.default.power.value.on);
641
825
  }
642
826
  set power(value) {
643
- var _a;
644
- 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})`);
645
835
  return;
646
836
  }
647
837
  const powerValue = value ? commands_1.default.power.value.on : commands_1.default.power.value.off;
648
838
  const command = { [commands_1.default.power.code]: powerValue };
649
839
  let logValue = 'power -> ' + this.getKeyName(commands_1.default.power.value, powerValue);
650
840
  if (powerValue === commands_1.default.power.value.on) {
651
- 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) {
652
843
  case this.platform.Characteristic.TargetHeaterCoolerState.COOL:
653
- if (this.status[commands_1.default.mode.code] !== commands_1.default.mode.value.cool) {
844
+ if (this.mode !== commands_1.default.mode.value.cool) {
654
845
  command[commands_1.default.mode.code] = commands_1.default.mode.value.cool;
655
- 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);
656
847
  if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.off) !== commands_1.default.xFan.value.on) {
657
848
  // turn on xFan in Cool mode if xFan is enabled for this device
658
- 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);
659
850
  command[commands_1.default.xFan.code] = commands_1.default.xFan.value.on;
660
851
  }
661
852
  }
662
853
  break;
663
854
  case this.platform.Characteristic.TargetHeaterCoolerState.HEAT:
664
- if (this.status[commands_1.default.mode.code] !== commands_1.default.mode.value.heat) {
855
+ if (this.mode !== commands_1.default.mode.value.heat) {
665
856
  command[commands_1.default.mode.code] = commands_1.default.mode.value.heat;
666
- 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
+ }
667
863
  }
668
864
  break;
669
865
  case this.platform.Characteristic.TargetHeaterCoolerState.AUTO:
670
- if (this.status[commands_1.default.mode.code] !== commands_1.default.mode.value.auto) {
866
+ if (this.mode !== commands_1.default.mode.value.auto) {
671
867
  command[commands_1.default.mode.code] = commands_1.default.mode.value.auto;
672
- 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
+ }
673
874
  }
674
875
  break;
675
876
  }
676
877
  if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
677
- settings_1.OVERRIDE_DEFAULT_SWING.never) && this.swingMode !== undefined) {
678
- 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;
679
880
  command[commands_1.default.swingVertical.code] = value;
680
- 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
+ }
681
1019
  }
682
1020
  }
683
1021
  this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
684
1022
  this.sendCommand(command);
685
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
+ }
686
1062
  get mode() {
687
1063
  return this.status[commands_1.default.mode.code] || commands_1.default.mode.value.auto;
688
1064
  }
689
1065
  set mode(value) {
690
- 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})`);
691
1069
  return;
692
1070
  }
693
1071
  let logValue = 'mode -> ' + this.getKeyName(commands_1.default.mode.value, value);
694
1072
  const command = { [commands_1.default.mode.code]: value };
695
1073
  if (this.deviceConfig.xFanEnabled && (this.status[commands_1.default.xFan.code] || commands_1.default.xFan.value.off) !== commands_1.default.xFan.value.on &&
696
- (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)) {
697
1075
  // turn on xFan in Cool and Dry mode if xFan is enabled for this device
698
1076
  logValue += ', xFan -> ' + this.getKeyName(commands_1.default.xFan.value, commands_1.default.xFan.value.on);
699
1077
  command[commands_1.default.xFan.code] = commands_1.default.xFan.value.on;
700
1078
  }
701
- if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
702
- settings_1.OVERRIDE_DEFAULT_SWING.never) && this.swingMode !== undefined) {
703
- const value = (this.swingMode === commands_1.default.swingVertical.value.default) ? this.deviceConfig.defaultVerticalSwing : this.swingMode;
704
- command[commands_1.default.swingVertical.code] = value;
705
- 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
+ }
706
1202
  }
707
1203
  this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
708
1204
  this.sendCommand(command);
@@ -714,7 +1210,7 @@ class GreeAirConditioner {
714
1210
  var _a, _b, _c, _d, _e, _f, _g, _h;
715
1211
  let minValue = this.deviceConfig.minimumTargetTemperature;
716
1212
  let maxValue = this.deviceConfig.maximumTargetTemperature;
717
- switch (this.status[commands_1.default.mode.code]) {
1213
+ switch (this.mode) {
718
1214
  case commands_1.default.mode.value.cool:
719
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);
720
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);
@@ -732,6 +1228,7 @@ class GreeAirConditioner {
732
1228
  set targetTemperature(value) {
733
1229
  var _a;
734
1230
  if (value === this.targetTemperature) {
1231
+ this.platform.log.debug(`[${this.getDeviceLabel()}] targetTemperature -> no change (${value})`);
735
1232
  return;
736
1233
  }
737
1234
  const tempValue = this.calcDeviceTargetTemp(value);
@@ -761,6 +1258,7 @@ class GreeAirConditioner {
761
1258
  }
762
1259
  set units(value) {
763
1260
  if (value === this.units) {
1261
+ this.platform.log.debug(`[${this.getDeviceLabel()}] units -> no change (${value})`);
764
1262
  return;
765
1263
  }
766
1264
  const command = { [commands_1.default.units.code]: value };
@@ -785,6 +1283,7 @@ class GreeAirConditioner {
785
1283
  }
786
1284
  set swingMode(value) {
787
1285
  if (value === this.swingMode) {
1286
+ this.platform.log.debug(`[${this.getDeviceLabel()}] swingMode -> no change (${value})`);
788
1287
  return;
789
1288
  }
790
1289
  const command = { [commands_1.default.swingVertical.code]: value };
@@ -795,7 +1294,8 @@ class GreeAirConditioner {
795
1294
  return this.status[commands_1.default.speed.code] || commands_1.default.speed.value.auto;
796
1295
  }
797
1296
  set speed(value) {
798
- 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})`);
799
1299
  return;
800
1300
  }
801
1301
  const command = { [commands_1.default.speed.code]: value };
@@ -810,54 +1310,78 @@ class GreeAirConditioner {
810
1310
  return this.status[commands_1.default.quietMode.code] || commands_1.default.quietMode.value.off;
811
1311
  }
812
1312
  set quietMode(value) {
813
- 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})`);
814
1316
  return;
815
1317
  }
816
- const command = { [commands_1.default.quietMode.code]: value };
817
- 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
+ }
818
1331
  if (value === commands_1.default.quietMode.value.on) {
819
1332
  command[commands_1.default.powerfulMode.code] = commands_1.default.powerfulMode.value.off;
820
1333
  logValue += ', powerfulMode -> ' + this.getKeyName(commands_1.default.powerfulMode.value, commands_1.default.powerfulMode.value.off);
821
1334
  command[commands_1.default.speed.code] = commands_1.default.speed.value.low;
822
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);
823
1338
  }
824
- else {
825
- command[commands_1.default.speed.code] = commands_1.default.speed.value.auto;
826
- logValue += ', speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
827
- }
828
- this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
829
- this.sendCommand(command);
830
1339
  }
831
1340
  get powerfulMode() {
832
1341
  return this.status[commands_1.default.powerfulMode.code] || commands_1.default.powerfulMode.value.off;
833
1342
  }
834
1343
  set powerfulMode(value) {
835
- 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})`);
836
1347
  return;
837
1348
  }
838
- let logValue = 'powerfulMode -> ' + this.getKeyName(commands_1.default.powerfulMode.value, value);
839
- 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
+ }
840
1362
  if (value === commands_1.default.powerfulMode.value.on) {
841
1363
  command[commands_1.default.quietMode.code] = commands_1.default.quietMode.value.off;
842
1364
  logValue += ', quietMode -> ' + this.getKeyName(commands_1.default.quietMode.value, commands_1.default.quietMode.value.off);
843
1365
  command[commands_1.default.speed.code] = commands_1.default.speed.value.high;
844
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);
845
1369
  }
846
- else {
847
- command[commands_1.default.speed.code] = commands_1.default.speed.value.auto;
848
- logValue += ', speed -> ' + this.getKeyName(commands_1.default.speed.value, commands_1.default.speed.value.auto);
849
- }
850
- this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
851
- this.sendCommand(command);
852
1370
  }
853
1371
  updateStatus(props) {
854
- 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;
855
1373
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus -> %j`, props);
856
- // Active
857
- if (props.includes(commands_1.default.power.code)) {
858
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Active) ->`, this.power ? 'ACTIVE' : 'INACTIVE');
859
- (_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.power ?
860
- 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);
861
1385
  }
862
1386
  // Current Heater-Cooler State
863
1387
  if (props.includes(commands_1.default.mode.code)) {
@@ -865,16 +1389,11 @@ class GreeAirConditioner {
865
1389
  switch (this.mode) {
866
1390
  case commands_1.default.mode.value.cool:
867
1391
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Heater-Cooler State) -> COOLING`);
868
- (_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);
869
1393
  break;
870
1394
  case commands_1.default.mode.value.heat:
871
1395
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Heater-Cooler State) -> HEATING`);
872
- (_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.HEATING);
873
- break;
874
- case commands_1.default.mode.value.fan:
875
- case commands_1.default.mode.value.dry:
876
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Heater-Cooler State) -> IDLE`);
877
- (_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);
878
1397
  break;
879
1398
  case commands_1.default.mode.value.auto:
880
1399
  if (this.currentTemperature > this.targetTemperature + 1.5) {
@@ -897,57 +1416,79 @@ class GreeAirConditioner {
897
1416
  (_h = this.HeaterCooler) === null || _h === void 0 ? void 0 : _h.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).updateValue(this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE);
898
1417
  }
899
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
+ }
900
1430
  // Target Heater-Cooler State
901
- 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)) {
902
1433
  switch (this.mode) {
903
1434
  case commands_1.default.mode.value.cool:
904
1435
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Target Heater-Cooler State) -> COOL`);
905
- (_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;
906
1438
  break;
907
1439
  case commands_1.default.mode.value.heat:
908
1440
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Target Heater-Cooler State) -> HEAT`);
909
- (_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;
910
1443
  break;
911
- default:
1444
+ case commands_1.default.mode.value.auto:
912
1445
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Target Heater-Cooler State) -> AUTO`);
913
- (_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;
914
1449
  }
1450
+ this.platform.api.updatePlatformAccessories([this.accessory]);
915
1451
  }
916
1452
  // Current Temperature
917
1453
  if (props.includes(commands_1.default.temperature.code)) {
918
1454
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Temperature) ->`, this.currentTemperature);
919
- (_m = this.HeaterCooler) === null || _m === void 0 ? void 0 : _m.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
920
- (_o = this.TemperatureSensor) === null || _o === void 0 ? void 0 : _o.getCharacteristic(this.platform.Characteristic.CurrentTemperature).updateValue(this.currentTemperature);
921
- (_p = this.tsAccessory) === null || _p === void 0 ? void 0 : _p.setCurrentTemperature(this.currentTemperature);
922
- (_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);
923
1459
  }
924
1460
  else if (props.includes(commands_1.default.targetTemperature.code) && this.TemperatureSensor === undefined) {
925
1461
  // temperature is not accessible -> targetTemperature is saved as currentTemperature
926
1462
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Current Temperature) ->`, this.currentTemperature);
927
- (_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);
928
1464
  }
929
1465
  // Cooling Threshold Temperature
930
1466
  if (props.includes(commands_1.default.targetTemperature.code) && this.power &&
931
1467
  (this.mode === commands_1.default.mode.value.cool || this.mode === commands_1.default.mode.value.auto)) {
932
1468
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Cooling Threshold Temperature) ->`, this.targetTemperature);
933
- (_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);
934
1470
  }
935
1471
  // Heating Threshold Temperature
936
1472
  if (props.includes(commands_1.default.targetTemperature.code) && this.power &&
937
1473
  (this.mode === commands_1.default.mode.value.heat || this.mode === commands_1.default.mode.value.auto)) {
938
1474
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Heating Threshold Temperature) ->`, this.targetTemperature);
939
- (_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);
940
1476
  }
941
1477
  // Temperature Display Units
942
1478
  if (props.includes(commands_1.default.units.code)) {
943
1479
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Temperature Display Units) ->`, this.units === commands_1.default.units.value.celsius ? 'CELSIUS' : 'FAHRENHEIT');
944
- (_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 ?
945
1481
  this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS : this.platform.Characteristic.TemperatureDisplayUnits.FAHRENHEIT);
946
1482
  }
947
1483
  // Swing Mode
948
1484
  if (props.includes(commands_1.default.swingVertical.code) && this.power) {
949
1485
  let swing = this.platform.Characteristic.SwingMode.SWING_ENABLED;
950
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
+ }
951
1492
  switch (this.swingMode) {
952
1493
  case commands_1.default.swingVertical.value.default:
953
1494
  case commands_1.default.swingVertical.value.fixedHighest:
@@ -956,58 +1497,79 @@ class GreeAirConditioner {
956
1497
  case commands_1.default.swingVertical.value.fixedLower:
957
1498
  case commands_1.default.swingVertical.value.fixedLowest:
958
1499
  swing = this.platform.Characteristic.SwingMode.SWING_DISABLED;
959
- logValue = 'DISABLED';
960
- if ([settings_1.OVERRIDE_DEFAULT_SWING.always, settings_1.OVERRIDE_DEFAULT_SWING.powerOn].includes(this.deviceConfig.overrideDefaultVerticalSwing ||
961
- settings_1.OVERRIDE_DEFAULT_SWING.never)) {
962
- logValue += ' (' + this.getKeyName(commands_1.default.swingVertical.value, this.swingMode) + ')';
963
- }
1500
+ logValue = `DISABLED (position: ${this.getKeyName(commands_1.default.swingVertical.value, this.swingMode)})`;
964
1501
  break;
965
1502
  }
966
1503
  this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Swing Mode) ->`, logValue);
967
- (_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);
968
1505
  }
969
- // Rotation Speed
970
- if (this.power) {
971
- 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;
972
1510
  if (props.includes(commands_1.default.quietMode.code) && this.quietMode === commands_1.default.quietMode.value.on) {
973
1511
  // quietMode -> on
974
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Rotation Speed) -> 1 (quiet)`);
975
- (_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;
976
1515
  }
977
1516
  else if (props.includes(commands_1.default.powerfulMode.code) && this.powerfulMode === commands_1.default.powerfulMode.value.on) {
978
1517
  // powerfulMode -> on
979
- logValue = `${this.deviceConfig.speedSteps + 3} (powerful)`;
980
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Rotation Speed) ->`, logValue);
981
- (_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;
982
1521
  }
983
1522
  else if (props.includes(commands_1.default.speed.code)) {
984
- // speed
985
1523
  let speedValue = 2; // default: auto
986
1524
  switch (this.speed) {
987
1525
  case commands_1.default.speed.value.low:
988
- logValue = '3 (low)';
989
1526
  speedValue = 3;
990
1527
  break;
991
1528
  case commands_1.default.speed.value.mediumLow:
992
- logValue = '4 (mediumLow)';
993
1529
  speedValue = 4;
994
1530
  break;
995
1531
  case commands_1.default.speed.value.medium:
996
- logValue = ((this.deviceConfig.speedSteps === 5) ? '5' : '4') + ' (medium)';
997
- speedValue = (this.deviceConfig.speedSteps === 5) ? 5 : 4;
1532
+ speedValue = (maxSpeed === 8) ? 5 : 4;
998
1533
  break;
999
1534
  case commands_1.default.speed.value.mediumHigh:
1000
- logValue = ((this.deviceConfig.speedSteps === 5) ? '6' : '4') + ' (mediumHigh)';
1001
- speedValue = (this.deviceConfig.speedSteps === 5) ? 6 : 4;
1535
+ speedValue = (maxSpeed === 8) ? 6 : 4;
1002
1536
  break;
1003
1537
  case commands_1.default.speed.value.high:
1004
- logValue = ((this.deviceConfig.speedSteps === 5) ? '7' : '5') + ' (high)';
1005
- speedValue = (this.deviceConfig.speedSteps === 5) ? 7 : 5;
1538
+ speedValue = (maxSpeed === 8) ? 7 : 5;
1006
1539
  break;
1007
1540
  }
1008
- this.platform.log.debug(`[${this.getDeviceLabel()}] updateStatus (Rotation Speed) ->`, logValue);
1009
- (_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;
1010
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);
1011
1573
  }
1012
1574
  }
1013
1575
  sendMessage(message) {
@@ -1070,6 +1632,12 @@ class GreeAirConditioner {
1070
1632
  opt: keys,
1071
1633
  p: values,
1072
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
+ }
1073
1641
  this.sendMessage(message);
1074
1642
  }
1075
1643
  requestDeviceStatus() {