Avoid closing shared aiohttp session in Vodafone Station (#146471)

This commit is contained in:
Simone Chemelli 2025-06-10 20:18:19 +03:00 committed by GitHub
parent d71ddcf69e
commit 936d56f9af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 27 deletions

View File

@ -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

View File

@ -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]}

View File

@ -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 = {