Skip to content

Commit

Permalink
fix: remove deprecated ATTR_FORECAST
Browse files Browse the repository at this point in the history
Fixes #105
  • Loading branch information
IATkachenko committed Mar 30, 2024
1 parent e8ceb97 commit 5061fd0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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
10 changes: 4 additions & 6 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 @@ -43,8 +42,7 @@
ATTR_API_WIND_BEARING,
ATTR_API_WIND_GUST,
ATTR_API_WIND_SPEED,
ATTR_API_YA_CONDITION,
ATTR_MIN_FORECAST_TEMPERATURE,
ATTR_API_YA_CONDITION, ATTR_FORECAST_DATA, ATTR_MIN_FORECAST_TEMPERATURE,
CONDITION_ICONS,
DOMAIN,
MANUFACTURER,
Expand Down Expand Up @@ -250,7 +248,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 +258,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
10 changes: 4 additions & 6 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,8 +44,7 @@
ATTR_API_WIND_GUST,
ATTR_API_WIND_SPEED,
ATTR_API_YA_CONDITION,
ATTRIBUTION,
CONF_IMAGE_SOURCE,
ATTRIBUTION, ATTR_FORECAST_DATA, CONF_IMAGE_SOURCE,
DOMAIN,
ENTRY_NAME,
UPDATER,
Expand Down Expand Up @@ -144,7 +142,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 +165,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,7 +205,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._twice_daily_forecast = self.coordinator.data.get(ATTR_FORECAST_DATA, [])
self._attr_forecast = self._twice_daily_forecast # backward compatibility
self._attr_humidity = self.coordinator.data.get(ATTR_API_HUMIDITY)
self._attr_native_pressure = self.coordinator.data.get(ATTR_API_PRESSURE)
Expand Down

0 comments on commit 5061fd0

Please sign in to comment.