From 5061fd051ae69d1e7d87ab7a7bb269f860740792 Mon Sep 17 00:00:00 2001 From: IATkachenko Date: Sat, 30 Mar 2024 20:17:41 +0300 Subject: [PATCH 1/3] fix: remove deprecated ATTR_FORECAST Fixes #105 --- custom_components/yandex_weather/const.py | 2 ++ custom_components/yandex_weather/updater.py | 10 ++++------ custom_components/yandex_weather/weather.py | 10 ++++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/custom_components/yandex_weather/const.py b/custom_components/yandex_weather/const.py index 697041e..2bf334a 100644 --- a/custom_components/yandex_weather/const.py +++ b/custom_components/yandex_weather/const.py @@ -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" diff --git a/custom_components/yandex_weather/updater.py b/custom_components/yandex_weather/updater.py index 7ac69ce..227a96d 100644 --- a/custom_components/yandex_weather/updater.py +++ b/custom_components/yandex_weather/updater.py @@ -11,7 +11,6 @@ import aiohttp from homeassistant.components.weather import ( - ATTR_FORECAST, ATTR_FORECAST_CONDITION, ATTR_FORECAST_IS_DAYTIME, ATTR_FORECAST_NATIVE_PRECIPITATION, @@ -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, @@ -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) @@ -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 diff --git a/custom_components/yandex_weather/weather.py b/custom_components/yandex_weather/weather.py index 8f4e54e..f24eecf 100644 --- a/custom_components/yandex_weather/weather.py +++ b/custom_components/yandex_weather/weather.py @@ -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, @@ -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, @@ -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]), @@ -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", @@ -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) From 41aab50498e9bce920010c28c2ba2bb3968ff0af Mon Sep 17 00:00:00 2001 From: IATkachenko Date: Sat, 30 Mar 2024 20:22:58 +0300 Subject: [PATCH 2/3] remove _attr_forecast too --- custom_components/yandex_weather/weather.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/yandex_weather/weather.py b/custom_components/yandex_weather/weather.py index f24eecf..02dd19c 100644 --- a/custom_components/yandex_weather/weather.py +++ b/custom_components/yandex_weather/weather.py @@ -44,7 +44,9 @@ ATTR_API_WIND_GUST, ATTR_API_WIND_SPEED, ATTR_API_YA_CONDITION, - ATTRIBUTION, ATTR_FORECAST_DATA, CONF_IMAGE_SOURCE, + ATTRIBUTION, + ATTR_FORECAST_DATA, + CONF_IMAGE_SOURCE, DOMAIN, ENTRY_NAME, UPDATER, @@ -206,7 +208,6 @@ def _handle_coordinator_update(self) -> None: image=self.coordinator.data.get(ATTR_API_IMAGE), ) 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) self._attr_native_temperature = self.coordinator.data.get(ATTR_API_TEMPERATURE) From 00a9e6818f6ab33e22ca5c39a50490bde940ed4e Mon Sep 17 00:00:00 2001 From: IATkachenko Date: Sat, 30 Mar 2024 20:30:44 +0300 Subject: [PATCH 3/3] style: turn to black --- custom_components/yandex_weather/updater.py | 4 +++- custom_components/yandex_weather/weather.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/custom_components/yandex_weather/updater.py b/custom_components/yandex_weather/updater.py index 227a96d..1463e33 100644 --- a/custom_components/yandex_weather/updater.py +++ b/custom_components/yandex_weather/updater.py @@ -42,7 +42,9 @@ ATTR_API_WIND_BEARING, ATTR_API_WIND_GUST, ATTR_API_WIND_SPEED, - ATTR_API_YA_CONDITION, ATTR_FORECAST_DATA, ATTR_MIN_FORECAST_TEMPERATURE, + ATTR_API_YA_CONDITION, + ATTR_FORECAST_DATA, + ATTR_MIN_FORECAST_TEMPERATURE, CONDITION_ICONS, DOMAIN, MANUFACTURER, diff --git a/custom_components/yandex_weather/weather.py b/custom_components/yandex_weather/weather.py index 02dd19c..c7283db 100644 --- a/custom_components/yandex_weather/weather.py +++ b/custom_components/yandex_weather/weather.py @@ -44,8 +44,8 @@ ATTR_API_WIND_GUST, ATTR_API_WIND_SPEED, ATTR_API_YA_CONDITION, - ATTRIBUTION, ATTR_FORECAST_DATA, + ATTRIBUTION, CONF_IMAGE_SOURCE, DOMAIN, ENTRY_NAME,