Skip to content

Commit

Permalink
fix: Target-temperature mis-represented with a configured temperature…
Browse files Browse the repository at this point in the history
…-factor and hot cache.

When a device was configured with a target temperature-factor other then 1, the target temperature would be mis-represented if you set a target temperature, force-close the home-app and re-open the home app.
The target temperature-factor would wrongly be applied to the previously configured temperature again.

The device cache should at all times represent the data that the tuya API could return, this commit makes the target temperature follow this priciniple.
  • Loading branch information
milo526 committed Jan 1, 2021
1 parent a4ac885 commit c50ed51
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/accessories/characteristics/targetTemperature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ export class TargetTemperatureCharacteristic extends TuyaWebCharacteristic {
const temperature = Number(homekitValue);

this.accessory
.setDeviceState("temperatureSet", { value: temperature }, { temperature })
.setDeviceState(
"temperatureSet",
{ value: temperature },
{
temperature:
temperature /
(this.accessory as ClimateAccessory).targetTemperatureFactor,
}
)
.then(() => {
this.debug("[SET] %s %s", homekitValue, temperature);
callback();
Expand All @@ -86,11 +94,13 @@ export class TargetTemperatureCharacteristic extends TuyaWebCharacteristic {
}

updateValue(data: DeviceState, callback?: CharacteristicGetCallback): void {
const temperature = data?.temperature
let temperature = data?.temperature
? Number(data?.temperature) *
(this.accessory as ClimateAccessory).targetTemperatureFactor
: undefined;
if (temperature) {
temperature = Math.round(temperature * 10) / 10;

this.debug("[UPDATE] %s", temperature);
this.accessory.setCharacteristic(
this.homekitCharacteristic,
Expand Down

0 comments on commit c50ed51

Please sign in to comment.