mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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
@ -149,6 +149,15 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
def forecast(self):
|
def forecast(self):
|
||||||
"""Return the forecast array."""
|
"""Return the forecast array."""
|
||||||
data = []
|
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():
|
for entry in self.forecast_data.get_weathers():
|
||||||
if self._mode == 'daily':
|
if self._mode == 'daily':
|
||||||
data.append({
|
data.append({
|
||||||
@ -159,7 +168,9 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
ATTR_FORECAST_TEMP_LOW:
|
ATTR_FORECAST_TEMP_LOW:
|
||||||
entry.get_temperature('celsius').get('night'),
|
entry.get_temperature('celsius').get('night'),
|
||||||
ATTR_FORECAST_PRECIPITATION:
|
ATTR_FORECAST_PRECIPITATION:
|
||||||
entry.get_rain().get('all'),
|
calc_precipitation(
|
||||||
|
entry.get_rain().get('all'),
|
||||||
|
entry.get_snow().get('all')),
|
||||||
ATTR_FORECAST_WIND_SPEED:
|
ATTR_FORECAST_WIND_SPEED:
|
||||||
entry.get_wind().get('speed'),
|
entry.get_wind().get('speed'),
|
||||||
ATTR_FORECAST_WIND_BEARING:
|
ATTR_FORECAST_WIND_BEARING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user