Skip to content

Commit

Permalink
Reduce temperature set precision to whole numbers
Browse files Browse the repository at this point in the history
This is in line with what the app allows you to set (whole numbers only) for heating and resolves libdyson-wg#39.
  • Loading branch information
Cody Cooper authored and Cody Cooper committed Jan 10, 2024
1 parent 1e4224a commit 2826678
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions custom_components/dyson_local/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 2826678

Please sign in to comment.