Skip to content

Commit 9a5d089

Browse files
committed
Minor fixes
1 parent 5338af7 commit 9a5d089

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

tesla_fleet_api/teslafleetapi.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,24 @@ async def _request(
106106
if access_token := await self.refresh_hook():
107107
self.access_token = access_token
108108

109+
headers = {
110+
"Authorization": f"Bearer {self.access_token}",
111+
"X-Library": f"python tesla_fleet_api {VERSION}",
112+
}
113+
109114
# Remove None values from params and json
110115
if params:
111116
params = {k: v for k, v in params.items() if v is not None}
112117
LOGGER.debug("Parameters: %s", params)
113118
if json:
114119
json = {k: v for k, v in json.items() if v is not None}
115120
LOGGER.debug("Body: %s", dumps(json))
121+
headers["Content-Type"] = "application/json"
116122

117123
async with self.session.request(
118124
method,
119125
f"{self.server}/{path}",
120-
headers={
121-
"Authorization": f"Bearer {self.access_token}",
122-
"Content-Type": "application/json",
123-
"X-Library": f"python tesla_fleet_api {VERSION}",
124-
},
126+
headers=headers,
125127
json=json,
126128
params=params,
127129
) as resp:

tesla_fleet_api/teslafleetoauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_login_url(self, scopes: list[Scope], state: str = "login") -> str:
4545
"""Get the login URL."""
4646
if self.redirect_uri is None:
4747
raise ValueError("Redirect URI is missing")
48-
return f"https://auth.tesla.com/oauth2/v3/authorize?response_type=code&prompt=login&client_id={self.client_id}&redirect_uri={self.redirect_uri}&scope={'+'.join(scopes)}&state={state}"
48+
return f"https://auth.tesla.com/oauth2/v3/authorize?response_type=code&client_id={self.client_id}&redirect_uri={self.redirect_uri}&scope={'+'.join(scopes)}&state={state}"
4949

5050
async def get_refresh_token(self, code: str) -> None:
5151
"""Get the refresh token."""

tesla_fleet_api/teslemetry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ async def server_side_polling(
9696
)
9797
).get("response")
9898

99-
async def vehicle_force_refresh(self, vin: str) -> dict[str, Any]:
99+
async def vehicle_data_refresh(self, vin: str) -> dict[str, Any]:
100100
"""Force a refresh of the vehicle data."""
101101
return await self._request(
102102
Method.GET,
103-
f"api/force/{vin}",
103+
f"api/refresh/{vin}",
104104
)
105105

106106
async def _request(

tesla_fleet_api/vehicle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def specific_signed(
4444

4545
def pre2021(self, vin: str) -> bool:
4646
"""Checks if a vehicle is a pre-2021 model S or X."""
47-
return vin[9] <= "L" and vin[3] in ["S", "X"]
47+
return vin[3] in ["S", "X"] and (vin[9] <= "L" or (vin[9] == "M" and vin[7] in ['1', '2', '3', '4']))
4848

4949
async def actuate_trunk(
5050
self, vehicle_tag: str | int, which_trunk: Trunk | str

tesla_fleet_api/vehiclesigned.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
from .vehiclespecific import VehicleSpecific
2323

2424
from .pb2.universal_message_pb2 import (
25-
# OPERATIONSTATUS_OK,
26-
MESSAGEFAULT_ERROR_INCORRECT_EPOCH,
2725
OPERATIONSTATUS_WAIT,
2826
OPERATIONSTATUS_ERROR,
2927
DOMAIN_VEHICLE_SECURITY,
3028
DOMAIN_INFOTAINMENT,
3129
Domain,
32-
# MessageFault_E,
3330
RoutableMessage,
3431
)
3532
from .pb2.car_server_pb2 import (
@@ -215,9 +212,10 @@ async def _handshake(self, domain: int) -> None:
215212
ec.SECP256R1(), vehicle_public_key
216213
),
217214
)
215+
key = hashlib.sha1(shared).digest()[:16]
218216

219217
self._sessions[domain] = Session(
220-
key=hashlib.sha1(shared).digest()[:16],
218+
key=key,
221219
counter=info.counter,
222220
epoch=info.epoch,
223221
delta=int(time.time()) - info.clock_time,

0 commit comments

Comments
 (0)