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

feat: remove deprecated ATTR_FORECAST #106

Merged
merged 3 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions custom_components/yandex_weather/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
ATTR_MIN_FORECAST_TEMPERATURE = "min_forecast_temperature"
ATTR_API_FORECAST_ICONS = "forecast_icons"

ATTR_FORECAST_DATA = "forecast_data"

CONF_UPDATES_PER_DAY = "updates_per_day"
CONF_IMAGE_SOURCE = "image_source"
CONF_LANGUAGE_KEY = "language"
Expand Down
8 changes: 4 additions & 4 deletions custom_components/yandex_weather/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import aiohttp
from homeassistant.components.weather import (
ATTR_FORECAST,
ATTR_FORECAST_CONDITION,
ATTR_FORECAST_IS_DAYTIME,
ATTR_FORECAST_NATIVE_PRECIPITATION,
Expand Down Expand Up @@ -44,6 +43,7 @@
ATTR_API_WIND_GUST,
ATTR_API_WIND_SPEED,
ATTR_API_YA_CONDITION,
ATTR_FORECAST_DATA,
ATTR_MIN_FORECAST_TEMPERATURE,
CONDITION_ICONS,
DOMAIN,
Expand Down Expand Up @@ -250,7 +250,7 @@ async def update(self):
tz=self.get_timezone(r["now_dt"], r["now"]),
),
ATTR_API_FORECAST_ICONS: [],
ATTR_FORECAST: [],
ATTR_FORECAST_DATA: [],
}
self.process_data(result, r["fact"], CURRENT_WEATHER_ATTRIBUTE_TRANSLATION)

Expand All @@ -260,11 +260,11 @@ async def update(self):
forecast = Forecast(datetime=f_datetime.isoformat())
self.process_data(forecast, f, FORECAST_ATTRIBUTE_TRANSLATION)
forecast[ATTR_FORECAST_IS_DAYTIME] = f["daytime"] == "d"
result[ATTR_FORECAST].append(forecast)
result[ATTR_FORECAST_DATA].append(forecast)
result[ATTR_API_FORECAST_ICONS].append(f.get("icon", "no_image"))

result[ATTR_MIN_FORECAST_TEMPERATURE] = self.get_min_forecast_temperature(
result[ATTR_FORECAST]
result[ATTR_FORECAST_DATA]
)

return result
Expand Down
9 changes: 4 additions & 5 deletions custom_components/yandex_weather/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging

from homeassistant.components.weather import (
ATTR_FORECAST,
ATTR_FORECAST_IS_DAYTIME,
ATTR_WEATHER_PRECIPITATION_UNIT,
ATTR_WEATHER_PRESSURE_UNIT,
Expand Down Expand Up @@ -45,6 +44,7 @@
ATTR_API_WIND_GUST,
ATTR_API_WIND_SPEED,
ATTR_API_YA_CONDITION,
ATTR_FORECAST_DATA,
ATTRIBUTION,
CONF_IMAGE_SOURCE,
DOMAIN,
Expand Down Expand Up @@ -144,7 +144,7 @@ async def async_added_to_hass(self) -> None:
self._attr_humidity = state.attributes.get("humidity")
self._attr_wind_bearing = state.attributes.get("wind_bearing")
self._attr_entity_picture = state.attributes.get("entity_picture")
self._twice_daily_forecast = state.attributes.get(ATTR_FORECAST, [])
self._twice_daily_forecast = state.attributes.get(ATTR_FORECAST_DATA, [])
for f in self._twice_daily_forecast:
for attribute, converter in [
("temperature", UNIT_CONVERSIONS[ATTR_WEATHER_TEMPERATURE_UNIT]),
Expand All @@ -167,7 +167,7 @@ async def async_added_to_hass(self) -> None:
)
except TypeError:
pass
self._attr_forecast = self._twice_daily_forecast # backward compatibility

self._attr_extra_state_attributes = {}
for attribute in [
"feels_like",
Expand Down Expand Up @@ -207,8 +207,7 @@ def _handle_coordinator_update(self) -> None:
is_day=self.coordinator.data.get("daytime") == "d",
image=self.coordinator.data.get(ATTR_API_IMAGE),
)
self._twice_daily_forecast = self.coordinator.data.get(ATTR_FORECAST, [])
self._attr_forecast = self._twice_daily_forecast # backward compatibility
self._twice_daily_forecast = self.coordinator.data.get(ATTR_FORECAST_DATA, [])
self._attr_humidity = self.coordinator.data.get(ATTR_API_HUMIDITY)
self._attr_native_pressure = self.coordinator.data.get(ATTR_API_PRESSURE)
self._attr_native_temperature = self.coordinator.data.get(ATTR_API_TEMPERATURE)
Expand Down
Loading