mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add conditions to forecast (#12074)
* add conditions to forecast chart * Fix pylint issues
This commit is contained in:
parent
6ae3fa40cf
commit
e9508405bc
@ -21,12 +21,14 @@ REQUIREMENTS = ['pyowm==2.8.0']
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ATTR_FORECAST_CONDITION = 'condition'
|
||||||
ATTRIBUTION = 'Data provided by OpenWeatherMap'
|
ATTRIBUTION = 'Data provided by OpenWeatherMap'
|
||||||
|
|
||||||
DEFAULT_NAME = 'OpenWeatherMap'
|
DEFAULT_NAME = 'OpenWeatherMap'
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_FORECAST_UPDATES = timedelta(minutes=30)
|
MIN_TIME_BETWEEN_FORECAST_UPDATES = timedelta(minutes=30)
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)
|
||||||
|
MIN_OFFSET_BETWEEN_FORECAST_CONDITIONS = 3
|
||||||
|
|
||||||
CONDITION_CLASSES = {
|
CONDITION_CLASSES = {
|
||||||
'cloudy': [804],
|
'cloudy': [804],
|
||||||
@ -137,10 +139,18 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def forecast(self):
|
def forecast(self):
|
||||||
"""Return the forecast array."""
|
"""Return the forecast array."""
|
||||||
return [{
|
data = []
|
||||||
|
for entry in self.forecast_data.get_weathers():
|
||||||
|
data.append({
|
||||||
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
|
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
|
||||||
ATTR_FORECAST_TEMP: entry.get_temperature('celsius').get('temp')}
|
ATTR_FORECAST_TEMP:
|
||||||
for entry in self.forecast_data.get_weathers()]
|
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):
|
def update(self):
|
||||||
"""Get the latest data from OWM and updates the states."""
|
"""Get the latest data from OWM and updates the states."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user