Add snow to Openweathermap precipitation forecast (#17551)

* Add snow to Openweathermap precipitation forecast

* Fix lint

* Fix pylint

* Add missing docstring
This commit is contained in:
Yevgeniy 2018-10-26 19:50:30 +06:00 committed by Daniel Høyer Iversen
parent 434c848104
commit 86d7bc4962

View file

@ -149,6 +149,15 @@ class OpenWeatherMapWeather(WeatherEntity):
def forecast(self):
"""Return the forecast array."""
data = []
def calc_precipitation(rain, snow):
"""Calculate the precipitation."""
rain_value = 0 if rain is None else rain
snow_value = 0 if snow is None else snow
if round(rain_value + snow_value, 1) == 0:
return None
return round(rain_value + snow_value, 1)
for entry in self.forecast_data.get_weathers():
if self._mode == 'daily':
data.append({
@ -159,7 +168,9 @@ class OpenWeatherMapWeather(WeatherEntity):
ATTR_FORECAST_TEMP_LOW:
entry.get_temperature('celsius').get('night'),
ATTR_FORECAST_PRECIPITATION:
entry.get_rain().get('all'),
calc_precipitation(
entry.get_rain().get('all'),
entry.get_snow().get('all')),
ATTR_FORECAST_WIND_SPEED:
entry.get_wind().get('speed'),
ATTR_FORECAST_WIND_BEARING: