Skip to content

Commit

Permalink
Add retry for empty responses (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
amosyuen committed Feb 2, 2023
1 parent a04f43f commit 7f953a8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
4 changes: 1 addition & 3 deletions custom_components/tplink_deco/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from cryptography.hazmat.primitives.ciphers import modes
from homeassistant.exceptions import ConfigEntryAuthFailed

from .exceptions import AuthException

TIMEOUT = 30

AES_KEY_BYTES = 16
Expand Down Expand Up @@ -400,7 +398,7 @@ async def _async_post(
"%s 403 error: %s. Likely caused by logging in with admin account on another device. See https://github.com/amosyuen/ha-tplink-deco#login-credentials."
% (context, err)
)
raise AuthException(message) from err
raise ConfigEntryAuthFailed(message) from err
raise err
except aiohttp.ClientError as err:
_LOGGER.error(
Expand Down
10 changes: 4 additions & 6 deletions custom_components/tplink_deco/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .const import DOMAIN
from .const import SIGNAL_CLIENT_ADDED
from .const import SIGNAL_DECO_ADDED
from .exceptions import AuthException

_LOGGER: logging.Logger = logging.getLogger(__package__)

Expand All @@ -41,16 +40,15 @@ def snake_case_to_title_space(str):
return " ".join([w.title() for w in str.split("_")])


async def async_call_with_retry(api, func, args=[]):
async def async_call_with_retry(api, func, args):
if args is None:
args = []
try:
return await func(*args)
except AuthException:
except ConfigEntryAuthFailed:
api.clear_auth()
# Retry for auth exception in case is a token expired case
return await func(*args)
except ConfigEntryAuthFailed:
api.clear_auth()
raise
except asyncio.TimeoutError:
# Retry for timeouts
return await func(*args)
Expand Down
2 changes: 0 additions & 2 deletions custom_components/tplink_deco/exceptions.py

This file was deleted.

2 changes: 1 addition & 1 deletion custom_components/tplink_deco/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"reauth_confirm": {
"description": "Problem with login credentials. See https://github.com/amosyuen/ha-tplink-deco#login-credentials",
"description": "Problem with login credentials. Maybe caused by logging in on separate device. See https://github.com/amosyuen/ha-tplink-deco#login-credentials",
"data": {
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tplink_deco/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"reauth_confirm": {
"description": "Problem with login credentials. See https://github.com/amosyuen/ha-tplink-deco#login-credentials",
"description": "Problem with login credentials. Maybe caused by logging in on separate device. See https://github.com/amosyuen/ha-tplink-deco#login-credentials",
"data": {
"username": "Username",
"password": "Password"
Expand Down

0 comments on commit 7f953a8

Please sign in to comment.