From 1c8a34c3499dd608b0733ad88d3709febc2b6f10 Mon Sep 17 00:00:00 2001 From: ollo69 <60491700+ollo69@users.noreply.github.com> Date: Sun, 6 Feb 2022 09:35:49 +0100 Subject: [PATCH] Clean-up AsusWRT setup entry (#65860) --- homeassistant/components/asuswrt/__init__.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/asuswrt/__init__.py b/homeassistant/components/asuswrt/__init__.py index ec0162af915..1a680a7fb65 100644 --- a/homeassistant/components/asuswrt/__init__.py +++ b/homeassistant/components/asuswrt/__init__.py @@ -123,33 +123,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: router.async_on_close(entry.add_update_listener(update_listener)) - hass.config_entries.async_setup_platforms(entry, PLATFORMS) - async def async_close_connection(event): """Close AsusWrt connection on HA Stop.""" await router.close() - stop_listener = hass.bus.async_listen_once( - EVENT_HOMEASSISTANT_STOP, async_close_connection + entry.async_on_unload( + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_close_connection) ) - hass.data.setdefault(DOMAIN, {})[entry.entry_id] = { - DATA_ASUSWRT: router, - "stop_listener": stop_listener, - } + hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {DATA_ASUSWRT: router} + + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - - if unload_ok: - hass.data[DOMAIN][entry.entry_id]["stop_listener"]() + if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT] await router.close() - hass.data[DOMAIN].pop(entry.entry_id) return unload_ok