Improve conditional on unload (#101149)

This commit is contained in:
Raman Gupta 2023-09-30 02:12:44 -04:00 committed by GitHub
parent 6e3c704a33
commit e6c9a82b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -915,6 +915,7 @@ async def disconnect_client(hass: HomeAssistant, entry: ConfigEntry) -> None:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry.""" """Unload a config entry."""
info = hass.data[DOMAIN][entry.entry_id] info = hass.data[DOMAIN][entry.entry_id]
client: ZwaveClient = info[DATA_CLIENT]
driver_events: DriverEvents = info[DATA_DRIVER_EVENTS] driver_events: DriverEvents = info[DATA_DRIVER_EVENTS]
tasks: list[Coroutine] = [ 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 unload_ok = all(await asyncio.gather(*tasks)) if tasks else True
if hasattr(driver_events, "driver"): if client.connected and client.driver:
await async_disable_server_logging_if_needed(hass, entry, driver_events.driver) await async_disable_server_logging_if_needed(hass, entry, client.driver)
if DATA_CLIENT_LISTEN_TASK in info: if DATA_CLIENT_LISTEN_TASK in info:
await disconnect_client(hass, entry) await disconnect_client(hass, entry)