From 55619e7d6d95854d5a8463505a41db814c37337f Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 8 Aug 2023 12:06:24 +0200 Subject: [PATCH] Modernize ecobee weather (#98023) --- homeassistant/components/ecobee/weather.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/ecobee/weather.py b/homeassistant/components/ecobee/weather.py index d38bc82c6f2..359f9ff485c 100644 --- a/homeassistant/components/ecobee/weather.py +++ b/homeassistant/components/ecobee/weather.py @@ -12,7 +12,9 @@ from homeassistant.components.weather import ( ATTR_FORECAST_NATIVE_WIND_SPEED, ATTR_FORECAST_TIME, ATTR_FORECAST_WIND_BEARING, + Forecast, WeatherEntity, + WeatherEntityFeature, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -59,6 +61,7 @@ class EcobeeWeather(WeatherEntity): _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND _attr_has_entity_name = True _attr_name = None + _attr_supported_features = WeatherEntityFeature.FORECAST_DAILY def __init__(self, data, name, index): """Initialize the Ecobee weather platform.""" @@ -161,13 +164,12 @@ class EcobeeWeather(WeatherEntity): time = self.weather.get("timestamp", "UNKNOWN") return f"Ecobee weather provided by {station} at {time} UTC" - @property - def forecast(self): + def _forecast(self) -> list[Forecast] | None: """Return the forecast array.""" if "forecasts" not in self.weather: return None - forecasts = [] + forecasts: list[Forecast] = [] date = dt_util.utcnow() for day in range(0, 5): forecast = _process_forecast(self.weather["forecasts"][day]) @@ -181,6 +183,15 @@ class EcobeeWeather(WeatherEntity): return forecasts return None + @property + def forecast(self) -> list[Forecast] | None: + """Return the forecast array.""" + return self._forecast() + + async def async_forecast_daily(self) -> list[Forecast] | None: + """Return the daily forecast in native units.""" + return self._forecast() + async def async_update(self) -> None: """Get the latest weather data.""" await self.data.update()