From 5c41796406dfe2ffe2fb6603832c6898878fe42e Mon Sep 17 00:00:00 2001 From: priiduonu Date: Tue, 31 Jul 2018 12:25:52 +0300 Subject: [PATCH] Round precipitation forecast to 1 decimal place The OWM returns precipitation forecast values as they are submitted to their network. It can lead to values like `0.0025000000000004 mm` which does not make sense and messes up the display card. This PR rounds the value to 1 decimal place. --- homeassistant/components/weather/openweathermap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/weather/openweathermap.py b/homeassistant/components/weather/openweathermap.py index 334948b67fb51a..65311ecde7b82f 100644 --- a/homeassistant/components/weather/openweathermap.py +++ b/homeassistant/components/weather/openweathermap.py @@ -173,7 +173,10 @@ def forecast(self): ATTR_FORECAST_TEMP: entry.get_temperature('celsius').get('temp'), ATTR_FORECAST_PRECIPITATION: - entry.get_rain().get('3h'), + (round(entry.get_rain().get('3h'), 1) + if entry.get_rain().get('3h') is not None + and (round(entry.get_rain().get('3h'), 1) > 0) + else None), ATTR_FORECAST_CONDITION: [k for k, v in CONDITION_CLASSES.items() if entry.get_weather_code() in v][0]