From 7b2fd4cac2fa1ce676c216ddf4d5ad1ecdf54fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kr=C3=B6ner?= Date: Thu, 8 Apr 2021 10:00:38 +0200 Subject: [PATCH] Account for 'dew_point' not always being present --- .../openweathermap/weather_update_coordinator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/openweathermap/weather_update_coordinator.py b/homeassistant/components/openweathermap/weather_update_coordinator.py index 51e475eb75455..20cc71da72573 100644 --- a/homeassistant/components/openweathermap/weather_update_coordinator.py +++ b/homeassistant/components/openweathermap/weather_update_coordinator.py @@ -122,7 +122,7 @@ def _convert_weather_response(self, weather_response): ATTR_API_FEELS_LIKE_TEMPERATURE: current_weather.temperature("celsius").get( "feels_like" ), - ATTR_API_DEW_POINT: (round(current_weather.dewpoint / 100, 1)), + ATTR_API_DEW_POINT: self._fmt_dewpoint(current_weather.dewpoint), ATTR_API_PRESSURE: current_weather.pressure.get("press"), ATTR_API_HUMIDITY: current_weather.humidity, ATTR_API_WIND_BEARING: current_weather.wind().get("deg"), @@ -178,6 +178,12 @@ def _convert_forecast(self, entry): return forecast + @staticmethod + def _fmt_dewpoint(dewpoint): + if dewpoint is not None: + return round(dewpoint / 100, 1) + return None + @staticmethod def _get_rain(rain): """Get rain data from weather data."""