Skip to content

Commit 45b8388

Browse files
committed
Limit retries to 3
1 parent d33051b commit 45b8388

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tesla_fleet_api/vehiclesigned.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async def _sendInfotainment(self, command: Action) -> dict[str, Any]:
234234
await self._handshake(DOMAIN_INFOTAINMENT)
235235
return await self._send(DOMAIN_INFOTAINMENT, command.SerializeToString())
236236

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

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

285289
if resp.signedMessageStatus.operation_status == OPERATIONSTATUS_WAIT:
286290
return {"response": {"result": False}}

0 commit comments

Comments
 (0)