mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
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
f91266908d
commit
74f32cfa90
@ -57,11 +57,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
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)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
if not unload_ok:
|
||||||
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
return False
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
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:
|
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user