Close Octoprint aiohttp session on unload (#144670)

This commit is contained in:
Ruben van Dijk 2025-05-11 21:06:04 +02:00 committed by GitHub
parent 80a04314fc
commit 554cb27703
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -181,11 +181,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
session = aiohttp.ClientSession(connector=connector)
@callback
def _async_close_websession(event: Event) -> None:
def _async_close_websession(event: Event | None = None) -> None:
"""Close websession."""
session.detach()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_close_websession)
entry.async_on_unload(_async_close_websession)
entry.async_on_unload(
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, _async_close_websession)
)
client = OctoprintClient(
host=entry.data[CONF_HOST],