Avoid blocking the event loop when unloading Monoprice (#116141)
* Avoid blocking the event loop when unloading Monoprice * Code review suggestions
This commit is contained in:
parent
244433aeca
commit
97d151d1c6
1 changed files with 18 additions and 4 deletions
|
@ -57,11 +57,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
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][UNDO_UPDATE_LISTENER]()
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
if not unload_ok:
|
||||
return False
|
||||
|
||||
return unload_ok
|
||||
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||
|
||||
def _cleanup(monoprice) -> None:
|
||||
"""Destroy the Monoprice object.
|
||||
|
||||
Destroying the Monoprice closes the serial connection, do it in an executor so the garbage
|
||||
collection does not block.
|
||||
"""
|
||||
del monoprice
|
||||
|
||||
monoprice = hass.data[DOMAIN][entry.entry_id][MONOPRICE_OBJECT]
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
await hass.async_add_executor_job(_cleanup, monoprice)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue