Skip to content

Commit

Permalink
fix(climate): heuristic_action rely on temperature step instead of pr…
Browse files Browse the repository at this point in the history
…ecision

related #502
  • Loading branch information
xZetsubou committed Jan 25, 2025
1 parent 91eb3f6 commit 3861f9e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions custom_components/localtuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,27 @@ def hvac_action(self):
and (target_temperature := self._target_temperature) is not None
and (current_temperature := self._current_temperature) is not None
):
target_precision_diff = target_temperature - self._precision
current_precision_diff = current_temperature + self._precision
# This function assumes that action changes based on target step different from current.
target_step = self.target_temperature_step
is_heating = current_temperature < (target_temperature - target_step)
is_cooling = current_temperature > (target_temperature + target_step)

if hvac_mode == HVACMode.HEAT:
if current_temperature < target_precision_diff:
if is_heating:
hvac_action = HVACAction.HEATING
elif current_precision_diff > target_temperature:
elif current_temperature >= target_temperature:
hvac_action = HVACAction.IDLE
elif hvac_mode == HVACMode.COOL:
if current_temperature > target_precision_diff:
if is_cooling:
hvac_action = HVACAction.COOLING
elif current_precision_diff < target_temperature:
elif current_temperature <= target_temperature:
hvac_action = HVACAction.IDLE
elif hvac_mode == HVACMode.HEAT_COOL:
if current_temperature < target_precision_diff:
if is_heating:
hvac_action = HVACAction.HEATING
elif current_precision_diff > target_temperature:
elif is_cooling:
hvac_action = HVACAction.COOLING
elif current_temperature == target_precision_diff:
elif current_temperature == target_temperature:
hvac_action = HVACAction.IDLE
elif hvac_mode == HVACMode.DRY:
hvac_action = HVACAction.DRYING
Expand Down Expand Up @@ -418,7 +420,7 @@ async def async_set_temperature(self, **kwargs):
temperature = kwargs[ATTR_TEMPERATURE]

if self._target_temp_forced_to_celsius:
# Revert temperature to Fahrenheit it was forced to celsius
# Revert Temperature to Fahrenheit it was forced to celsius
temperature = round(c_to_f(temperature))

temperature = round(temperature / self._precision_target)
Expand Down Expand Up @@ -468,10 +470,10 @@ def connection_made(self):
super().connection_made()

match self.dp_value(self._dp_id):
case str() as i if i.lower() in ("on", "off"):
self._state_on = "ON" if i.isupper() else "on"
self._state_off = "OFF" if i.isupper() else "off"
case int() as i if not isinstance(i, bool) and i in (0, 1):
case str() as v if v.lower() in ("on", "off"):
self._state_on = "ON" if v.isupper() else "on"
self._state_off = "OFF" if v.isupper() else "off"
case int() as v if not isinstance(v, bool) and v in (0, 1):
self._state_on = 1
self._state_off = 0

Expand Down

0 comments on commit 3861f9e

Please sign in to comment.