Skip to content

Commit

Permalink
update current_temperature, explicitly convert temps (fixes pytest er…
Browse files Browse the repository at this point in the history
…ror)
  • Loading branch information
mag2352 committed Jun 9, 2024
1 parent b213821 commit 4956942
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async def _send_regulated_temperature(self, force=False):
# regulation can use the device_temp
self.auto_regulation_use_device_temp
# and we have access to the device temp
and (device_temp := self._hass.states.get(under._entity_id).attributes.get("current_temperature")) is not None
and (device_temp := under.underlying_current_temperature) is not None
# and target is not reach (ie we need regulation)
and (
(
Expand Down
11 changes: 8 additions & 3 deletions custom_components/versatile_thermostat/underlyings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import async_call_later
from homeassistant.util.unit_conversion import TemperatureConverter

from .const import UnknownEntity, overrides
from .keep_alive import IntervalCaller
Expand Down Expand Up @@ -704,7 +705,7 @@ def underlying_current_temperature(self) -> float | None:
if not hasattr(self._underlying_climate, "current_temperature"):
return None

return self._underlying_climate.current_temperature
return self._hass.states.get(self._entity_id).attributes.get("current_temperature")

def turn_aux_heat_on(self) -> None:
"""Turn auxiliary heater on."""
Expand All @@ -731,8 +732,12 @@ def cap_sent_value(self, value) -> float:
self._underlying_climate.min_temp is not None
and self._underlying_climate is not None
):
min_val = self._hass.states.get(self._entity_id).attributes.get("min_temp")
max_val = self._hass.states.get(self._entity_id).attributes.get("max_temp")
min_val = TemperatureConverter.convert(
self._underlying_climate.min_temp, self._underlying_climate.temperature_unit, self._hass.config.units.temperature_unit
)
max_val = TemperatureConverter.convert(
self._underlying_climate.max_temp, self._underlying_climate.temperature_unit, self._hass.config.units.temperature_unit
)

new_value = max(min_val, min(value, max_val))
else:
Expand Down

0 comments on commit 4956942

Please sign in to comment.