From 936d56f9af069ac85a486178ff0e40730bc13e56 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Tue, 10 Jun 2025 20:18:19 +0300 Subject: [PATCH] Avoid closing shared aiohttp session in Vodafone Station (#146471) --- .../components/vodafone_station/__init__.py | 1 - .../vodafone_station/config_flow.py | 1 - .../vodafone_station/coordinator.py | 47 +++++++++---------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/vodafone_station/__init__.py b/homeassistant/components/vodafone_station/__init__.py index 5efc33ca882..17b0fe6e501 100644 --- a/homeassistant/components/vodafone_station/__init__.py +++ b/homeassistant/components/vodafone_station/__init__.py @@ -37,7 +37,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: VodafoneConfigEntry) -> if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): coordinator = entry.runtime_data await coordinator.api.logout() - await coordinator.api.close() return unload_ok diff --git a/homeassistant/components/vodafone_station/config_flow.py b/homeassistant/components/vodafone_station/config_flow.py index b69078b8ce6..c330a93a1a8 100644 --- a/homeassistant/components/vodafone_station/config_flow.py +++ b/homeassistant/components/vodafone_station/config_flow.py @@ -48,7 +48,6 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, await api.login() finally: await api.logout() - await api.close() return {"title": data[CONF_HOST]} diff --git a/homeassistant/components/vodafone_station/coordinator.py b/homeassistant/components/vodafone_station/coordinator.py index 846d4b042c0..57d39151160 100644 --- a/homeassistant/components/vodafone_station/coordinator.py +++ b/homeassistant/components/vodafone_station/coordinator.py @@ -117,32 +117,29 @@ class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]): async def _async_update_data(self) -> UpdateCoordinatorDataType: """Update router data.""" _LOGGER.debug("Polling Vodafone Station host: %s", self._host) + try: - try: - await self.api.login() - raw_data_devices = await self.api.get_devices_data() - data_sensors = await self.api.get_sensor_data() - await self.api.logout() - except exceptions.CannotAuthenticate as err: - raise ConfigEntryAuthFailed( - translation_domain=DOMAIN, - translation_key="cannot_authenticate", - translation_placeholders={"error": repr(err)}, - ) from err - except ( - exceptions.CannotConnect, - exceptions.AlreadyLogged, - exceptions.GenericLoginError, - JSONDecodeError, - ) as err: - raise UpdateFailed( - translation_domain=DOMAIN, - translation_key="update_failed", - translation_placeholders={"error": repr(err)}, - ) from err - except (ConfigEntryAuthFailed, UpdateFailed): - await self.api.close() - raise + await self.api.login() + raw_data_devices = await self.api.get_devices_data() + data_sensors = await self.api.get_sensor_data() + await self.api.logout() + except exceptions.CannotAuthenticate as err: + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="cannot_authenticate", + translation_placeholders={"error": repr(err)}, + ) from err + except ( + exceptions.CannotConnect, + exceptions.AlreadyLogged, + exceptions.GenericLoginError, + JSONDecodeError, + ) as err: + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="update_failed", + translation_placeholders={"error": repr(err)}, + ) from err utc_point_in_time = dt_util.utcnow() data_devices = {