Skip to content

Commit

Permalink
Add: Retry 3 times on update failure before raising reauth request
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Nov 19, 2023
1 parent eeee05b commit d62c505
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/tapo_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,18 @@ async def async_update_data():
updateDataForAllControllers[controller] = await getCamData(
hass, controller
)
hass.data[DOMAIN][entry.entry_id]["reauth_retries"] = 0
except Exception as e:
updateDataForAllControllers[controller] = False
if str(e) == "Invalid authentication data":
hass.data[DOMAIN][entry.entry_id]["refreshEnabled"] = False
raise ConfigEntryAuthFailed(e)
if hass.data[DOMAIN][entry.entry_id]["reauth_retries"] < 3:
hass.data[DOMAIN][entry.entry_id]["reauth_retries"] += 1
raise e
else:
hass.data[DOMAIN][entry.entry_id][
"refreshEnabled"
] = False
raise ConfigEntryAuthFailed(e)
LOGGER.error(e)

hass.data[DOMAIN][entry.entry_id][
Expand Down Expand Up @@ -552,6 +559,7 @@ async def async_update_data():

hass.data[DOMAIN][entry.entry_id] = {
"setup_retries": 0,
"reauth_retries": 0,
"runningMediaSync": False,
"controller": tapoController,
"entry": entry,
Expand Down

0 comments on commit d62c505

Please sign in to comment.