diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index acb95c17814..b200d634ba9 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -110,7 +110,7 @@ class WeatherEntity(Entity): ATTR_WEATHER_TEMPERATURE: show_temp( self.hass, self.temperature, self.temperature_unit, self.precision), - ATTR_WEATHER_HUMIDITY: self.humidity, + ATTR_WEATHER_HUMIDITY: round(self.humidity) } ozone = self.ozone diff --git a/homeassistant/components/weather/darksky.py b/homeassistant/components/weather/darksky.py index 139f8abfce6..21f67ce080a 100644 --- a/homeassistant/components/weather/darksky.py +++ b/homeassistant/components/weather/darksky.py @@ -96,7 +96,7 @@ class DarkSkyWeather(WeatherEntity): @property def humidity(self): """Return the humidity.""" - return round(self._ds_currently.get('humidity') * 100.0, 2) + return self._ds_currently.get('humidity') * 100.0 @property def wind_speed(self): diff --git a/homeassistant/helpers/temperature.py b/homeassistant/helpers/temperature.py index a4626c33210..e4c985d5cfb 100644 --- a/homeassistant/helpers/temperature.py +++ b/homeassistant/helpers/temperature.py @@ -3,11 +3,12 @@ from numbers import Number from homeassistant.core import HomeAssistant from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.const import PRECISION_HALVES, PRECISION_TENTHS def display_temp(hass: HomeAssistant, temperature: float, unit: str, precision: float) -> float: - """Convert temperature into preferred units for display purposes.""" + """Convert temperature into preferred units/precision for display.""" temperature_unit = unit ha_unit = hass.config.units.temperature_unit @@ -25,9 +26,12 @@ def display_temp(hass: HomeAssistant, temperature: float, unit: str, temperature, temperature_unit, ha_unit) # Round in the units appropriate - if precision == 0.5: - return round(temperature * 2) / 2.0 - elif precision == 0.1: - return round(temperature, 1) + if precision == PRECISION_HALVES: + temperature = round(temperature * 2) / 2.0 + elif precision == PRECISION_TENTHS: + temperature = round(temperature, 1) # Integer as a fall back (PRECISION_WHOLE) - return round(temperature) + else: + temperature = round(temperature) + + return temperature