36
36
from .helpers import http_request
37
37
from .lock import TedeeLock , TedeeLockState
38
38
39
+ NUM_RETRIES = 3
39
40
_LOGGER = logging .getLogger (__name__ )
40
41
41
42
@@ -377,7 +378,10 @@ async def _local_api_call(
377
378
self , path : str , http_method : str , json_data = None
378
379
) -> tuple [bool , Any | None ]:
379
380
"""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 ):
381
385
try :
382
386
_LOGGER .debug ("Getting locks from Local API..." )
383
387
self ._last_local_call = time .time ()
@@ -389,15 +393,14 @@ async def _local_api_call(
389
393
self ._timeout ,
390
394
json_data ,
391
395
)
392
- return True , r
393
396
except TedeeAuthException as ex :
394
397
msg = "Local API authentication failed."
395
- if not self ._personal_token :
398
+ if not self ._personal_token and ( retry_number == NUM_RETRIES ) :
396
399
raise TedeeLocalAuthException (msg ) from ex
397
400
398
401
_LOGGER .debug (msg )
399
402
except (TedeeClientException , TedeeRateLimitException ) as ex :
400
- if not self ._personal_token :
403
+ if not self ._personal_token and ( retry_number == NUM_RETRIES ) :
401
404
_LOGGER .debug (
402
405
"Error while calling local API endpoint %s. Error: %s. Full error: %s" ,
403
406
path ,
@@ -415,6 +418,10 @@ async def _local_api_call(
415
418
type (ex ).__name__ ,
416
419
)
417
420
_LOGGER .debug ("Full error: %s" , str (ex ), exc_info = True )
421
+
422
+ else :
423
+ return True , r
424
+ await asyncio .sleep (0.5 )
418
425
return False , None
419
426
420
427
def parse_webhook_message (self , message : dict ) -> None :
0 commit comments