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

Change Home Assistant's depracated forecast property. #1

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
ATTR_WEATHER_PRESSURE,
ATTR_FORECAST_NATIVE_TEMP_LOW,
WeatherEntity,
WeatherEntityFeature,
Forecast,
)

from awesomeversion import AwesomeVersion
Expand Down Expand Up @@ -45,6 +47,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class FMIWeatherEntity(CoordinatorEntity, WeatherEntity):
"""Define an FMI Weather Entity."""

_attr_supported_features = (
WeatherEntityFeature.FORECAST_HOURLY |
WeatherEntityFeature.FORECAST_DAILY
)

def __init__(self, name, coordinator, daily_mode):
"""Initialize FMI weather object."""
super().__init__(coordinator)
Expand Down Expand Up @@ -181,8 +188,7 @@ def condition(self):

return get_weather_symbol(self._fmi.current.data.symbol.value, self._fmi.hass)

@property
def forecast(self):
def _forecast(self, daily_mode: bool = False) -> list[Forecast] | None:
"""Return the forecast array."""
if self._fmi is None:
_LOGGER.debug("FMI: Coordinator is not available!")
Expand All @@ -191,7 +197,7 @@ def forecast(self):
if self._fmi.forecast is None:
return None

if self._daily_mode:
if daily_mode or self._daily_mode:
# Daily mode, aggregate forecast for every day
day = 0
data = []
Expand Down Expand Up @@ -239,3 +245,20 @@ def forecast(self):
)

return data

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

async def async_forecast_hourly(self) -> list[Forecast] | None:
"""Return the hourly forecast in native units."""
return self._forecast()

async def async_forecast_daily(self) -> list[Forecast] | None:
"""Return the daily forecast in native units."""
return self._forecast(daily_mode=True)

async def async_update(self) -> None:
"""Get the latest weather data."""
await self._fmi.async_refresh()