From c423b01eb08c5c1a80eb0b861d8e46017ae4a540 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Tue, 4 Jan 2022 16:52:27 +0100 Subject: [PATCH] Implement retry for Netatmo webhook registration (#62597) --- homeassistant/components/netatmo/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/homeassistant/components/netatmo/__init__.py b/homeassistant/components/netatmo/__init__.py index 1e1cde039f0..130cd9a8938 100644 --- a/homeassistant/components/netatmo/__init__.py +++ b/homeassistant/components/netatmo/__init__.py @@ -73,6 +73,8 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) +MAX_WEBHOOK_RETRIES = 3 + async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Netatmo component.""" @@ -146,6 +148,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.config_entries.async_setup_platforms(entry, PLATFORMS) + _webhook_retries = 0 + async def unregister_webhook(call: ServiceCall | None) -> None: if CONF_WEBHOOK_ID not in entry.data: return @@ -163,6 +167,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: "No webhook to be dropped for %s", entry.data[CONF_WEBHOOK_ID] ) + nonlocal _webhook_retries + if _webhook_retries < MAX_WEBHOOK_RETRIES: + _webhook_retries += 1 + async_call_later(hass, 30, register_webhook) + async def register_webhook(call: ServiceCall | None) -> None: if CONF_WEBHOOK_ID not in entry.data: data = {**entry.data, CONF_WEBHOOK_ID: secrets.token_hex()}