Skip to content

Commit

Permalink
add retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Mar 21, 2024
1 parent 031664a commit 01efb17
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions pytedee_async/tedee_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .helpers import http_request
from .lock import TedeeLock, TedeeLockState

NUM_RETRIES = 3
_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -377,7 +378,10 @@ async def _local_api_call(
self, path: str, http_method: str, json_data=None
) -> tuple[bool, Any | None]:
"""Call the local api"""
if self._use_local_api:

if not self._use_local_api:
return False, None
for retry_number in range(1, NUM_RETRIES + 1):
try:
_LOGGER.debug("Getting locks from Local API...")
self._last_local_call = time.time()
Expand All @@ -389,15 +393,14 @@ async def _local_api_call(
self._timeout,
json_data,
)
return True, r
except TedeeAuthException as ex:
msg = "Local API authentication failed."
if not self._personal_token:
if not self._personal_token and (retry_number == NUM_RETRIES):
raise TedeeLocalAuthException(msg) from ex

_LOGGER.debug(msg)
except (TedeeClientException, TedeeRateLimitException) as ex:
if not self._personal_token:
if not self._personal_token and (retry_number == NUM_RETRIES):
_LOGGER.debug(
"Error while calling local API endpoint %s. Error: %s. Full error: %s",
path,
Expand All @@ -415,6 +418,10 @@ async def _local_api_call(
type(ex).__name__,
)
_LOGGER.debug("Full error: %s", str(ex), exc_info=True)

else:
return True, r
await asyncio.sleep(0.5)
return False, None

def parse_webhook_message(self, message: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pytedee_async",
version="0.2.16",
version="0.2.17",
author="Josef Zweck",
author_email="[email protected]",
description="A Tedee Lock Client package",
Expand Down

0 comments on commit 01efb17

Please sign in to comment.