From 53dce224cd7c881a2651a633264b1db7691e7317 Mon Sep 17 00:00:00 2001 From: Maxwell Gonsalves <52668552+mag2352@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:46:45 -0400 Subject: [PATCH] Change VTherm temperature unit to HA's preferred unit. (#461) * Change VTherm temperature unit to HA's preferred unit. * fix pytest issue * update current_temperature, explicitly convert temps (fixes pytest error) --- .../versatile_thermostat/thermostat_climate.py | 5 +---- custom_components/versatile_thermostat/underlyings.py | 11 ++++++++--- requirements_dev.txt | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/custom_components/versatile_thermostat/thermostat_climate.py b/custom_components/versatile_thermostat/thermostat_climate.py index 879dece..f35edad 100644 --- a/custom_components/versatile_thermostat/thermostat_climate.py +++ b/custom_components/versatile_thermostat/thermostat_climate.py @@ -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): diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 4a01285..4112e2c 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -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 @@ -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.""" @@ -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: diff --git a/requirements_dev.txt b/requirements_dev.txt index 052ded7..1c97616 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1 +1 @@ -homeassistant==2024.4.3 +homeassistant==2024.6.1