Skip to content

Commit

Permalink
Fix signing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Feb 4, 2025
1 parent c67b5be commit 074c975
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions tesla_fleet_api/vehiclesigned.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
Response,
Action,
MediaPlayAction,
ResultReason,
VehicleAction,
VehicleControlFlashLightsAction,
ChargingStartStopAction,
Expand Down Expand Up @@ -95,8 +94,6 @@
SIGNATURE_TYPE_HMAC_PERSONALIZED,
TAG_DOMAIN,
TAG_SIGNATURE_TYPE,
KeyIdentity,
SignatureData,
SessionInfo,
HMAC_Personalized_Signature_Data,
TAG_PERSONALIZATION,
Expand All @@ -107,7 +104,6 @@
)
from .pb2.common_pb2 import (
Void,
LatLong,
PreconditioningTimes,
OffPeakChargingTimes,
# ChargeSchedule,
Expand Down Expand Up @@ -152,7 +148,7 @@ def update(self, sessionInfo: SessionInfo, privateKey: ec.EllipticCurvePrivateKe

def get(self) -> HMAC_Personalized_Signature_Data:
"""Sign a command and return session metadata"""
self.counter += 1
self.counter = self.counter+1
return HMAC_Personalized_Signature_Data(
epoch=self.epoch,
counter=self.counter,
Expand Down Expand Up @@ -300,18 +296,18 @@ async def _sign(
await sleep(2)
return await self._sign(domain, command, attempt)

if resp.HasField("signedMessageStatus"):
if resp.HasField("protobuf_message_as_bytes"):
if(resp.from_destination.domain == DOMAIN_VEHICLE_SECURITY):
vcsec = FromVCSECMessage.FromString(resp.protobuf_message_as_bytes)
LOGGER.debug("VCSEC Response: %s", vcsec)
if vcsec.HasField("nominalError"):
LOGGER.error("Command failed with reason: %s", vcsec.nominalError.genericError)
return {
"response": {
"result": False,
"reason": GenericError_E.Name(vcsec.nominalError.genericError)
"result": False,
"reason": GenericError_E.Name(vcsec.nominalError.genericError)
}
}
}
elif vcsec.commandStatus.operationStatus == OPERATIONSTATUS_OK:
return {"response": {"result": True, "reason": ""}}
elif vcsec.commandStatus.operationStatus == OPERATIONSTATUS_WAIT:
Expand All @@ -323,7 +319,7 @@ async def _sign(
await sleep(2)
return await self._sign(domain, command, attempt)
elif vcsec.commandStatus.operationStatus == OPERATIONSTATUS_ERROR:
if(vcsec.commandStatus.signedMessageStatus):
if(resp.HasField("signedMessageStatus")):
raise SIGNED_MESSAGE_INFORMATION_FAULTS[vcsec.commandStatus.signedMessageStatus.signedMessageInformation]

elif(resp.from_destination.domain == DOMAIN_INFOTAINMENT):
Expand All @@ -345,7 +341,7 @@ async def _sign(
}
}

return {"response": {"result": None, "reason": "No Response"}}
return {"response": {"result": True, "reason": ""}}

async def actuate_trunk(self, which_trunk: Trunk | str) -> dict[str, Any]:
"""Controls the front or rear trunk."""
Expand Down Expand Up @@ -1023,6 +1019,7 @@ async def sun_roof_control(self, state: str | SunRoofCommand) -> dict[str, Any]:
"""Controls the panoramic sunroof on the Model S."""
if isinstance(state, SunRoofCommand):
state = state.value
action = VehicleControlSunroofOpenCloseAction()
match state:
case "vent":
action = VehicleControlSunroofOpenCloseAction(vent=Void())
Expand All @@ -1034,9 +1031,7 @@ async def sun_roof_control(self, state: str | SunRoofCommand) -> dict[str, Any]:
return await self._sendInfotainment(
Action(
vehicleAction=VehicleAction(
vehicleControlSunroofOpenCloseAction=VehicleControlSunroofOpenCloseAction(
state=state
)
vehicleControlSunroofOpenCloseAction=action
)
)
)
Expand All @@ -1052,10 +1047,8 @@ async def trigger_homelink(
"""Turns on HomeLink (used to open and close garage doors)."""
action = VehicleControlTriggerHomelinkAction()
if lat is not None and lon is not None:
location = LatLong()
location.latitude = lat
location.longitude = lon
action.location = location
action.location.latitude = lat
action.location.longitude = lon
if token is not None:
action.token = token

Expand Down

0 comments on commit 074c975

Please sign in to comment.