Skip to content

Commit

Permalink
Cancel callbacks on Withings entry unload (#101536)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored and frenck committed Oct 6, 2023
1 parent 6c2d1e2 commit 7369ae8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions homeassistant/components/withings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def register_webhook(

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,
Expand All @@ -183,14 +183,16 @@ async def manage_cloudhook(state: cloud.CloudConnectionState) -> None:

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))
Expand Down

0 comments on commit 7369ae8

Please sign in to comment.