From 543348fe581645eee1ca5c5d3205c97e123fa974 Mon Sep 17 00:00:00 2001 From: Ruben van Dijk <15885455+RubenNL@users.noreply.github.com> Date: Sun, 11 May 2025 21:06:04 +0200 Subject: [PATCH] Close Octoprint aiohttp session on unload (#144670) --- homeassistant/components/octoprint/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/octoprint/__init__.py b/homeassistant/components/octoprint/__init__.py index 59fd04357eb..48d81b81f0c 100644 --- a/homeassistant/components/octoprint/__init__.py +++ b/homeassistant/components/octoprint/__init__.py @@ -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],