Skip to content

Commit 01efb17

Browse files
committed
add retry logic
1 parent 031664a commit 01efb17

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pytedee_async/tedee_client.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from .helpers import http_request
3737
from .lock import TedeeLock, TedeeLockState
3838

39+
NUM_RETRIES = 3
3940
_LOGGER = logging.getLogger(__name__)
4041

4142

@@ -377,7 +378,10 @@ async def _local_api_call(
377378
self, path: str, http_method: str, json_data=None
378379
) -> tuple[bool, Any | None]:
379380
"""Call the local api"""
380-
if self._use_local_api:
381+
382+
if not self._use_local_api:
383+
return False, None
384+
for retry_number in range(1, NUM_RETRIES + 1):
381385
try:
382386
_LOGGER.debug("Getting locks from Local API...")
383387
self._last_local_call = time.time()
@@ -389,15 +393,14 @@ async def _local_api_call(
389393
self._timeout,
390394
json_data,
391395
)
392-
return True, r
393396
except TedeeAuthException as ex:
394397
msg = "Local API authentication failed."
395-
if not self._personal_token:
398+
if not self._personal_token and (retry_number == NUM_RETRIES):
396399
raise TedeeLocalAuthException(msg) from ex
397400

398401
_LOGGER.debug(msg)
399402
except (TedeeClientException, TedeeRateLimitException) as ex:
400-
if not self._personal_token:
403+
if not self._personal_token and (retry_number == NUM_RETRIES):
401404
_LOGGER.debug(
402405
"Error while calling local API endpoint %s. Error: %s. Full error: %s",
403406
path,
@@ -415,6 +418,10 @@ async def _local_api_call(
415418
type(ex).__name__,
416419
)
417420
_LOGGER.debug("Full error: %s", str(ex), exc_info=True)
421+
422+
else:
423+
return True, r
424+
await asyncio.sleep(0.5)
418425
return False, None
419426

420427
def parse_webhook_message(self, message: dict) -> None:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pytedee_async",
8-
version="0.2.16",
8+
version="0.2.17",
99
author="Josef Zweck",
1010
author_email="[email protected]",
1111
description="A Tedee Lock Client package",

0 commit comments

Comments
 (0)