From 88995b5276ba21c143ad232b43b0c470ffb1447a Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Sat, 22 Jun 2024 11:46:01 -0600 Subject: [PATCH] Handle cleanup of config entry --- custom_components/tapo_control/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/tapo_control/__init__.py b/custom_components/tapo_control/__init__.py index 6a24959..7f87645 100644 --- a/custom_components/tapo_control/__init__.py +++ b/custom_components/tapo_control/__init__.py @@ -285,6 +285,8 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: LOGGER.debug("Deleting hot storage files for entity " + entry_id + "...") deleteDir(hotDirPath) + # Remove the entry data + hass.data[DOMAIN].pop(entry_id, None) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): if PYTAPO_REQUIRED_VERSION != PYTAPO_VERSION: @@ -513,10 +515,12 @@ async def async_update_data(): and hass.data[DOMAIN][entry.entry_id]["mediaSyncScheduled"] is False ): hass.data[DOMAIN][entry.entry_id]["mediaSyncScheduled"] = True - async_track_time_interval( - hass, - mediaSync, - timedelta(seconds=60), + entry.async_on_unload( + async_track_time_interval( + hass, + mediaSync, + timedelta(seconds=60), + ) ) elif ( hass.data[DOMAIN][entry.entry_id]["initialMediaScanRunning"]