Account for openweathermap 'dew_point' not always being present (#48826)

This commit is contained in:
Hans Kröner 2021-04-08 13:39:53 +02:00 committed by GitHub
parent e70d7327f9
commit 2765256b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,7 +122,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator):
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 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator):
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."""