Implement retry for Netatmo webhook registration (#62597)

This commit is contained in:
Tobias Sauerwein 2022-01-04 16:52:27 +01:00 committed by GitHub
parent ee375ff42d
commit c423b01eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()}