mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Clean-up AsusWRT setup entry (#65860)
This commit is contained in:
parent
72601ccf32
commit
1c8a34c349
@ -123,33 +123,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
router.async_on_close(entry.add_update_listener(update_listener))
|
router.async_on_close(entry.add_update_listener(update_listener))
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
|
||||||
|
|
||||||
async def async_close_connection(event):
|
async def async_close_connection(event):
|
||||||
"""Close AsusWrt connection on HA Stop."""
|
"""Close AsusWrt connection on HA Stop."""
|
||||||
await router.close()
|
await router.close()
|
||||||
|
|
||||||
stop_listener = hass.bus.async_listen_once(
|
entry.async_on_unload(
|
||||||
EVENT_HOMEASSISTANT_STOP, async_close_connection
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_close_connection)
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {DATA_ASUSWRT: router}
|
||||||
DATA_ASUSWRT: router,
|
|
||||||
"stop_listener": stop_listener,
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
}
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
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."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||||
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN][entry.entry_id]["stop_listener"]()
|
|
||||||
router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT]
|
router = hass.data[DOMAIN][entry.entry_id][DATA_ASUSWRT]
|
||||||
await router.close()
|
await router.close()
|
||||||
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
Loading…
x
Reference in New Issue
Block a user