mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Modify weather components for "new" frontend card (#14076)
* Enable weather condition for all forecasts (OWM) * Remove entity_picture from BR * Remove summary texts from Dark Sky * Update test_darksky.py
This commit is contained in:
parent
f23f9465d3
commit
a94864c86f
@ -121,15 +121,6 @@ class BrWeather(WeatherEntity):
|
|||||||
if conditions:
|
if conditions:
|
||||||
return conditions.get(ccode)
|
return conditions.get(ccode)
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_picture(self):
|
|
||||||
"""Return the entity picture to use in the frontend, if any."""
|
|
||||||
from buienradar.buienradar import (IMAGE)
|
|
||||||
|
|
||||||
if self._data and self._data.condition:
|
|
||||||
return self._data.condition.get(IMAGE, None)
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self):
|
def temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
|
@ -25,9 +25,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
ATTRIBUTION = "Powered by Dark Sky"
|
ATTRIBUTION = "Powered by Dark Sky"
|
||||||
|
|
||||||
ATTR_DAILY_FORECAST_SUMMARY = 'daily_forecast_summary'
|
|
||||||
ATTR_HOURLY_FORECAST_SUMMARY = 'hourly_forecast_summary'
|
|
||||||
|
|
||||||
CONF_UNITS = 'units'
|
CONF_UNITS = 'units'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Dark Sky'
|
DEFAULT_NAME = 'Dark Sky'
|
||||||
@ -122,25 +119,6 @@ class DarkSkyWeather(WeatherEntity):
|
|||||||
ATTR_FORECAST_TEMP: entry.d.get('temperature')}
|
ATTR_FORECAST_TEMP: entry.d.get('temperature')}
|
||||||
for entry in self._ds_hourly.data]
|
for entry in self._ds_hourly.data]
|
||||||
|
|
||||||
@property
|
|
||||||
def hourly_forecast_summary(self):
|
|
||||||
"""Return a summary of the hourly forecast."""
|
|
||||||
return self._ds_hourly.summary
|
|
||||||
|
|
||||||
@property
|
|
||||||
def daily_forecast_summary(self):
|
|
||||||
"""Return a summary of the daily forecast."""
|
|
||||||
return self._ds_daily.summary
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
attrs = {
|
|
||||||
ATTR_DAILY_FORECAST_SUMMARY: self.daily_forecast_summary,
|
|
||||||
ATTR_HOURLY_FORECAST_SUMMARY: self.hourly_forecast_summary
|
|
||||||
}
|
|
||||||
return attrs
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from Dark Sky."""
|
"""Get the latest data from Dark Sky."""
|
||||||
self._dark_sky.update()
|
self._dark_sky.update()
|
||||||
|
@ -28,7 +28,6 @@ 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],
|
||||||
@ -144,12 +143,11 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
data.append({
|
data.append({
|
||||||
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
|
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
|
||||||
ATTR_FORECAST_TEMP:
|
ATTR_FORECAST_TEMP:
|
||||||
entry.get_temperature('celsius').get('temp')
|
entry.get_temperature('celsius').get('temp'),
|
||||||
})
|
ATTR_FORECAST_CONDITION:
|
||||||
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()
|
[k for k, v in CONDITION_CLASSES.items()
|
||||||
if entry.get_weather_code() in v][0]
|
if entry.get_weather_code() in v][0]
|
||||||
|
})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
@ -49,6 +49,3 @@ class TestDarkSky(unittest.TestCase):
|
|||||||
|
|
||||||
state = self.hass.states.get('weather.test')
|
state = self.hass.states.get('weather.test')
|
||||||
self.assertEqual(state.state, 'Clear')
|
self.assertEqual(state.state, 'Clear')
|
||||||
self.assertEqual(state.attributes['daily_forecast_summary'],
|
|
||||||
'No precipitation throughout the week, with '
|
|
||||||
'temperatures falling to 66°F on Thursday.')
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user