Skip to content

Commit

Permalink
Change VTherm temperature unit to HA's preferred unit. (#461)
Browse files Browse the repository at this point in the history
* Change VTherm temperature unit to HA's preferred unit.

* fix pytest issue

* update current_temperature, explicitly convert temps (fixes pytest error)
  • Loading branch information
mag2352 authored Jun 10, 2024
1 parent 2fd6007 commit 53dce22
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 1 addition & 4 deletions custom_components/versatile_thermostat/thermostat_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,7 @@ def swing_modes(self) -> list[str] | None:
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
if self.underlying_entity(0):
return self.underlying_entity(0).temperature_unit

return self._unit
return self.hass.config.units.temperature_unit

@property
def supported_features(self):
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._underlying_climate.min_temp
max_val = self._underlying_climate.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
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
homeassistant==2024.4.3
homeassistant==2024.6.1

0 comments on commit 53dce22

Please sign in to comment.