From 86cf2e29b2ba322ceac6d3b24f67c7bfd602a611 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 6 Oct 2023 17:10:19 +0200 Subject: [PATCH] Cancel callbacks on Withings entry unload (#101536) --- homeassistant/components/withings/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index 597517693c0..25965b30ce2 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -161,7 +161,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: webhook_name = "Withings" if entry.title != DEFAULT_TITLE: - webhook_name = " ".join([DEFAULT_TITLE, entry.title]) + webhook_name = f"{DEFAULT_TITLE} {entry.title}" webhook_register( hass, @@ -183,14 +183,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if state is cloud.CloudConnectionState.CLOUD_DISCONNECTED: await unregister_webhook(None) - async_call_later(hass, 30, register_webhook) + entry.async_on_unload(async_call_later(hass, 30, register_webhook)) if cloud.async_active_subscription(hass): if cloud.async_is_connected(hass): await register_webhook(None) - cloud.async_listen_connection_change(hass, manage_cloudhook) + entry.async_on_unload( + cloud.async_listen_connection_change(hass, manage_cloudhook) + ) else: - async_at_started(hass, register_webhook) + entry.async_on_unload(async_at_started(hass, register_webhook)) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) entry.async_on_unload(entry.add_update_listener(update_listener))