3636from .helpers import http_request
3737from .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 :
0 commit comments