Skip to content

Commit

Permalink
Potential epoch fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Dec 26, 2024
1 parent 757af97 commit d33051b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test.py
test*.py
register.py
*.pyc
__pycache__
Expand Down
11 changes: 9 additions & 2 deletions tesla_fleet_api/vehiclesigned.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.serialization import PublicFormat, Encoding

from .exceptions import MESSAGE_FAULTS
from .exceptions import MESSAGE_FAULTS, TeslaFleetMessageFaultIncorrectEpoch

from .const import (
LOGGER,
Expand All @@ -23,6 +23,7 @@

from .pb2.universal_message_pb2 import (
# OPERATIONSTATUS_OK,
MESSAGEFAULT_ERROR_INCORRECT_EPOCH,
OPERATIONSTATUS_WAIT,
OPERATIONSTATUS_ERROR,
DOMAIN_VEHICLE_SECURITY,
Expand Down Expand Up @@ -273,7 +274,13 @@ async def _send(self, domain: int, command: bytes) -> dict[str, Any]:

msg.signature_data.CopyFrom(signature)

resp = await self._signed_message(msg)
try:
resp = await self._signed_message(msg)
except TeslaFleetMessageFaultIncorrectEpoch:
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)

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

0 comments on commit d33051b

Please sign in to comment.