From e6c9a82b5f62e7abe2c7043bc29e8fe3e383a1fd Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sat, 30 Sep 2023 02:12:44 -0400 Subject: [PATCH] Improve conditional on unload (#101149) --- homeassistant/components/zwave_js/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zwave_js/__init__.py b/homeassistant/components/zwave_js/__init__.py index b9a26630406..c9decc92a67 100644 --- a/homeassistant/components/zwave_js/__init__.py +++ b/homeassistant/components/zwave_js/__init__.py @@ -915,6 +915,7 @@ async def disconnect_client(hass: HomeAssistant, entry: ConfigEntry) -> None: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" info = hass.data[DOMAIN][entry.entry_id] + client: ZwaveClient = info[DATA_CLIENT] driver_events: DriverEvents = info[DATA_DRIVER_EVENTS] tasks: list[Coroutine] = [ @@ -925,8 +926,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: unload_ok = all(await asyncio.gather(*tasks)) if tasks else True - if hasattr(driver_events, "driver"): - await async_disable_server_logging_if_needed(hass, entry, driver_events.driver) + if client.connected and client.driver: + await async_disable_server_logging_if_needed(hass, entry, client.driver) if DATA_CLIENT_LISTEN_TASK in info: await disconnect_client(hass, entry)