Skip to content

Commit

Permalink
Limit retries to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Dec 26, 2024
1 parent d33051b commit 45b8388
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tesla_fleet_api/vehiclesigned.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def _sendInfotainment(self, command: Action) -> dict[str, Any]:
await self._handshake(DOMAIN_INFOTAINMENT)
return await self._send(DOMAIN_INFOTAINMENT, command.SerializeToString())

async def _send(self, domain: int, command: bytes) -> dict[str, Any]:
async def _send(self, domain: int, command: bytes, attempt: int = 1) -> dict[str, Any]:
"""Send a signed message to the vehicle."""
LOGGER.debug(f"Sending to domain {Domain.Name(domain)}")
msg = RoutableMessage()
Expand Down Expand Up @@ -276,11 +276,15 @@ async def _send(self, domain: int, command: bytes) -> dict[str, Any]:

try:
resp = await self._signed_message(msg)
except TeslaFleetMessageFaultIncorrectEpoch:
except TeslaFleetMessageFaultIncorrectEpoch as e:
attempt += 1
if attempt > 3:
# We tried 3 times, give up, raise the error
raise e
LOGGER.info(f"Session expired, starting new handshake with {Domain.Name(domain)}")
await self._handshake(domain)
LOGGER.info(f"Handshake complete, retrying message to {Domain.Name(domain)}")
return await self._send(domain, command)
return await self._send(domain, command, attempt)

if resp.signedMessageStatus.operation_status == OPERATIONSTATUS_WAIT:
return {"response": {"result": False}}
Expand Down

0 comments on commit 45b8388

Please sign in to comment.