From e9508405bc1e8cc8df5d9af528bd28ba44b9f568 Mon Sep 17 00:00:00 2001 From: escoand Date: Wed, 31 Jan 2018 13:05:15 +0100 Subject: [PATCH] Add conditions to forecast (#12074) * add conditions to forecast chart * Fix pylint issues --- .../components/weather/openweathermap.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/weather/openweathermap.py b/homeassistant/components/weather/openweathermap.py index 408b6968588..c8a1bdf8f68 100644 --- a/homeassistant/components/weather/openweathermap.py +++ b/homeassistant/components/weather/openweathermap.py @@ -21,12 +21,14 @@ REQUIREMENTS = ['pyowm==2.8.0'] _LOGGER = logging.getLogger(__name__) +ATTR_FORECAST_CONDITION = 'condition' ATTRIBUTION = 'Data provided by OpenWeatherMap' DEFAULT_NAME = 'OpenWeatherMap' MIN_TIME_BETWEEN_FORECAST_UPDATES = timedelta(minutes=30) MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10) +MIN_OFFSET_BETWEEN_FORECAST_CONDITIONS = 3 CONDITION_CLASSES = { 'cloudy': [804], @@ -137,10 +139,18 @@ class OpenWeatherMapWeather(WeatherEntity): @property def forecast(self): """Return the forecast array.""" - return [{ - ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000, - ATTR_FORECAST_TEMP: entry.get_temperature('celsius').get('temp')} - for entry in self.forecast_data.get_weathers()] + data = [] + for entry in self.forecast_data.get_weathers(): + data.append({ + ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000, + ATTR_FORECAST_TEMP: + entry.get_temperature('celsius').get('temp') + }) + if (len(data) - 1) % MIN_OFFSET_BETWEEN_FORECAST_CONDITIONS == 0: + data[len(data) - 1][ATTR_FORECAST_CONDITION] = \ + [k for k, v in CONDITION_CLASSES.items() + if entry.get_weather_code() in v][0] + return data def update(self): """Get the latest data from OWM and updates the states."""