Allow wemo config entry to be unloaded (#93082)

* Fix lingering timer in wemo

* Also stop the subscriptions
This commit is contained in:
epenet 2023-05-16 06:31:31 +02:00 committed by GitHub
parent 36332eb441
commit f6b700372a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -113,7 +113,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
wemo_dispatcher = WemoDispatcher(entry)
wemo_discovery = WemoDiscovery(hass, wemo_dispatcher, static_conf)
async def async_stop_wemo(event: Event) -> None:
async def async_stop_wemo(_: Event | None = None) -> None:
"""Shutdown Wemo subscriptions and subscription thread on exit."""
_LOGGER.debug("Shutting down WeMo event subscriptions")
await hass.async_add_executor_job(registry.stop)
@ -123,6 +123,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry.async_on_unload(
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop_wemo)
)
entry.async_on_unload(async_stop_wemo)
# Need to do this at least once in case statistics are defined and discovery is disabled
await wemo_discovery.discover_statics()
@ -133,6 +134,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a wemo config entry."""
# This makes sure that `entry.async_on_unload` routines run correctly on unload
return True
class WemoDispatcher:
"""Dispatch WeMo devices to the correct platform."""