-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Yahoo Weather update, supports forecast for more days #8626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
28b4972
4f929ea
9be313b
3eae6dd
bda23f7
b945231
c93fa08
ce00d78
7bdc2b6
0e1df57
dd16584
bc7b179
9ec5d9c
c790723
72bbde7
3733b3e
719681e
3d0b569
1366721
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,9 @@ | |
|
|
||
| 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) | ||
| WeatherEntity, PLATFORM_SCHEMA, | ||
| ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME) | ||
| from homeassistant.const import (TEMP_CELSIUS, CONF_NAME) | ||
|
|
||
| REQUIREMENTS = ["yahooweather==0.8"] | ||
|
|
||
|
|
@@ -21,8 +22,10 @@ | |
| ATTR_FORECAST_CONDITION = 'condition' | ||
| ATTRIBUTION = "Weather details provided by Yahoo! Inc." | ||
|
|
||
| CONF_FORECAST = 'forecast' | ||
| ATTR_FORECAST_TEMP_LOW = 'templow' | ||
|
|
||
| CONF_WOEID = 'woeid' | ||
| CONF_FORECAST = 'forecast' | ||
|
|
||
| DEFAULT_NAME = 'Yweather' | ||
|
|
||
|
|
@@ -33,25 +36,28 @@ | |
| '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, | ||
| 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)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this change. |
||
| }) | ||
|
|
||
| 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,9 +88,17 @@ 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not allow to use globals. You need do that inside data with a membervariable
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CONDITION_CLASSES_LIST should be a const, so I think I forget to move the init code into globle scope. 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 |
||
|
|
||
| add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True) | ||
|
|
||
|
|
||
| def _windtostring(degree): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
| return DEGREE_TO_TEXT[int((int(degree) + 22.5) / 45)] | ||
|
|
||
|
|
||
| class YahooWeatherWeather(WeatherEntity): | ||
| """Representation of Yahoo! weather data.""" | ||
|
|
||
|
|
@@ -102,11 +116,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'])] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should catch ValueError and IndexError |
||
|
|
||
| @property | ||
| def temperature(self): | ||
|
|
@@ -138,6 +148,11 @@ def wind_speed(self): | |
| """Return the wind speed.""" | ||
| return self._data.yahoo.Wind['speed'] | ||
|
|
||
| @property | ||
| def wind_bearing(self): | ||
| """Return the wind speed.""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bearing not speed. |
||
| return self._data.yahoo.Wind['direction'] | ||
|
|
||
| @property | ||
| def attribution(self): | ||
| """Return the attribution.""" | ||
|
|
@@ -146,19 +161,14 @@ 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 [ | ||
| { | ||
| 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.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make a breaking change. I see no reason to change this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The forecast in yaml works different from the old one, so I think maybe its better to change
forecastto something likeforecast_days.