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:
parent
434c848104
commit
86d7bc4962
1 changed files with 12 additions and 1 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue