Skip to content
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

Remove deprecated forecast attribute from WeatherEntity #110761

Merged
merged 15 commits into from
Mar 27, 2024
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,9 @@ omit =
homeassistant/components/openuv/binary_sensor.py
homeassistant/components/openuv/coordinator.py
homeassistant/components/openuv/sensor.py
homeassistant/components/openweathermap/__init__.py
homeassistant/components/openweathermap/sensor.py
homeassistant/components/openweathermap/weather.py
homeassistant/components/openweathermap/weather_update_coordinator.py
homeassistant/components/opnsense/__init__.py
homeassistant/components/opower/__init__.py
Expand Down
11 changes: 3 additions & 8 deletions homeassistant/components/accuweather/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ def uv_index(self) -> float:
"""Return the UV index."""
return cast(float, self.coordinator.data["UVIndex"])

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast array."""
@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
if not self.coordinator.forecast:
return None
# remap keys from library to keys understood by the weather component
Expand Down Expand Up @@ -177,8 +177,3 @@ def forecast(self) -> list[Forecast] | None:
}
for item in self.coordinator.data[ATTR_FORECAST]
]

@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
return self.forecast
5 changes: 3 additions & 2 deletions homeassistant/components/buienradar/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ def __init__(self, config, coordinates):
self._attr_unique_id = (
f"{coordinates[CONF_LATITUDE]:2.6f}{coordinates[CONF_LONGITUDE]:2.6f}"
)
self._forecast: list | None = None

@callback
def data_updated(self, data: BrData) -> None:
"""Update data."""
self._attr_attribution = data.attribution
self._attr_condition = self._calc_condition(data)
self._attr_forecast = self._calc_forecast(data)
self._forecast = self._calc_forecast(data)
self._attr_humidity = data.humidity
self._attr_name = (
self._stationname or f"BR {data.stationname or '(unknown station)'}"
Expand Down Expand Up @@ -196,4 +197,4 @@ def _calc_forecast(self, data: BrData):

async def async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
return self._attr_forecast
return self._forecast
5 changes: 0 additions & 5 deletions homeassistant/components/ecobee/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ def _forecast(self) -> list[Forecast] | None:
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()
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/environment_canada/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ def condition(self):
return icon_code_to_condition(int(icon_code))
return ""

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast array."""
return get_forecast(self.ec_data, False)

@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
Expand Down
7 changes: 0 additions & 7 deletions homeassistant/components/ipma/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,6 @@ def _forecast(self, forecast: list[IPMAForecast] | None) -> list[Forecast]:
for data_in in forecast
]

@property
def forecast(self) -> list[Forecast]:
"""Return the forecast array."""
return self._forecast(
self._hourly_forecast if self._period == 1 else self._daily_forecast
)

async def _try_update_forecast(
self,
forecast_type: Literal["daily", "hourly"],
Expand Down
60 changes: 0 additions & 60 deletions homeassistant/components/kitchen_sink/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,6 @@ async def async_setup_entry(
"""Set up the Demo config entry."""
async_add_entities(
[
DemoWeather(
"Legacy weather",
"Sunshine",
21.6414,
92,
1099,
0.5,
UnitOfTemperature.CELSIUS,
UnitOfPressure.HPA,
UnitOfSpeed.METERS_PER_SECOND,
[
[ATTR_CONDITION_RAINY, 1, 22, 15, 60],
[ATTR_CONDITION_RAINY, 5, 19, 8, 30],
[ATTR_CONDITION_CLOUDY, 0, 15, 9, 10],
[ATTR_CONDITION_SUNNY, 0, 12, 6, 0],
[ATTR_CONDITION_PARTLYCLOUDY, 2, 14, 7, 20],
[ATTR_CONDITION_RAINY, 15, 18, 7, 0],
[ATTR_CONDITION_FOG, 0.2, 21, 12, 100],
],
None,
None,
None,
),
DemoWeather(
"Legacy + daily weather",
"Sunshine",
Expand All @@ -103,15 +80,6 @@ async def async_setup_entry(
[ATTR_CONDITION_RAINY, 15, 18, 7, 0],
[ATTR_CONDITION_FOG, 0.2, 21, 12, 100],
],
[
[ATTR_CONDITION_RAINY, 1, 22, 15, 60],
[ATTR_CONDITION_RAINY, 5, 19, 8, 30],
[ATTR_CONDITION_CLOUDY, 0, 15, 9, 10],
[ATTR_CONDITION_SUNNY, 0, 12, 6, 0],
[ATTR_CONDITION_PARTLYCLOUDY, 2, 14, 7, 20],
[ATTR_CONDITION_RAINY, 15, 18, 7, 0],
[ATTR_CONDITION_FOG, 0.2, 21, 12, 100],
],
None,
None,
),
Expand All @@ -125,7 +93,6 @@ async def async_setup_entry(
UnitOfTemperature.FAHRENHEIT,
UnitOfPressure.INHG,
UnitOfSpeed.MILES_PER_HOUR,
None,
[
[ATTR_CONDITION_SNOWY, 2, -10, -15, 60],
[ATTR_CONDITION_PARTLYCLOUDY, 1, -13, -14, 25],
Expand Down Expand Up @@ -156,7 +123,6 @@ async def async_setup_entry(
UnitOfTemperature.CELSIUS,
UnitOfPressure.HPA,
UnitOfSpeed.METERS_PER_SECOND,
None,
[
[ATTR_CONDITION_RAINY, 1, 22, 15, 60],
[ATTR_CONDITION_RAINY, 5, 19, 8, 30],
Expand Down Expand Up @@ -196,7 +162,6 @@ async def async_setup_entry(
UnitOfPressure.HPA,
UnitOfSpeed.METERS_PER_SECOND,
None,
None,
[
[ATTR_CONDITION_CLOUDY, 1, 22, 15, 60],
[ATTR_CONDITION_CLOUDY, 5, 19, 8, 30],
Expand Down Expand Up @@ -226,7 +191,6 @@ async def async_setup_entry(
UnitOfTemperature.CELSIUS,
UnitOfPressure.HPA,
UnitOfSpeed.METERS_PER_SECOND,
None,
[
[ATTR_CONDITION_RAINY, 1, 22, 15, 60],
[ATTR_CONDITION_RAINY, 5, 19, 8, 30],
Expand Down Expand Up @@ -268,7 +232,6 @@ def __init__(
temperature_unit: str,
pressure_unit: str,
wind_speed_unit: str,
forecast: list[list] | None,
forecast_daily: list[list] | None,
forecast_hourly: list[list] | None,
forecast_twice_daily: list[list] | None,
Expand All @@ -284,7 +247,6 @@ def __init__(
self._native_pressure_unit = pressure_unit
self._native_wind_speed = wind_speed
self._native_wind_speed_unit = wind_speed_unit
self._forecast = forecast
self._forecast_daily = forecast_daily
self._forecast_hourly = forecast_hourly
self._forecast_twice_daily = forecast_twice_daily
Expand Down Expand Up @@ -360,28 +322,6 @@ def condition(self) -> str:
"""Return the weather condition."""
return CONDITION_MAP[self._condition.lower()]

@property
def forecast(self) -> list[Forecast]:
"""Return legacy forecast."""
if self._forecast is None:
return []
reftime = dt_util.now().replace(hour=16, minute=00)

forecast_data = []
for entry in self._forecast:
data_dict = Forecast(
datetime=reftime.isoformat(),
condition=entry[0],
precipitation=entry[1],
temperature=entry[2],
templow=entry[3],
precipitation_probability=entry[4],
)
reftime = reftime + timedelta(hours=24)
forecast_data.append(data_dict)

return forecast_data

async def async_forecast_daily(self) -> list[Forecast]:
"""Return the daily forecast."""
if self._forecast_daily is None:
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/met/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ def _forecast(self, hourly: bool) -> list[Forecast] | None:
ha_forecast.append(ha_item) # type: ignore[arg-type]
return ha_forecast

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast array."""
return self._forecast(False)

@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/met_eireann/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ def _forecast(self, hourly: bool) -> list[Forecast]:
ha_forecast.append(ha_item)
return ha_forecast

@property
def forecast(self) -> list[Forecast]:
"""Return the forecast array."""
return self._forecast(False)

@callback
def _async_forecast_daily(self) -> list[Forecast]:
"""Return the daily forecast in native units."""
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/meteo_france/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ def _forecast(self, mode: str) -> list[Forecast]:
)
return forecast_data

@property
def forecast(self) -> list[Forecast]:
"""Return the forecast array."""
return self._forecast(self._mode)

async def async_forecast_daily(self) -> list[Forecast]:
"""Return the daily forecast in native units."""
return self._forecast(FORECAST_MODE_DAILY)
Expand Down
8 changes: 0 additions & 8 deletions homeassistant/components/metoffice/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ def wind_bearing(self) -> str | None:
return str(value) if value is not None else None
return None

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast array."""
return [
_build_forecast_data(timestep)
for timestep in self.coordinator.data.forecast
]

@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the twice daily forecast in native units."""
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/nws/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ def _forecast(
forecast.append(data)
return forecast

@property
def forecast(self) -> list[Forecast] | None:
"""Return forecast."""
return self._forecast(self._forecast_legacy, DAYNIGHT)

@callback
def _async_forecast_hourly(self) -> list[Forecast] | None:
"""Return the hourly forecast in native units."""
Expand Down
11 changes: 3 additions & 8 deletions homeassistant/components/open_meteo/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def wind_bearing(self) -> float | str | None:
return None
return self.coordinator.data.current_weather.wind_direction

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast in native units."""
@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
if self.coordinator.data.daily is None:
return None

Expand Down Expand Up @@ -124,8 +124,3 @@ def forecast(self) -> list[Forecast] | None:
forecasts.append(forecast)

return forecasts

@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
return self.forecast
6 changes: 3 additions & 3 deletions homeassistant/components/openweathermap/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def wind_bearing(self) -> float | str | None:
return self.coordinator.data[ATTR_API_WIND_BEARING]

@property
def forecast(self) -> list[Forecast] | None:
def _forecast(self) -> list[Forecast] | None:
"""Return the forecast array."""
api_forecasts = self.coordinator.data[ATTR_API_FORECAST]
forecasts = [
Expand All @@ -201,9 +201,9 @@ def forecast(self) -> list[Forecast] | None:
@callback
def _async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
return self.forecast
return self._forecast

@callback
def _async_forecast_hourly(self) -> list[Forecast] | None:
"""Return the hourly forecast in native units."""
return self.forecast
return self._forecast
29 changes: 0 additions & 29 deletions homeassistant/components/smhi/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,6 @@ async def retry_update(self, _: datetime) -> None:
"""Retry refresh weather forecast."""
await self.async_update(no_throttle=True)

@property
def forecast(self) -> list[Forecast] | None:
"""Return the forecast."""
if self._forecast_daily is None or len(self._forecast_daily) < 2:
return None

data: list[Forecast] = []

for forecast in self._forecast_daily[1:]:
condition = CONDITION_MAP.get(forecast.symbol)

data.append(
{
ATTR_FORECAST_TIME: forecast.valid_time.isoformat(),
ATTR_FORECAST_NATIVE_TEMP: forecast.temperature_max,
ATTR_FORECAST_NATIVE_TEMP_LOW: forecast.temperature_min,
ATTR_FORECAST_NATIVE_PRECIPITATION: forecast.total_precipitation,
ATTR_FORECAST_CONDITION: condition,
ATTR_FORECAST_NATIVE_PRESSURE: forecast.pressure,
ATTR_FORECAST_WIND_BEARING: forecast.wind_direction,
ATTR_FORECAST_NATIVE_WIND_SPEED: forecast.wind_speed,
ATTR_FORECAST_HUMIDITY: forecast.humidity,
ATTR_FORECAST_NATIVE_WIND_GUST_SPEED: forecast.wind_gust,
ATTR_FORECAST_CLOUD_COVERAGE: forecast.cloudiness,
}
)

return data

def _get_forecast_data(
self, forecast_data: list[SmhiForecast] | None
) -> list[Forecast] | None:
Expand Down