From 28266782e643c1926b5948f40069fffdee2905c8 Mon Sep 17 00:00:00 2001 From: Cody Cooper Date: Wed, 10 Jan 2024 20:20:17 +1300 Subject: [PATCH] Reduce temperature set precision to whole numbers This is in line with what the app allows you to set (whole numbers only) for heating and resolves #39. --- custom_components/dyson_local/climate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/custom_components/dyson_local/climate.py b/custom_components/dyson_local/climate.py index f3aac11..613d856 100644 --- a/custom_components/dyson_local/climate.py +++ b/custom_components/dyson_local/climate.py @@ -17,7 +17,7 @@ ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, UnitOfTemperature +from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, UnitOfTemperature, PRECISION_WHOLE from homeassistant.core import Callable, HomeAssistant from . import DysonEntity @@ -97,7 +97,7 @@ def current_temperature(self) -> Optional[int]: temperature_kelvin = self._current_temperature_kelvin if isinstance(temperature_kelvin, str): return None - return float(f"{(temperature_kelvin - 273.15):.1f}") + return round(float(f"{(temperature_kelvin - 273.15):.1f}")) @environmental_property def current_humidity(self) -> int: @@ -114,12 +114,21 @@ def max_temp(self): """Return the maximum temperature.""" return 37 + @property + def target_temperature_step(self): + """Return the supported step size a target temperature can be increased or decreased by.""" + return PRECISION_WHOLE + def set_temperature(self, **kwargs): """Set new target temperature.""" target_temp = kwargs.get(ATTR_TEMPERATURE) if target_temp is None: _LOGGER.error("Missing target temperature %s", kwargs) return + # Limit the target temperature to whole numbers + if target_temp != round(target_temp): + _LOGGER.warning('Temperature requested is not a whole number, adjusting') + target_temp = round(target_temp) _LOGGER.debug("Set %s temperature %s", self.name, target_temp) # Limit the target temperature into acceptable range. target_temp = min(self.max_temp, target_temp)