homebridge-gree-ac 2.1.4 → 2.1.6

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.
@@ -63,16 +63,23 @@ class GreeAirConditioner {
63
63
  break;
64
64
  case 'dat': // package type is device status
65
65
  if (this.accessory.bound) {
66
+ let invalidTempFromDevice = false;
66
67
  pack.cols.forEach((col, i) => {
67
- if (!(col === commands_1.default.temperature.code && i === 0)) { // temperature value 0 should be ignored (means: no sensor data)
68
+ if (col === commands_1.default.temperature.code && (pack.dat[i] <= 0 || pack.dat[i] >= 100)) {
69
+ // temperature value outside of valid range (1-99 -> -39°C - +59°C) should be ignored (means: no sensor data)
70
+ invalidTempFromDevice = true;
71
+ }
72
+ else {
68
73
  this.status[col] = pack.dat[i];
69
74
  }
70
75
  });
71
76
  this.platform.log.debug(`[${this.getDeviceLabel()}] Device status -> %j`, this.status);
72
- if (!pack.cols.includes(commands_1.default.temperature.code) &&
73
- pack.cols.includes(commands_1.default.targetTemperature.code)) {
77
+ if (!pack.cols.includes(commands_1.default.temperature.code) || invalidTempFromDevice) {
74
78
  // temperature is not accessible -> use targetTemperature
75
- this.status[commands_1.default.temperature.code] = this.status[commands_1.default.targetTemperature.code] + this.deviceConfig.sensorOffset;
79
+ const targetTemp = this.status[commands_1.default.targetTemperature.code] !== undefined ?
80
+ this.status[commands_1.default.targetTemperature.code] : 25; // use default if target temperature is also unknown
81
+ this.status[commands_1.default.temperature.code] = targetTemp + this.deviceConfig.sensorOffset;
82
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Current temperature not available`, '- Threshold temperature is used as current (' + commands_1.default.targetTemperature.code + '->' + commands_1.default.temperature.code + ')');
76
83
  if (this.TemperatureSensor !== undefined) {
77
84
  this.accessory.removeService(this.TemperatureSensor);
78
85
  this.TemperatureSensor = undefined;
@@ -133,34 +140,79 @@ class GreeAirConditioner {
133
140
  setTimeout(this.checkBindingStatus.bind(this, 1), settings_1.BINDING_TIMEOUT);
134
141
  });
135
142
  }
143
+ initCharacteristics() {
144
+ // these characteristic properties are not updated by HomeKit, they are initialized only once
145
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
146
+ // Cooling Threshold Temperature Characteristic
147
+ // minValue / maxValue usually generates error messages in debug log:
148
+ // "Characteristic 'Cooling Threshold Temperature': characteristic was supplied illegal value ..."
149
+ // this is not a problem, this is information only that GREE is more restricitive than Apple's default
150
+ (_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).setProps({
151
+ minStep: this.deviceConfig.temperatureStepSize,
152
+ minValue: Math.max(this.deviceConfig.minimumTargetTemperature, settings_1.TEMPERATURE_LIMITS.coolingMinimum),
153
+ maxValue: Math.min(this.deviceConfig.maximumTargetTemperature, settings_1.TEMPERATURE_LIMITS.coolingMaximum),
154
+ });
155
+ this.platform.log.debug(`[${this.getDeviceLabel()}] CoolingThresholdTemperature - minValue: %s, maxValue: %s, minStep: %s`, (_c = (_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.minValue) === null || _c === void 0 ? void 0 : _c.toString(), (_e = (_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.maxValue) === null || _e === void 0 ? void 0 : _e.toString(), (_g = (_f = this.HeaterCooler) === null || _f === void 0 ? void 0 : _f.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.minStep) === null || _g === void 0 ? void 0 : _g.toString());
156
+ // Heating Threshold Temperature Characteristic
157
+ // minValue / maxValue usually generates error messages in debug log:
158
+ // "Characteristic 'Heating Threshold Temperature': characteristic was supplied illegal value ..."
159
+ // this is not a problem, this is information only that GREE is more restricitive than Apple's default
160
+ (_h = this.HeaterCooler) === null || _h === void 0 ? void 0 : _h.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).setProps({
161
+ minStep: this.deviceConfig.temperatureStepSize,
162
+ minValue: Math.max(this.deviceConfig.minimumTargetTemperature, settings_1.TEMPERATURE_LIMITS.heatingMinimum),
163
+ maxValue: Math.min(this.deviceConfig.maximumTargetTemperature, settings_1.TEMPERATURE_LIMITS.heatingMaximum),
164
+ });
165
+ this.platform.log.debug(`[${this.getDeviceLabel()}] HeatingThresholdTemperature - minValue: %s, maxValue: %s, minStep: %s`, (_k = (_j = this.HeaterCooler) === null || _j === void 0 ? void 0 : _j.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.minValue) === null || _k === void 0 ? void 0 : _k.toString(), (_m = (_l = this.HeaterCooler) === null || _l === void 0 ? void 0 : _l.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.maxValue) === null || _m === void 0 ? void 0 : _m.toString(), (_p = (_o = this.HeaterCooler) === null || _o === void 0 ? void 0 : _o.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.minStep) === null || _p === void 0 ? void 0 : _p.toString());
166
+ // Rotation Speed Characteristic
167
+ (_q = this.HeaterCooler) === null || _q === void 0 ? void 0 : _q.getCharacteristic(this.platform.Characteristic.RotationSpeed).setProps({
168
+ minValue: 0,
169
+ maxValue: this.deviceConfig.speedSteps + 3,
170
+ minStep: 1
171
+ });
172
+ this.platform.log.debug(`[${this.getDeviceLabel()}] RotationSpeed - minValue: %s, maxValue: %s, minStep: %s`, (_s = (_r = this.HeaterCooler) === null || _r === void 0 ? void 0 : _r.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minValue) === null || _s === void 0 ? void 0 : _s.toString(), (_u = (_t = this.HeaterCooler) === null || _t === void 0 ? void 0 : _t.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.maxValue) === null || _u === void 0 ? void 0 : _u.toString(), (_w = (_v = this.HeaterCooler) === null || _v === void 0 ? void 0 : _v.getCharacteristic(this.platform.Characteristic.RotationSpeed).props.minStep) === null || _w === void 0 ? void 0 : _w.toString());
173
+ }
136
174
  // All platform, accessory and service initialization is made in initAccessory function
137
175
  initAccessory() {
138
176
  var _a, _b, _c;
139
177
  // register accessory in homebridge by api if not registered before
140
178
  if (!this.accessory.registered) {
141
- this.platform.log.debug(`[${this.getDeviceLabel()}] registering new accessory in homebridge:`, this.accessory.context.device.mac, this.accessory.UUID);
179
+ this.platform.log.debug(`[${this.getDeviceLabel()}] Registering new accessory in homebridge:`, this.accessory.context.device.mac, this.accessory.UUID);
142
180
  this.platform.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [this.accessory]);
181
+ // set static accessory information
182
+ this.accessory.getService(this.platform.Service.AccessoryInformation)
183
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, this.accessory.context.device.brand || 'Gree')
184
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, this.accessory.context.device.mac)
185
+ .setCharacteristic(this.platform.Characteristic.Model, ((_a = this.deviceConfig) === null || _a === void 0 ? void 0 : _a.model) || this.accessory.context.device.model || this.accessory.context.device.name || 'Air Conditioner')
186
+ .setCharacteristic(this.platform.Characteristic.HardwareRevision, this.accessory.context.device.ver ?
187
+ this.accessory.context.device.ver.substring(this.accessory.context.device.ver.lastIndexOf('V') + 1) : '1.0.0')
188
+ .setCharacteristic(this.platform.Characteristic.Name, this.accessory.displayName);
189
+ // get the HeaterCooler service if it exists, otherwise create a new HeaterCooler service
190
+ // we don't use subtype because we add only one service with this type
191
+ this.HeaterCooler = this.accessory.getService(this.platform.Service.HeaterCooler) ||
192
+ this.accessory.addService(this.platform.Service.HeaterCooler, this.accessory.displayName, undefined);
193
+ // set static characeristics
194
+ this.initCharacteristics();
143
195
  }
144
- this.platform.api.updatePlatformAccessories([this.accessory]);
145
196
  if (this.tsAccessoryMac) {
146
197
  this.tsAccessory = new tsAccessory_1.GreeAirConditionerTS(this.platform, this.platform.getAccessory(this.accessory.context.device.mac + '_ts'));
147
198
  }
148
199
  // set accessory information
149
200
  this.accessory.getService(this.platform.Service.AccessoryInformation)
150
- .setCharacteristic(this.platform.Characteristic.Manufacturer, this.accessory.context.device.brand || 'Gree')
151
- .setCharacteristic(this.platform.Characteristic.Model, ((_a = this.deviceConfig) === null || _a === void 0 ? void 0 : _a.model) || this.accessory.context.device.model || this.accessory.context.device.name || 'Air Conditioner')
152
- .setCharacteristic(this.platform.Characteristic.SerialNumber, this.accessory.context.device.mac)
153
201
  .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.accessory.context.device.hid && this.accessory.context.device.hid.lastIndexOf('V') >= 0 &&
154
202
  this.accessory.context.device.hid.lastIndexOf('V') < this.accessory.context.device.hid.lastIndexOf('.') ?
155
- this.accessory.context.device.hid.substring(this.accessory.context.device.hid.lastIndexOf('V') + 1, this.accessory.context.device.hid.lastIndexOf('.')) : '1.0.0')
156
- .setCharacteristic(this.platform.Characteristic.HardwareRevision, this.accessory.context.device.ver ?
157
- this.accessory.context.device.ver.substring(this.accessory.context.device.ver.lastIndexOf('V') + 1) : '1.0.0')
158
- .setCharacteristic(this.platform.Characteristic.Name, this.accessory.displayName);
203
+ this.accessory.context.device.hid.substring(this.accessory.context.device.hid.lastIndexOf('V') + 1, this.accessory.context.device.hid.lastIndexOf('.')) : '1.0.0');
159
204
  // get the HeaterCooler service if it exists, otherwise create a new HeaterCooler service
160
205
  // we don't use subtype because we add only one service with this type
161
- this.HeaterCooler = this.accessory.getService(this.platform.Service.HeaterCooler) ||
162
- this.accessory.addService(this.platform.Service.HeaterCooler, this.accessory.displayName, undefined);
163
- this.HeaterCooler.displayName = this.accessory.displayName;
206
+ if (!this.HeaterCooler) {
207
+ this.HeaterCooler = this.accessory.getService(this.platform.Service.HeaterCooler);
208
+ if (!this.HeaterCooler) {
209
+ 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);
211
+ // set static characeristics
212
+ this.initCharacteristics();
213
+ }
214
+ }
215
+ // TemperatureSensor service
164
216
  if (this.deviceConfig.temperatureSensor === settings_1.TS_TYPE.child) {
165
217
  this.platform.log.debug(`[${this.getDeviceLabel()}] Add Temperature Sensor child service`);
166
218
  this.TemperatureSensor = this.accessory.getService(this.platform.Service.TemperatureSensor) ||
@@ -177,6 +229,7 @@ class GreeAirConditioner {
177
229
  }
178
230
  this.HeaterCooler.setPrimaryService(true);
179
231
  (_b = this.TemperatureSensor) === null || _b === void 0 ? void 0 : _b.setPrimaryService(false);
232
+ this.platform.api.updatePlatformAccessories([this.accessory]);
180
233
  // each service must implement at-minimum the "required characteristics" for the given service type
181
234
  // see https://developers.homebridge.io/#/service/HeaterCooler
182
235
  // register handlers for the Active Characteristic
@@ -195,15 +248,11 @@ class GreeAirConditioner {
195
248
  .onGet(this.getCurrentTemperature.bind(this, 'Heater Cooler'));
196
249
  (_c = this.TemperatureSensor) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.getCurrentTemperature.bind(this, 'Temperature Sensor'));
197
250
  // register handlers for the Cooling Threshold Temperature Characteristic
198
- // (minValue and maxValue can't be set here, they need an active accessory in cooling sate to set)
199
251
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
200
- .setProps({ minStep: 0.5 })
201
252
  .onGet(this.getTargetTemperature.bind(this, 'CoolingThresholdTemperature'))
202
253
  .onSet(this.setTargetTemperature.bind(this));
203
254
  // register handlers for the Heating Threshold Temperature Characteristic
204
- // (minValue and maxValue can't be set here, they need an active accessory in heating sate to set)
205
255
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
206
- .setProps({ minStep: 0.5 })
207
256
  .onGet(this.getTargetTemperature.bind(this, 'HeatingThresholdTemperature'))
208
257
  .onSet(this.setTargetTemperature.bind(this));
209
258
  // register handlers for the Temperature Display Units Characteristic
@@ -216,11 +265,6 @@ class GreeAirConditioner {
216
265
  .onSet(this.setSwingMode.bind(this));
217
266
  // register handlers for the Rotation Speed Characteristic
218
267
  this.HeaterCooler.getCharacteristic(this.platform.Characteristic.RotationSpeed)
219
- .setProps({
220
- minValue: 0,
221
- maxValue: this.deviceConfig.speedSteps + 3,
222
- minStep: 1
223
- })
224
268
  .onGet(this.getRotationSpeed.bind(this))
225
269
  .onSet(this.setRotationSpeed.bind(this));
226
270
  }
@@ -371,11 +415,9 @@ class GreeAirConditioner {
371
415
  switch (this.mode) {
372
416
  case commands_1.default.mode.value.cool:
373
417
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> COOLING`);
374
- setTimeout(() => this.initThresholdTemperature(this.platform.Characteristic.CurrentHeaterCoolerState.COOLING), settings_1.INIT_TEMP_TRESHOLD_TIMEOUT);
375
418
  return this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
376
419
  case commands_1.default.mode.value.heat:
377
420
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> HEATING`);
378
- setTimeout(() => this.initThresholdTemperature(this.platform.Characteristic.CurrentHeaterCoolerState.HEATING), settings_1.INIT_TEMP_TRESHOLD_TIMEOUT);
379
421
  return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
380
422
  case commands_1.default.mode.value.fan:
381
423
  case commands_1.default.mode.value.dry:
@@ -384,12 +426,10 @@ class GreeAirConditioner {
384
426
  case commands_1.default.mode.value.auto:
385
427
  if (this.currentTemperature > this.status[commands_1.default.targetTemperature.code]) {
386
428
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> COOLING`);
387
- setTimeout(() => this.initThresholdTemperature(this.platform.Characteristic.CurrentHeaterCoolerState.COOLING), settings_1.INIT_TEMP_TRESHOLD_TIMEOUT);
388
429
  return this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
389
430
  }
390
431
  if (this.currentTemperature < this.status[commands_1.default.targetTemperature.code]) {
391
432
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> HEATING`);
392
- setTimeout(() => this.initThresholdTemperature(this.platform.Characteristic.CurrentHeaterCoolerState.HEATING), settings_1.INIT_TEMP_TRESHOLD_TIMEOUT);
393
433
  return this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
394
434
  }
395
435
  this.platform.log.debug(`[${this.getDeviceLabel()}] Get CurrentHeaterCoolerState -> IDLE`);
@@ -478,36 +518,6 @@ class GreeAirConditioner {
478
518
  return value;
479
519
  }
480
520
  // helper functions
481
- initThresholdTemperature(HeaterCoolerState) {
482
- var _a, _b, _c, _d, _e, _f;
483
- switch (HeaterCoolerState) {
484
- case this.platform.Characteristic.CurrentHeaterCoolerState.COOLING:
485
- if (((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.minValue) !==
486
- this.deviceConfig.minimumTargetTemperature ||
487
- ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.maxValue) !==
488
- this.deviceConfig.maximumTargetTemperature) {
489
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set CoolingThresholdTemperature minValue -> %i, maxValue -> %i`, this.deviceConfig.minimumTargetTemperature, this.deviceConfig.maximumTargetTemperature);
490
- (_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).setProps({
491
- minValue: this.deviceConfig.minimumTargetTemperature,
492
- maxValue: this.deviceConfig.maximumTargetTemperature
493
- });
494
- }
495
- break;
496
- case this.platform.Characteristic.CurrentHeaterCoolerState.HEATING:
497
- if (((_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.minValue) !==
498
- this.deviceConfig.minimumTargetTemperature ||
499
- ((_e = this.HeaterCooler) === null || _e === void 0 ? void 0 : _e.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.maxValue) !==
500
- this.deviceConfig.maximumTargetTemperature) {
501
- this.platform.log.debug(`[${this.getDeviceLabel()}] Set HeatingThresholdTemperature minValue -> %i, maxValue -> %i`, this.deviceConfig.minimumTargetTemperature, this.deviceConfig.maximumTargetTemperature);
502
- (_f = this.HeaterCooler) === null || _f === void 0 ? void 0 : _f.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).setProps({
503
- minValue: this.deviceConfig.minimumTargetTemperature,
504
- maxValue: this.deviceConfig.maximumTargetTemperature
505
- });
506
- }
507
- break;
508
- }
509
- this.platform.api.updatePlatformAccessories([this.accessory]);
510
- }
511
521
  getDeviceLabel() {
512
522
  return `${this.accessory.displayName} -- ${this.accessory.context.device.address}:${this.accessory.context.device.port}`;
513
523
  }
@@ -542,7 +552,17 @@ class GreeAirConditioner {
542
552
  }
543
553
  return name;
544
554
  }
545
- calcDeviceTargetTemp(temp) {
555
+ calcDeviceTargetTemp(temp, unit) {
556
+ var _a;
557
+ if (unit === commands_1.default.units.value.celsius ||
558
+ (unit === undefined && ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits).value) ===
559
+ this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS)) {
560
+ return Math.floor(temp);
561
+ }
562
+ if (temp >= 15.25 && temp < 15.75) {
563
+ // execption
564
+ return 15;
565
+ }
546
566
  const baseTemp = Math.round(temp);
547
567
  const baseFahrenheit = temp * 9 / 5 + 32;
548
568
  const baseFahrenheitDecimalPart = baseFahrenheit - Math.floor(baseFahrenheit);
@@ -550,31 +570,58 @@ class GreeAirConditioner {
550
570
  (baseFahrenheitDecimalPart >= 0.25 && baseFahrenheitDecimalPart < 0.35) ? 1 : 0;
551
571
  return baseTemp - correction;
552
572
  }
553
- calcDeviceTargetOffset(temp) {
573
+ calcDeviceTargetOffset(temp, unit) {
574
+ var _a;
575
+ if (unit === commands_1.default.units.value.celsius ||
576
+ (unit === undefined && ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits).value) ===
577
+ this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS)) {
578
+ return 0;
579
+ }
554
580
  if (temp === 16) {
581
+ // exception
555
582
  return 0;
556
583
  }
557
584
  const baseFahrenheit = temp * 9 / 5 + 32;
558
585
  const baseFahrenheitDecimalPart = baseFahrenheit - Math.floor(baseFahrenheit);
559
- return (((baseFahrenheitDecimalPart >= 0.05 && baseFahrenheitDecimalPart < 0.15) ||
586
+ const offset = (((baseFahrenheitDecimalPart >= 0.05 && baseFahrenheitDecimalPart < 0.15) ||
560
587
  (baseFahrenheitDecimalPart >= 0.25 && baseFahrenheitDecimalPart < 0.35) ||
561
588
  (baseFahrenheitDecimalPart >= 0.55 && baseFahrenheitDecimalPart < 0.65) ||
562
589
  (baseFahrenheitDecimalPart >= 0.75 && baseFahrenheitDecimalPart < 0.85)) ? 1 : 0);
590
+ return temp >= 15.25 && temp < 16.25 ? 1 - offset : offset;
563
591
  }
564
- getTargetTempFromDevice(temp, offset) {
592
+ getTargetTempFromDevice(temp, offset, unit) {
565
593
  var _a, _b;
594
+ let targetValue;
595
+ const heatingTargetValue = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).value) || 25;
596
+ const coolingTargetValue = ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).value) || 25;
597
+ switch (this.status[commands_1.default.mode.code]) {
598
+ case commands_1.default.mode.value.heat:
599
+ targetValue = heatingTargetValue;
600
+ break;
601
+ case commands_1.default.mode.value.cool:
602
+ targetValue = coolingTargetValue;
603
+ break;
604
+ default:
605
+ targetValue = (coolingTargetValue + heatingTargetValue) / 2;
606
+ break;
607
+ }
608
+ if (unit === commands_1.default.units.value.celsius) {
609
+ if (Math.floor(targetValue) === +temp && targetValue !== +temp) {
610
+ this.platform.log.debug(`[${this.getDeviceLabel()}] TargetTemperature FIX: %f -> %f`, +temp, targetValue);
611
+ return targetValue;
612
+ }
613
+ return +temp;
614
+ }
566
615
  const key = temp.toString() + ',' + offset.toString();
567
616
  const value = settings_1.TEMPERATURE_TABLE[key];
568
617
  if (value === undefined) {
569
- return 25; // default value if invalid data received from device
618
+ this.platform.log.debug(`[${this.getDeviceLabel()}] TargetTemperature FIX: invalid -> %f`, +temp);
619
+ return +temp; // invalid temperature-offset pair received from device -> return temperature value
570
620
  }
571
621
  // some temperature values are the same on the physical AC unit -> fix this issue:
572
- const targetValue = ((_a = this.HeaterCooler) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).value) ||
573
- ((_b = this.HeaterCooler) === null || _b === void 0 ? void 0 : _b.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).value);
574
- if ((targetValue === 17.5 && value === 18) ||
575
- (targetValue === 22.5 && value === 23) ||
576
- (targetValue === 27.5 && value === 28)) {
577
- this.platform.log.debug(`[${this.getDeviceLabel()}] TargetTemperature FIX: %d -> %d`, value, targetValue);
622
+ if ((targetValue === 12.5 && value === 13) || (targetValue === 17.5 && value === 18) ||
623
+ (targetValue === 22.5 && value === 23) || (targetValue === 27.5 && value === 28)) {
624
+ this.platform.log.debug(`[${this.getDeviceLabel()}] TargetTemperature FIX: %f -> %f`, value, targetValue);
578
625
  return targetValue;
579
626
  }
580
627
  // no fix needed, return original value
@@ -656,7 +703,7 @@ class GreeAirConditioner {
656
703
  return this.status[commands_1.default.temperature.code] - (this.deviceConfig.sensorOffset) || 25;
657
704
  }
658
705
  get targetTemperature() {
659
- var _a, _b, _c, _d;
706
+ var _a, _b, _c, _d, _e, _f, _g, _h;
660
707
  let minValue = this.deviceConfig.minimumTargetTemperature;
661
708
  let maxValue = this.deviceConfig.maximumTargetTemperature;
662
709
  switch (this.status[commands_1.default.mode.code]) {
@@ -668,8 +715,11 @@ class GreeAirConditioner {
668
715
  minValue = Math.max(this.deviceConfig.minimumTargetTemperature, ((_c = this.HeaterCooler) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.minValue) || 0);
669
716
  maxValue = Math.min(this.deviceConfig.maximumTargetTemperature, ((_d = this.HeaterCooler) === null || _d === void 0 ? void 0 : _d.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.maxValue) || 25);
670
717
  break;
718
+ case commands_1.default.mode.value.auto:
719
+ minValue = Math.max(this.deviceConfig.minimumTargetTemperature, Math.min(((_e = this.HeaterCooler) === null || _e === void 0 ? void 0 : _e.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.minValue) || 10, ((_f = this.HeaterCooler) === null || _f === void 0 ? void 0 : _f.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.minValue) || 0));
720
+ maxValue = Math.min(this.deviceConfig.maximumTargetTemperature, Math.max(((_g = this.HeaterCooler) === null || _g === void 0 ? void 0 : _g.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature).props.maxValue) || 35, ((_h = this.HeaterCooler) === null || _h === void 0 ? void 0 : _h.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature).props.maxValue) || 25));
671
721
  }
672
- return Math.max(Math.min(this.getTargetTempFromDevice(this.status[commands_1.default.targetTemperature.code] || 25, this.status[commands_1.default.temperatureOffset.code] || 0), (maxValue)), (minValue));
722
+ return Math.max(Math.min(this.getTargetTempFromDevice(this.status[commands_1.default.targetTemperature.code] || 25, this.status[commands_1.default.temperatureOffset.code] || 0, this.status[commands_1.default.units.code]), (maxValue)), (minValue));
673
723
  }
674
724
  set targetTemperature(value) {
675
725
  var _a;
@@ -706,7 +756,20 @@ class GreeAirConditioner {
706
756
  return;
707
757
  }
708
758
  const command = { [commands_1.default.units.code]: value };
709
- this.platform.log.info(`[${this.getDeviceLabel()}] units ->`, this.getKeyName(commands_1.default.units.value, value));
759
+ let logValue = 'units -> ' + this.getKeyName(commands_1.default.units.value, value);
760
+ // convert target temperature to new unit
761
+ const actTemp = this.getTargetTempFromDevice(this.status[commands_1.default.targetTemperature.code], this.status[commands_1.default.temperatureOffset.code], this.units);
762
+ const tempValue = this.calcDeviceTargetTemp(actTemp, value);
763
+ if (tempValue !== this.status[commands_1.default.targetTemperature.code]) {
764
+ command[commands_1.default.targetTemperature.code] = tempValue;
765
+ logValue += ', targetTemperature -> ' + tempValue.toString();
766
+ }
767
+ const tempOffset = this.calcDeviceTargetOffset(actTemp, value);
768
+ if (tempOffset !== this.status[commands_1.default.temperatureOffset.code]) {
769
+ command[commands_1.default.temperatureOffset.code] = tempOffset;
770
+ logValue += ', temperatureOffset -> ' + tempOffset.toString();
771
+ }
772
+ this.platform.log.info(`[${this.getDeviceLabel()}]`, logValue);
710
773
  this.sendCommand(command);
711
774
  }
712
775
  get swingMode() {