From 28b4972233de42617fb05df574de22743604edfd Mon Sep 17 00:00:00 2001 From: Boyi C Date: Sun, 23 Jul 2017 17:18:45 +0800 Subject: [PATCH 01/19] work on weather panel --- .../components/frontend/www_static/home-assistant-polymer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index c7be840a9d73b..224e06681c92c 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit c7be840a9d73b6a32a0d74b1a5c0fb4475018d75 +Subproject commit 224e06681c92c9a785383ed26b0341d0544eca40 From 4f929ea17451f1e67cdac7f13308e2b88ca8865e Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 00:24:48 +0800 Subject: [PATCH 02/19] update yahooweather with more forecast details --- homeassistant/components/weather/yweather.py | 47 +++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 0e216273d65a2..3612f780878f4 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -12,7 +12,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.components.weather import ( WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_TEMP) -from homeassistant.const import (TEMP_CELSIUS, CONF_NAME, STATE_UNKNOWN) +from homeassistant.const import (TEMP_CELSIUS, CONF_NAME) REQUIREMENTS = ["yahooweather==0.8"] @@ -21,6 +21,9 @@ ATTR_FORECAST_CONDITION = 'condition' ATTRIBUTION = "Weather details provided by Yahoo! Inc." +ATTR_FORECAST_DATE = 'datetime' +ATTR_FORECAST_TEMP = 'temperature' + CONF_FORECAST = 'forecast' CONF_WOEID = 'woeid' @@ -33,18 +36,20 @@ 'fog': [19, 20, 21, 22, 23], 'hail': [17, 18, 35], 'lightning': [37], - 'lightning-rainy': [38, 39], + 'lightning-rainy': [38, 39, 47], 'partlycloudy': [44], 'pouring': [40, 45], 'rainy': [9, 11, 12], 'snowy': [8, 13, 14, 15, 16, 41, 42, 43], - 'snowy-rainy': [5, 6, 7, 10, 46, 47], - 'sunny': [32], + 'snowy-rainy': [5, 6, 7, 10, 46], + 'sunny': [32, 33, 34], 'windy': [24], 'windy-variant': [], 'exceptional': [0, 1, 2, 3, 4, 25, 36], } +CONDITION_CLASSES_LIST = [str(x) for x in range(0, 50)] + PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, @@ -52,6 +57,7 @@ vol.All(vol.Coerce(int), vol.Range(min=0, max=5)), }) +DEGREE_TO_TEXT = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'] def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yahoo! weather platform.""" @@ -82,8 +88,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None): len(yahoo_api.yahoo.Forecast)) return False + for cond, condlst in CONDITION_CLASSES.items(): + for condi in condlst: + CONDITION_CLASSES_LIST[condi] = cond + add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True) +def _windtostring(degree): + return DEGREE_TO_TEXT[int((int(degree) + 22.5) / 45)] class YahooWeatherWeather(WeatherEntity): """Representation of Yahoo! weather data.""" @@ -102,11 +114,7 @@ def name(self): @property def condition(self): """Return the current condition.""" - try: - return [k for k, v in CONDITION_CLASSES.items() if - int(self._data.yahoo.Now['code']) in v][0] - except IndexError: - return STATE_UNKNOWN + return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])] @property def temperature(self): @@ -138,6 +146,11 @@ def wind_speed(self): """Return the wind speed.""" return self._data.yahoo.Wind['speed'] + @property + def wind_bearing(self): + """Return the wind speed.""" + return self._data.yahoo.Wind['direction'] + @property def attribution(self): """Return the attribution.""" @@ -146,19 +159,9 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" - try: - forecast_condition = \ - [k for k, v in CONDITION_CLASSES.items() if - int(self._data.yahoo.Forecast[self._forecast]['code']) - in v][0] - except IndexError: - return STATE_UNKNOWN - - return [{ - ATTR_FORECAST_CONDITION: forecast_condition, - ATTR_FORECAST_TEMP: - self._data.yahoo.Forecast[self._forecast]['high'], - }] + return [{'datetime':v['date'], ATTR_FORECAST_TEMP:int(v['high']), 'templow': int(v['low']), + 'condition': CONDITION_CLASSES_LIST[int(v['code'])]} + for v in self._data.yahoo.Forecast] def update(self): """Get the latest data from Yahoo! and updates the states.""" From 9be313b46422c2aff2060bd6e2d69e8df7948189 Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 18:23:19 +0800 Subject: [PATCH 03/19] Update yweather to allow user input forecast date --- homeassistant/components/weather/yweather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 3612f780878f4..3760b3c1b4202 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -53,8 +53,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_FORECAST, default=0): - vol.All(vol.Coerce(int), vol.Range(min=0, max=5)), + vol.Optional(CONF_FORECAST, default=5): + vol.All(vol.Coerce(int), vol.Range(min=0, max=5)), }) DEGREE_TO_TEXT = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'] @@ -161,7 +161,7 @@ def forecast(self): """Return the forecast array.""" return [{'datetime':v['date'], ATTR_FORECAST_TEMP:int(v['high']), 'templow': int(v['low']), 'condition': CONDITION_CLASSES_LIST[int(v['code'])]} - for v in self._data.yahoo.Forecast] + for v in self._data.yahoo.Forecast[:self._forecast]] def update(self): """Get the latest data from Yahoo! and updates the states.""" From 3eae6dd278f5b62d89dff95367dba1fd44ad38a6 Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 18:48:12 +0800 Subject: [PATCH 04/19] fix for houndci --- homeassistant/components/weather/yweather.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 3760b3c1b4202..2a708bca3dda0 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -11,7 +11,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.components.weather import ( - WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_TEMP) + WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME) from homeassistant.const import (TEMP_CELSIUS, CONF_NAME) REQUIREMENTS = ["yahooweather==0.8"] @@ -21,11 +21,11 @@ ATTR_FORECAST_CONDITION = 'condition' ATTRIBUTION = "Weather details provided by Yahoo! Inc." -ATTR_FORECAST_DATE = 'datetime' -ATTR_FORECAST_TEMP = 'temperature' +ATTR_FORECAST_TIME = 'datetime' +ATTR_FORECAST_TEMP_LOW = 'templow' -CONF_FORECAST = 'forecast' CONF_WOEID = 'woeid' +CONF_FORECAST = 'forecast' DEFAULT_NAME = 'Yweather' @@ -94,9 +94,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True) + def _windtostring(degree): return DEGREE_TO_TEXT[int((int(degree) + 22.5) / 45)] + class YahooWeatherWeather(WeatherEntity): """Representation of Yahoo! weather data.""" @@ -159,8 +161,8 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" - return [{'datetime':v['date'], ATTR_FORECAST_TEMP:int(v['high']), 'templow': int(v['low']), - 'condition': CONDITION_CLASSES_LIST[int(v['code'])]} + return [{ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']), + ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[int(v['code'])]} for v in self._data.yahoo.Forecast[:self._forecast]] def update(self): From bda23f71e7cbb401593f5c9d906448890d16e337 Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 19:09:37 +0800 Subject: [PATCH 05/19] fix long line --- homeassistant/components/weather/yweather.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 2a708bca3dda0..44aab2c776e67 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -11,7 +11,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.components.weather import ( - WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME) + WeatherEntity, PLATFORM_SCHEMA, + ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME) from homeassistant.const import (TEMP_CELSIUS, CONF_NAME) REQUIREMENTS = ["yahooweather==0.8"] @@ -21,7 +22,6 @@ ATTR_FORECAST_CONDITION = 'condition' ATTRIBUTION = "Weather details provided by Yahoo! Inc." -ATTR_FORECAST_TIME = 'datetime' ATTR_FORECAST_TEMP_LOW = 'templow' CONF_WOEID = 'woeid' @@ -161,9 +161,14 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" - return [{ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']), - ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[int(v['code'])]} - for v in self._data.yahoo.Forecast[:self._forecast]] + return [ + { + ATTR_FORECAST_TIME: v['date'], + ATTR_FORECAST_TEMP:int(v['high']), + ATTR_FORECAST_TEMP_LOW: int(v['low']), + ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[ + int(v['code'])] + } for v in self._data.yahoo.Forecast[:self._forecast]] def update(self): """Get the latest data from Yahoo! and updates the states.""" From b945231666a8058d480e57a5944e17a5922a958e Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 21:00:13 +0800 Subject: [PATCH 06/19] fix1 --- homeassistant/components/weather/yweather.py | 27 ++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 44aab2c776e67..6b6c0814bec6c 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -48,17 +48,21 @@ 'exceptional': [0, 1, 2, 3, 4, 25, 36], } -CONDITION_CLASSES_LIST = [str(x) for x in range(0, 50)] +_CONDITION_CLASSES_MAX = 50 + +CONDITION_CLASSES_LIST = [str(x) for x in range(0, _CONDITION_CLASSES_MAX)] + +for cond, condlst in CONDITION_CLASSES.items(): + for condi in condlst: + CONDITION_CLASSES_LIST[condi] = cond PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_FORECAST, default=5): - vol.All(vol.Coerce(int), vol.Range(min=0, max=5)), + vol.All(vol.Coerce(int), vol.Range(min=0, max=10)), }) -DEGREE_TO_TEXT = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'] - def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yahoo! weather platform.""" from yahooweather import get_woeid, UNIT_C, UNIT_F @@ -88,17 +92,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None): len(yahoo_api.yahoo.Forecast)) return False - for cond, condlst in CONDITION_CLASSES.items(): - for condi in condlst: - CONDITION_CLASSES_LIST[condi] = cond - add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True) -def _windtostring(degree): - return DEGREE_TO_TEXT[int((int(degree) + 22.5) / 45)] - - class YahooWeatherWeather(WeatherEntity): """Representation of Yahoo! weather data.""" @@ -116,7 +112,10 @@ def name(self): @property def condition(self): """Return the current condition.""" - return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])] + try: + return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])] + except (ValueError, IndexError): + return '' @property def temperature(self): @@ -161,6 +160,8 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" + if self._forecast == None: + return [] return [ { ATTR_FORECAST_TIME: v['date'], From c93fa08026b9d75597e9af6d5cea43301ce80078 Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 21:16:24 +0800 Subject: [PATCH 07/19] Revert "work on weather panel" This reverts commit 28b4972233de42617fb05df574de22743604edfd. revert unintentional submodule change --- .../components/frontend/www_static/home-assistant-polymer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index 224e06681c92c..c7be840a9d73b 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit 224e06681c92c9a785383ed26b0341d0544eca40 +Subproject commit c7be840a9d73b6a32a0d74b1a5c0fb4475018d75 From ce00d787d2857d4242a964ac1285829d48695d6c Mon Sep 17 00:00:00 2001 From: Boyi C Date: Mon, 24 Jul 2017 21:21:28 +0800 Subject: [PATCH 08/19] fix2 fix typo, add try catch to another int() --- homeassistant/components/weather/yweather.py | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 6b6c0814bec6c..6dcbc6597a2a2 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -160,16 +160,19 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" - if self._forecast == None: + if not self._forecast: + return [] + try: + return [ + { + ATTR_FORECAST_TIME: v['date'], + ATTR_FORECAST_TEMP:int(v['high']), + ATTR_FORECAST_TEMP_LOW: int(v['low']), + ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[ + int(v['code'])] + } for v in self._data.yahoo.Forecast[:self._forecast]] + except (ValueError, IndexError): return [] - return [ - { - ATTR_FORECAST_TIME: v['date'], - ATTR_FORECAST_TEMP:int(v['high']), - ATTR_FORECAST_TEMP_LOW: int(v['low']), - ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[ - int(v['code'])] - } for v in self._data.yahoo.Forecast[:self._forecast]] def update(self): """Get the latest data from Yahoo! and updates the states.""" From 7bdc2b69b1c92368e625effd093edb9f93d7b70a Mon Sep 17 00:00:00 2001 From: Boyi C Date: Tue, 25 Jul 2017 01:11:11 +0800 Subject: [PATCH 09/19] fix pylint --- homeassistant/components/weather/yweather.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 6dcbc6597a2a2..d18615e830cac 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -63,6 +63,7 @@ vol.All(vol.Coerce(int), vol.Range(min=0, max=10)), }) + def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Yahoo! weather platform.""" from yahooweather import get_woeid, UNIT_C, UNIT_F From 0e1df57d24d06b89e2e8d597a10e08b94294bf11 Mon Sep 17 00:00:00 2001 From: Boyi C Date: Tue, 25 Jul 2017 14:27:51 +0800 Subject: [PATCH 10/19] fix3 --- homeassistant/components/weather/yweather.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index d18615e830cac..5d0b1cec231e7 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -13,7 +13,7 @@ from homeassistant.components.weather import ( WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME) -from homeassistant.const import (TEMP_CELSIUS, CONF_NAME) +from homeassistant.const import (TEMP_CELSIUS, CONF_NAME, STATE_UNKNOWN) REQUIREMENTS = ["yahooweather==0.8"] @@ -116,7 +116,7 @@ def condition(self): try: return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])] except (ValueError, IndexError): - return '' + return STATE_UNKNOWN @property def temperature(self): @@ -150,7 +150,7 @@ def wind_speed(self): @property def wind_bearing(self): - """Return the wind speed.""" + """Return the wind direction.""" return self._data.yahoo.Wind['direction'] @property @@ -161,7 +161,7 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" - if not self._forecast: + if self._forecast == 0: return [] try: return [ From dd16584a9c02566e0803db296e32989059d76f45 Mon Sep 17 00:00:00 2001 From: Boyi C Date: Wed, 26 Jul 2017 19:29:42 +0800 Subject: [PATCH 11/19] fix4 --- homeassistant/components/weather/yweather.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 5d0b1cec231e7..1cd80650b7dcf 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -25,7 +25,7 @@ ATTR_FORECAST_TEMP_LOW = 'templow' CONF_WOEID = 'woeid' -CONF_FORECAST = 'forecast' +CONF_FORECAST_DAYS = 'forecast_days' DEFAULT_NAME = 'Yweather' @@ -48,9 +48,7 @@ 'exceptional': [0, 1, 2, 3, 4, 25, 36], } -_CONDITION_CLASSES_MAX = 50 - -CONDITION_CLASSES_LIST = [str(x) for x in range(0, _CONDITION_CLASSES_MAX)] +CONDITION_CLASSES_LIST = [str(x) for x in range(0, 50)] for cond, condlst in CONDITION_CLASSES.items(): for condi in condlst: @@ -59,7 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_FORECAST, default=5): + vol.Optional(CONF_FORECAST_DAYS, default=5): vol.All(vol.Coerce(int), vol.Range(min=0, max=10)), }) @@ -70,7 +68,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): unit = hass.config.units.temperature_unit woeid = config.get(CONF_WOEID) - forecast = config.get(CONF_FORECAST) + forecast = config.get(CONF_FORECAST_DAYS) name = config.get(CONF_NAME) yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F From bc7b17948c8c60dd7754071d66680704c69fdd75 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 15:24:56 +0200 Subject: [PATCH 12/19] Update yweather.py --- homeassistant/components/weather/yweather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 1cd80650b7dcf..d6d797f26278b 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -57,7 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_FORECAST_DAYS, default=5): + vol.Optional(CONF_FORECAST_DAYS, default=0): vol.All(vol.Coerce(int), vol.Range(min=0, max=10)), }) From 9ec5d9cf7b0a85c5c40567de8c8404ca54a81164 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 15:26:30 +0200 Subject: [PATCH 13/19] Update yweather.py --- homeassistant/components/weather/yweather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index d6d797f26278b..e01bb82eb4099 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -25,7 +25,7 @@ ATTR_FORECAST_TEMP_LOW = 'templow' CONF_WOEID = 'woeid' -CONF_FORECAST_DAYS = 'forecast_days' +CONF_FORECAST = 'forecast' DEFAULT_NAME = 'Yweather' @@ -57,7 +57,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_FORECAST_DAYS, default=0): + vol.Optional(CONF_FORECAST, default=0): vol.All(vol.Coerce(int), vol.Range(min=0, max=10)), }) @@ -68,7 +68,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): unit = hass.config.units.temperature_unit woeid = config.get(CONF_WOEID) - forecast = config.get(CONF_FORECAST_DAYS) + forecast = config.get(CONF_FORECAST) name = config.get(CONF_NAME) yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F From c790723564532e4c3252e23a5e0f00180ffbb66f Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 15:54:32 +0200 Subject: [PATCH 14/19] Remove global data construct --- homeassistant/components/weather/yweather.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index e01bb82eb4099..49e59d452d33d 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -19,6 +19,8 @@ _LOGGER = logging.getLogger(__name__) +DATA_CONDITION = 'yahoo_condition' + ATTR_FORECAST_CONDITION = 'condition' ATTRIBUTION = "Weather details provided by Yahoo! Inc." @@ -48,11 +50,6 @@ 'exceptional': [0, 1, 2, 3, 4, 25, 36], } -CONDITION_CLASSES_LIST = [str(x) for x in range(0, 50)] - -for cond, condlst in CONDITION_CLASSES.items(): - for condi in condlst: - CONDITION_CLASSES_LIST[condi] = cond PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, @@ -90,6 +87,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.error("Yahoo! only support %d days forecast", len(yahoo_api.yahoo.Forecast)) return False + + # create condition helper + if DATA_CONDITION not in hass.data: + hass.data[DATA_CONDITION] = [str(x) for x in range(0, 50)] + for cond, condlst in CONDITION_CLASSES.items(): + for condi in condlst: + hass.data[DATA_CONDITION][condi] = cond add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True) @@ -112,7 +116,7 @@ def name(self): def condition(self): """Return the current condition.""" try: - return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])] + return hass.data[DATA_CONDITION][int(self._data.yahoo.Now['code'])] except (ValueError, IndexError): return STATE_UNKNOWN @@ -167,7 +171,7 @@ def forecast(self): ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']), - ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[ + ATTR_FORECAST_CONDITION: hass.data[DATA_CONDITION][ int(v['code'])] } for v in self._data.yahoo.Forecast[:self._forecast]] except (ValueError, IndexError): From 72bbde71c9581f7863d190db87643e6cccec1562 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 15:57:11 +0200 Subject: [PATCH 15/19] Yahoo API support only 5 days forecast --- homeassistant/components/weather/yweather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 49e59d452d33d..cbbf75e96a1fb 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -55,7 +55,7 @@ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_FORECAST, default=0): - vol.All(vol.Coerce(int), vol.Range(min=0, max=10)), + vol.All(vol.Coerce(int), vol.Range(min=0, max=5)), }) From 3733b3e5e0b9817bfccecb41574fa15bd069b500 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 16:03:33 +0200 Subject: [PATCH 16/19] remove forecast --- homeassistant/components/weather/yweather.py | 23 +++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index cbbf75e96a1fb..d91632979f5dd 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -27,7 +27,6 @@ ATTR_FORECAST_TEMP_LOW = 'templow' CONF_WOEID = 'woeid' -CONF_FORECAST = 'forecast' DEFAULT_NAME = 'Yweather' @@ -54,8 +53,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_WOEID, default=None): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_FORECAST, default=0): - vol.All(vol.Coerce(int), vol.Range(min=0, max=5)), }) @@ -65,7 +62,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): unit = hass.config.units.temperature_unit woeid = config.get(CONF_WOEID) - forecast = config.get(CONF_FORECAST) name = config.get(CONF_NAME) yunit = UNIT_C if unit == TEMP_CELSIUS else UNIT_F @@ -82,11 +78,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if not yahoo_api.update(): _LOGGER.critical("Can't retrieve weather data from Yahoo!") return False - - if forecast >= len(yahoo_api.yahoo.Forecast): - _LOGGER.error("Yahoo! only support %d days forecast", - len(yahoo_api.yahoo.Forecast)) - return False # create condition helper if DATA_CONDITION not in hass.data: @@ -95,17 +86,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for condi in condlst: hass.data[DATA_CONDITION][condi] = cond - add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True) + add_devices([YahooWeatherWeather(yahoo_api, name)], True) class YahooWeatherWeather(WeatherEntity): """Representation of Yahoo! weather data.""" - def __init__(self, weather_data, name, forecast): + def __init__(self, weather_data, name): """Initialize the sensor.""" self._name = name self._data = weather_data - self._forecast = forecast @property def name(self): @@ -116,7 +106,8 @@ def name(self): def condition(self): """Return the current condition.""" try: - return hass.data[DATA_CONDITION][int(self._data.yahoo.Now['code'])] + return self.hass.data[DATA_CONDITION][int( + self._data.yahoo.Now['code'])] except (ValueError, IndexError): return STATE_UNKNOWN @@ -163,8 +154,6 @@ def attribution(self): @property def forecast(self): """Return the forecast array.""" - if self._forecast == 0: - return [] try: return [ { @@ -173,9 +162,9 @@ def forecast(self): ATTR_FORECAST_TEMP_LOW: int(v['low']), ATTR_FORECAST_CONDITION: hass.data[DATA_CONDITION][ int(v['code'])] - } for v in self._data.yahoo.Forecast[:self._forecast]] + } for v in self._data.yahoo.Forecast[]] except (ValueError, IndexError): - return [] + return STATE_UNKNOWN def update(self): """Get the latest data from Yahoo! and updates the states.""" From 719681edbfba0315a3ad3365fe73a74bdb1dc477 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 16:05:42 +0200 Subject: [PATCH 17/19] fix lint --- homeassistant/components/weather/yweather.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index d91632979f5dd..21501bce99960 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -78,7 +78,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if not yahoo_api.update(): _LOGGER.critical("Can't retrieve weather data from Yahoo!") return False - + # create condition helper if DATA_CONDITION not in hass.data: hass.data[DATA_CONDITION] = [str(x) for x in range(0, 50)] @@ -160,7 +160,7 @@ def forecast(self): ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']), - ATTR_FORECAST_CONDITION: hass.data[DATA_CONDITION][ + ATTR_FORECAST_CONDITION: self.hass.data[DATA_CONDITION][ int(v['code'])] } for v in self._data.yahoo.Forecast[]] except (ValueError, IndexError): From 3d0b56955328bcf98465b9b6d3ff4dadfb198b69 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 16:08:21 +0200 Subject: [PATCH 18/19] fix lint p2 --- homeassistant/components/weather/yweather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index 21501bce99960..d1bad720d0aaa 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -160,9 +160,9 @@ def forecast(self): ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']), - ATTR_FORECAST_CONDITION: self.hass.data[DATA_CONDITION][ - int(v['code'])] - } for v in self._data.yahoo.Forecast[]] + ATTR_FORECAST_CONDITION: + self.hass.data[DATA_CONDITION][int(v['code'])] + } for v in self._data.yahoo.Forecast] except (ValueError, IndexError): return STATE_UNKNOWN From 1366721a6f0599f8c71b5fd9cbdbf876a09b88f7 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 26 Jul 2017 16:11:44 +0200 Subject: [PATCH 19/19] Update yweather.py --- homeassistant/components/weather/yweather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index d1bad720d0aaa..687d919ed95ca 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -160,7 +160,7 @@ def forecast(self): ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']), - ATTR_FORECAST_CONDITION: + ATTR_FORECAST_CONDITION: self.hass.data[DATA_CONDITION][int(v['code'])] } for v in self._data.yahoo.Forecast] except (ValueError, IndexError):