From 3eea61361c3adb3cfc835c673587a400f4689403 Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Wed, 26 Oct 2022 17:42:15 +0200 Subject: [PATCH] Clean up velbus cache folder only on removal of the config entry (#81031) --- homeassistant/components/velbus/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index 585e093a42c5..2ac751e283d0 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -175,14 +175,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: - """Remove the velbus connection.""" + """Unload (close) the velbus connection.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) await hass.data[DOMAIN][entry.entry_id]["cntrl"].stop() hass.data[DOMAIN].pop(entry.entry_id) - await hass.async_add_executor_job( - shutil.rmtree, - hass.config.path(STORAGE_DIR, f"velbuscache-{entry.entry_id}"), - ) if not hass.data[DOMAIN]: hass.data.pop(DOMAIN) hass.services.async_remove(DOMAIN, SERVICE_SCAN) @@ -190,3 +186,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.services.async_remove(DOMAIN, SERVICE_SET_MEMO_TEXT) hass.services.async_remove(DOMAIN, SERVICE_CLEAR_CACHE) return unload_ok + + +async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: + """Remove the velbus entry, so we also have to cleanup the cache dir.""" + await hass.async_add_executor_job( + shutil.rmtree, + hass.config.path(STORAGE_DIR, f"velbuscache-{entry.entry_id}"), + )