mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Implement retry for Netatmo webhook registration (#62597)
This commit is contained in:
parent
ee375ff42d
commit
c423b01eb0
@ -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()}
|
||||
|
Loading…
x
Reference in New Issue
Block a user