tesla-fleet-api 0.9.10__py3-none-any.whl → 1.0.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. tesla_fleet_api/__init__.py +7 -22
  2. tesla_fleet_api/const.py +1 -225
  3. tesla_fleet_api/exceptions.py +117 -0
  4. tesla_fleet_api/tesla/__init__.py +11 -0
  5. tesla_fleet_api/tesla/bluetooth.py +33 -0
  6. tesla_fleet_api/{charging.py → tesla/charging.py} +1 -1
  7. tesla_fleet_api/{energy.py → tesla/energysite.py} +41 -33
  8. tesla_fleet_api/{teslafleetapi.py → tesla/fleet.py} +8 -53
  9. tesla_fleet_api/{teslafleetoauth.py → tesla/oauth.py} +3 -4
  10. tesla_fleet_api/{partner.py → tesla/partner.py} +1 -1
  11. tesla_fleet_api/tesla/tesla.py +52 -0
  12. tesla_fleet_api/{user.py → tesla/user.py} +1 -1
  13. tesla_fleet_api/teslemetry/__init__.py +5 -0
  14. tesla_fleet_api/{teslemetry.py → teslemetry/teslemetry.py} +16 -25
  15. tesla_fleet_api/teslemetry/vehicle.py +73 -0
  16. tesla_fleet_api/tessie/__init__.py +5 -0
  17. tesla_fleet_api/{tessie.py → tessie/tessie.py} +17 -9
  18. tesla_fleet_api/tessie/vehicle.py +41 -0
  19. {tesla_fleet_api-0.9.10.dist-info → tesla_fleet_api-1.0.0.dist-info}/METADATA +3 -2
  20. tesla_fleet_api-1.0.0.dist-info/RECORD +24 -0
  21. tesla_fleet_api/energyspecific.py +0 -125
  22. tesla_fleet_api/pb2/__init__.py +0 -0
  23. tesla_fleet_api/pb2/__init__.pyi +0 -9
  24. tesla_fleet_api/pb2/car_server_pb2.py +0 -175
  25. tesla_fleet_api/pb2/car_server_pb2.pyi +0 -904
  26. tesla_fleet_api/pb2/common_pb2.py +0 -33
  27. tesla_fleet_api/pb2/common_pb2.pyi +0 -130
  28. tesla_fleet_api/pb2/errors_pb2.py +0 -17
  29. tesla_fleet_api/pb2/errors_pb2.pyi +0 -32
  30. tesla_fleet_api/pb2/keys_pb2.py +0 -15
  31. tesla_fleet_api/pb2/keys_pb2.pyi +0 -21
  32. tesla_fleet_api/pb2/managed_charging_pb2.py +0 -15
  33. tesla_fleet_api/pb2/managed_charging_pb2.pyi +0 -17
  34. tesla_fleet_api/pb2/signatures_pb2.py +0 -35
  35. tesla_fleet_api/pb2/signatures_pb2.pyi +0 -152
  36. tesla_fleet_api/pb2/universal_message_pb2.py +0 -30
  37. tesla_fleet_api/pb2/universal_message_pb2.pyi +0 -148
  38. tesla_fleet_api/pb2/vcsec_pb2.py +0 -79
  39. tesla_fleet_api/pb2/vcsec_pb2.pyi +0 -482
  40. tesla_fleet_api/pb2/vehicle_pb2.py +0 -125
  41. tesla_fleet_api/pb2/vehicle_pb2.pyi +0 -1183
  42. tesla_fleet_api/teslafleetopensource.py +0 -61
  43. tesla_fleet_api/vehicle.py +0 -880
  44. tesla_fleet_api/vehiclesigned.py +0 -1129
  45. tesla_fleet_api/vehiclespecific.py +0 -509
  46. tesla_fleet_api-0.9.10.dist-info/RECORD +0 -42
  47. {tesla_fleet_api-0.9.10.dist-info → tesla_fleet_api-1.0.0.dist-info}/LICENSE +0 -0
  48. {tesla_fleet_api-0.9.10.dist-info → tesla_fleet_api-1.0.0.dist-info}/WHEEL +0 -0
  49. {tesla_fleet_api-0.9.10.dist-info → tesla_fleet_api-1.0.0.dist-info}/top_level.txt +0 -0
@@ -1,880 +0,0 @@
1
- from __future__ import annotations
2
- from time import time
3
- from locale import getlocale
4
- from typing import Any, List, TYPE_CHECKING
5
- from cryptography.hazmat.primitives.asymmetric import ec
6
- from .const import (
7
- Method,
8
- Trunk,
9
- ClimateKeeperMode,
10
- CabinOverheatProtectionTemp,
11
- VehicleDataEndpoint,
12
- SunRoofCommand,
13
- WindowCommand,
14
- DeviceType,
15
- Seat,
16
- Level,
17
- )
18
- from .vehiclespecific import VehicleSpecific
19
- from .vehiclesigned import VehicleSigned
20
-
21
- if TYPE_CHECKING:
22
- from .teslafleetapi import TeslaFleetApi
23
-
24
- DEFAULT_LOCALE = (getlocale()[0] or "en-US").replace("_","-")
25
-
26
- class Vehicle:
27
- """Class describing the Tesla Fleet API vehicle endpoints and commands."""
28
-
29
- _parent: TeslaFleetApi
30
-
31
- def __init__(self, parent: TeslaFleetApi):
32
- self._parent = parent
33
- self._request = parent._request
34
-
35
- def specific(self, vin: str) -> VehicleSpecific:
36
- """Creates a class for each vehicle."""
37
- return VehicleSpecific(self, vin)
38
-
39
- def specific_signed(
40
- self, vin: str, private_key: ec.EllipticCurvePrivateKey | None = None
41
- ) -> VehicleSigned:
42
- """Creates a class for each vehicle with command signing."""
43
- return VehicleSigned(self, vin, private_key)
44
-
45
- def pre2021(self, vin: str) -> bool:
46
- """Checks if a vehicle is a pre-2021 model S or X."""
47
- return vin[3] in ["S", "X"] and (vin[9] <= "L" or (vin[9] == "M" and vin[7] in ['1', '2', '3', '4']))
48
-
49
- async def actuate_trunk(
50
- self, vehicle_tag: str | int, which_trunk: Trunk | str
51
- ) -> dict[str, Any]:
52
- """Controls the front or rear trunk."""
53
- return await self._request(
54
- Method.POST,
55
- f"api/1/vehicles/{vehicle_tag}/command/actuate_trunk",
56
- json={"which_trunk": which_trunk},
57
- )
58
-
59
- async def adjust_volume(
60
- self, vehicle_tag: str | int, volume: float
61
- ) -> dict[str, Any]:
62
- """Adjusts vehicle media playback volume."""
63
- if volume < 0.0 or volume > 11.0:
64
- raise ValueError("Volume must a number from 0.0 to 11.0")
65
- return await self._request(
66
- Method.POST,
67
- f"api/1/vehicles/{vehicle_tag}/command/adjust_volume",
68
- json={"volume": volume},
69
- )
70
-
71
- async def auto_conditioning_start(self, vehicle_tag: str | int) -> dict[str, Any]:
72
- """Starts climate preconditioning."""
73
- return await self._request(
74
- Method.POST,
75
- f"api/1/vehicles/{vehicle_tag}/command/auto_conditioning_start",
76
- )
77
-
78
- async def auto_conditioning_stop(self, vehicle_tag: str | int) -> dict[str, Any]:
79
- """Stops climate preconditioning."""
80
- return await self._request(
81
- Method.POST,
82
- f"api/1/vehicles/{vehicle_tag}/command/auto_conditioning_stop",
83
- )
84
-
85
- async def cancel_software_update(self, vehicle_tag: str | int) -> dict[str, Any]:
86
- """Cancels the countdown to install the vehicle software update."""
87
- return await self._request(
88
- Method.POST,
89
- f"api/1/vehicles/{vehicle_tag}/command/cancel_software_update",
90
- )
91
-
92
- async def charge_max_range(self, vehicle_tag: str | int) -> dict[str, Any]:
93
- """Charges in max range mode -- we recommend limiting the use of this mode to long trips."""
94
- return await self._request(
95
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/charge_max_range"
96
- )
97
-
98
- async def charge_port_door_close(self, vehicle_tag: str | int) -> dict[str, Any]:
99
- """Closes the charge port door."""
100
- return await self._request(
101
- Method.POST,
102
- f"api/1/vehicles/{vehicle_tag}/command/charge_port_door_close",
103
- )
104
-
105
- async def charge_port_door_open(self, vehicle_tag: str | int) -> dict[str, Any]:
106
- """Opens the charge port door."""
107
- return await self._request(
108
- Method.POST,
109
- f"api/1/vehicles/{vehicle_tag}/command/charge_port_door_open",
110
- )
111
-
112
- async def charge_standard(self, vehicle_tag: str | int) -> dict[str, Any]:
113
- """Charges in Standard mode."""
114
- return await self._request(
115
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/charge_standard"
116
- )
117
-
118
- async def charge_start(self, vehicle_tag: str | int) -> dict[str, Any]:
119
- """Starts charging the vehicle."""
120
- return await self._request(
121
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/charge_start"
122
- )
123
-
124
- async def charge_stop(self, vehicle_tag: str | int) -> dict[str, Any]:
125
- """Stops charging the vehicle."""
126
- return await self._request(
127
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/charge_stop"
128
- )
129
-
130
- async def clear_pin_to_drive_admin(self, vehicle_tag: str | int):
131
- """Deactivates PIN to Drive and resets the associated PIN for vehicles running firmware versions 2023.44+. This command is only accessible to fleet managers or owners."""
132
- return await self._request(
133
- Method.POST,
134
- f"api/1/vehicles/{vehicle_tag}/command/clear_pin_to_drive_admin",
135
- )
136
-
137
- async def door_lock(self, vehicle_tag: str | int) -> dict[str, Any]:
138
- """Locks the vehicle."""
139
- return await self._request(
140
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/door_lock"
141
- )
142
-
143
- async def door_unlock(self, vehicle_tag: str | int) -> dict[str, Any]:
144
- """Unlocks the vehicle."""
145
- return await self._request(
146
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/door_unlock"
147
- )
148
-
149
- async def erase_user_data(self, vehicle_tag: str | int) -> dict[str, Any]:
150
- """Erases user's data from the user interface. Requires the vehicle to be in park."""
151
- return await self._request(
152
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/erase_user_data"
153
- )
154
-
155
- async def flash_lights(self, vehicle_tag: str | int) -> dict[str, Any]:
156
- """Briefly flashes the vehicle headlights. Requires the vehicle to be in park."""
157
- return await self._request(
158
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/flash_lights"
159
- )
160
-
161
- async def guest_mode(self, vehicle_tag: str | int, enable: bool) -> dict[str, Any]:
162
- """Restricts certain vehicle UI functionality from guest users"""
163
- return await self._request(
164
- Method.POST,
165
- f"api/1/vehicles/{vehicle_tag}/command/guest_mode",
166
- json={"enable": enable},
167
- )
168
-
169
- async def honk_horn(self, vehicle_tag: str | int) -> dict[str, Any]:
170
- """Honks the vehicle horn. Requires the vehicle to be in park."""
171
- return await self._request(
172
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/honk_horn"
173
- )
174
-
175
- async def media_next_fav(self, vehicle_tag: str | int) -> dict[str, Any]:
176
- """Advances media player to next favorite track."""
177
- return await self._request(
178
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/media_next_fav"
179
- )
180
-
181
- async def media_next_track(self, vehicle_tag: str | int) -> dict[str, Any]:
182
- """Advances media player to next track."""
183
- return await self._request(
184
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/media_next_track"
185
- )
186
-
187
- async def media_prev_fav(self, vehicle_tag: str | int) -> dict[str, Any]:
188
- """Advances media player to previous favorite track."""
189
- return await self._request(
190
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/media_prev_fav"
191
- )
192
-
193
- async def media_prev_track(self, vehicle_tag: str | int) -> dict[str, Any]:
194
- """Advances media player to previous track."""
195
- return await self._request(
196
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/media_prev_track"
197
- )
198
-
199
- async def media_toggle_playback(self, vehicle_tag: str | int) -> dict[str, Any]:
200
- """Toggles current play/pause state."""
201
- return await self._request(
202
- Method.POST,
203
- f"api/1/vehicles/{vehicle_tag}/command/media_toggle_playback",
204
- )
205
-
206
- async def media_volume_down(self, vehicle_tag: str | int) -> dict[str, Any]:
207
- """Turns the volume down by one."""
208
- return await self._request(
209
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/media_volume_down"
210
- )
211
-
212
- async def navigation_gps_request(
213
- self, vehicle_tag: str | int, lat: float, lon: float, order: int | None = None
214
- ) -> dict[str, Any]:
215
- """Start navigation to given coordinates. Order can be used to specify order of multiple stops."""
216
- return await self._request(
217
- Method.POST,
218
- f"api/1/vehicles/{vehicle_tag}/command/navigation_gps_request",
219
- json={"lat": lat, "lon": lon, "order": order},
220
- )
221
-
222
- async def navigation_request(
223
- self, vehicle_tag: str | int, value: str, type: str = "share_ext_content_raw", locale: str | None = None, timestamp_ms: int | None = None
224
- ) -> dict[str, Any]:
225
- """Sends a location to the in-vehicle navigation system."""
226
- timestamp_ms = timestamp_ms or int(time() * 1000)
227
- locale = locale or DEFAULT_LOCALE
228
- return await self._request(
229
- Method.POST,
230
- f"api/1/vehicles/{vehicle_tag}/command/navigation_request",
231
- json={"value": {"android.intent.extra.TEXT":value}, "type": type, "locale": locale, "timestamp_ms": timestamp_ms},
232
- )
233
-
234
- async def navigation_sc_request(
235
- self, vehicle_tag: str | int, id: int, order: int | None = None
236
- ) -> dict[str, Any]:
237
- """Sends a location to the in-vehicle navigation system."""
238
- return await self._request(
239
- Method.POST,
240
- f"api/1/vehicles/{vehicle_tag}/command/navigation_sc_request",
241
- json={"type": type, "id": id, "order": order},
242
- )
243
-
244
- async def remote_auto_seat_climate_request(
245
- self,
246
- vehicle_tag: str | int,
247
- auto_seat_position: int | Seat,
248
- auto_climate_on: bool,
249
- ) -> dict[str, Any]:
250
- """Sets automatic seat heating and cooling."""
251
- return await self._request(
252
- Method.POST,
253
- f"api/1/vehicles/{vehicle_tag}/command/remote_auto_seat_climate_request",
254
- json={
255
- "auto_seat_position": auto_seat_position,
256
- "auto_climate_on": auto_climate_on,
257
- },
258
- )
259
-
260
- async def remote_auto_steering_wheel_heat_climate_request(
261
- self, vehicle_tag: str | int, on: bool
262
- ) -> dict[str, Any]:
263
- """Sets automatic steering wheel heating on/off."""
264
- return await self._request(
265
- Method.POST,
266
- f"api/1/vehicles/{vehicle_tag}/command/remote_auto_steering_wheel_heat_climate_request",
267
- json={"on": on},
268
- )
269
-
270
- async def remote_boombox(
271
- self, vehicle_tag: str | int, sound: int
272
- ) -> dict[str, Any]:
273
- """Plays a sound through the vehicle external speaker."""
274
- return await self._request(
275
- Method.POST,
276
- f"api/1/vehicles/{vehicle_tag}/command/remote_boombox",
277
- json={"sound": sound},
278
- )
279
-
280
- async def remote_seat_cooler_request(
281
- self,
282
- vehicle_tag: str | int,
283
- seat_position: Seat | int,
284
- seat_cooler_level: Level | int,
285
- ) -> dict[str, Any]:
286
- """Sets seat cooling."""
287
- return await self._request(
288
- Method.POST,
289
- f"api/1/vehicles/{vehicle_tag}/command/remote_seat_cooler_request",
290
- json={
291
- "seat_position": seat_position,
292
- "seat_cooler_level": seat_cooler_level,
293
- },
294
- )
295
-
296
- async def remote_seat_heater_request(
297
- self,
298
- vehicle_tag: str | int,
299
- seat_position: Seat | int,
300
- seat_heater_level: Level | int,
301
- ) -> dict[str, Any]:
302
- """Sets seat heating."""
303
- return await self._request(
304
- Method.POST,
305
- f"api/1/vehicles/{vehicle_tag}/command/remote_seat_heater_request",
306
- json={
307
- "heater": seat_position,
308
- "level": seat_heater_level,
309
- },
310
- )
311
-
312
- async def remote_start_drive(self, vehicle_tag: str | int) -> dict[str, Any]:
313
- """Starts the vehicle remotely. Requires keyless driving to be enabled."""
314
- return await self._request(
315
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/remote_start_drive"
316
- )
317
-
318
- async def remote_steering_wheel_heat_level_request(
319
- self, vehicle_tag: str | int, level: Level | int
320
- ) -> dict[str, Any]:
321
- """Sets steering wheel heat level."""
322
- return await self._request(
323
- Method.POST,
324
- f"api/1/vehicles/{vehicle_tag}/command/remote_steering_wheel_heat_level_request",
325
- json={"level": level},
326
- )
327
-
328
- async def remote_steering_wheel_heater_request(
329
- self, vehicle_tag: str | int, on: bool
330
- ) -> dict[str, Any]:
331
- """Sets steering wheel heating on/off. For vehicles that do not support auto steering wheel heat."""
332
- return await self._request(
333
- Method.POST,
334
- f"api/1/vehicles/{vehicle_tag}/command/remote_steering_wheel_heater_request",
335
- json={"on": on},
336
- )
337
-
338
- async def reset_pin_to_drive_pin(self, vehicle_tag: str | int) -> dict[str, Any]:
339
- """Removes PIN to Drive. Requires the car to be in Pin to Drive mode and not in Valet mode. Note that this only works if PIN to Drive is not active. This command also requires the Tesla Vehicle Command Protocol - for more information, please see refer to the documentation here."""
340
- return await self._request(
341
- Method.POST,
342
- f"api/1/vehicles/{vehicle_tag}/command/reset_pin_to_drive_pin",
343
- )
344
-
345
- async def reset_valet_pin(self, vehicle_tag: str | int) -> dict[str, Any]:
346
- """Removes PIN for Valet Mode."""
347
- return await self._request(
348
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/reset_valet_pin"
349
- )
350
-
351
- async def schedule_software_update(
352
- self, vehicle_tag: str | int, offset_sec: int
353
- ) -> dict[str, Any]:
354
- """Schedules a vehicle software update (over the air "OTA") to be installed in the future."""
355
- return await self._request(
356
- Method.POST,
357
- f"api/1/vehicles/{vehicle_tag}/command/schedule_software_update",
358
- json={"offset_sec": offset_sec},
359
- )
360
-
361
- async def set_bioweapon_mode(
362
- self, vehicle_tag: str | int, on: bool, manual_override: bool
363
- ) -> dict[str, Any]:
364
- """Turns Bioweapon Defense Mode on and off."""
365
- return await self._request(
366
- Method.POST,
367
- f"api/1/vehicles/{vehicle_tag}/command/set_bioweapon_mode",
368
- json={"on": on, "manual_override": manual_override},
369
- )
370
-
371
- async def set_cabin_overheat_protection(
372
- self, vehicle_tag: str | int, on: bool, fan_only: bool
373
- ) -> dict[str, Any]:
374
- """Sets the vehicle overheat protection."""
375
- return await self._request(
376
- Method.POST,
377
- f"api/1/vehicles/{vehicle_tag}/command/set_cabin_overheat_protection",
378
- json={"on": on, "fan_only": fan_only},
379
- )
380
-
381
- async def set_charge_limit(
382
- self, vehicle_tag: str | int, percent: int
383
- ) -> dict[str, Any]:
384
- """Sets the vehicle charge limit."""
385
- return await self._request(
386
- Method.POST,
387
- f"api/1/vehicles/{vehicle_tag}/command/set_charge_limit",
388
- json={"percent": percent},
389
- )
390
-
391
- async def set_charging_amps(
392
- self, vehicle_tag: str | int, charging_amps: int
393
- ) -> dict[str, Any]:
394
- """Sets the vehicle charging amps."""
395
- return await self._request(
396
- Method.POST,
397
- f"api/1/vehicles/{vehicle_tag}/command/set_charging_amps",
398
- json={"charging_amps": charging_amps},
399
- )
400
-
401
- async def set_climate_keeper_mode(
402
- self, vehicle_tag: str | int, climate_keeper_mode: ClimateKeeperMode | int
403
- ) -> dict[str, Any]:
404
- """Enables climate keeper mode."""
405
- return await self._request(
406
- Method.POST,
407
- f"api/1/vehicles/{vehicle_tag}/command/set_climate_keeper_mode",
408
- json={"climate_keeper_mode": climate_keeper_mode},
409
- )
410
-
411
- async def set_cop_temp(
412
- self, vehicle_tag: str | int, cop_temp: CabinOverheatProtectionTemp | int
413
- ) -> dict[str, Any]:
414
- """Adjusts the Cabin Overheat Protection temperature (COP)."""
415
- return await self._request(
416
- Method.POST,
417
- f"api/1/vehicles/{vehicle_tag}/command/set_cop_temp",
418
- json={"cop_temp": cop_temp},
419
- )
420
-
421
- async def set_pin_to_drive(
422
- self, vehicle_tag: str | int, on: bool, password: str | int
423
- ) -> dict[str, Any]:
424
- """Sets a four-digit passcode for PIN to Drive. This PIN must then be entered before the vehicle can be driven."""
425
- return await self._request(
426
- Method.POST,
427
- f"api/1/vehicles/{vehicle_tag}/command/set_pin_to_drive",
428
- json={"on": on, "password": str(password)},
429
- )
430
-
431
- async def set_preconditioning_max(
432
- self, vehicle_tag: str | int, on: bool, manual_override: bool
433
- ) -> dict[str, Any]:
434
- """Sets an override for preconditioning — it should default to empty if no override is used."""
435
- return await self._request(
436
- Method.POST,
437
- f"api/1/vehicles/{vehicle_tag}/command/set_preconditioning_max",
438
- json={"on": on, "manual_override": manual_override},
439
- )
440
-
441
- async def set_scheduled_charging(
442
- self, vehicle_tag: str | int, enable: bool, time: int
443
- ) -> dict[str, Any]:
444
- """Sets a time at which charging should be completed. The time parameter is minutes after midnight (e.g: time=120 schedules charging for 2:00am vehicle local time)."""
445
- return await self._request(
446
- Method.POST,
447
- f"api/1/vehicles/{vehicle_tag}/command/set_scheduled_charging",
448
- json={"enable": enable, "time": time},
449
- )
450
-
451
- async def set_scheduled_departure(
452
- self,
453
- vehicle_tag: str | int,
454
- enable: bool = True,
455
- preconditioning_enabled: bool = False,
456
- preconditioning_weekdays_only: bool = False,
457
- departure_time: int = 0,
458
- off_peak_charging_enabled: bool = False,
459
- off_peak_charging_weekdays_only: bool = False,
460
- end_off_peak_time: int = 0,
461
- ) -> dict[str, Any]:
462
- """Sets a time at which departure should be completed. The time parameter is minutes after midnight (e.g: time=120 schedules departure for 2:00am vehicle local time)."""
463
- return await self._request(
464
- Method.POST,
465
- f"api/1/vehicles/{vehicle_tag}/command/set_scheduled_departure",
466
- json={
467
- "enable": enable,
468
- "preconditioning_enabled": preconditioning_enabled,
469
- "preconditioning_weekdays_only": preconditioning_weekdays_only,
470
- "departure_time": departure_time,
471
- "off_peak_charging_enabled": off_peak_charging_enabled,
472
- "off_peak_charging_weekdays_only": off_peak_charging_weekdays_only,
473
- "end_off_peak_time": end_off_peak_time,
474
- },
475
- )
476
-
477
- async def set_sentry_mode(self, vehicle_tag: str | int, on: bool) -> dict[str, Any]:
478
- """Enables and disables Sentry Mode. Sentry Mode allows customers to watch the vehicle cameras live from the mobile app, as well as record sentry events."""
479
- return await self._request(
480
- Method.POST,
481
- f"api/1/vehicles/{vehicle_tag}/command/set_sentry_mode",
482
- json={"on": on},
483
- )
484
-
485
- async def set_temps(
486
- self,
487
- vehicle_tag: str | int,
488
- driver_temp: float,
489
- passenger_temp: float,
490
- ) -> dict[str, Any]:
491
- """Sets the driver and/or passenger-side cabin temperature (and other zones if sync is enabled)."""
492
- return await self._request(
493
- Method.POST,
494
- f"api/1/vehicles/{vehicle_tag}/command/set_temps",
495
- json={"driver_temp": driver_temp, "passenger_temp": passenger_temp},
496
- )
497
-
498
- async def set_valet_mode(
499
- self, vehicle_tag: str | int, on: bool, password: str | int
500
- ) -> dict[str, Any]:
501
- """Turns on Valet Mode and sets a four-digit passcode that must then be entered to disable Valet Mode."""
502
- return await self._request(
503
- Method.POST,
504
- f"api/1/vehicles/{vehicle_tag}/command/set_valet_mode",
505
- json={"on": on, "password": str(password)},
506
- )
507
-
508
- async def set_vehicle_name(
509
- self, vehicle_tag: str | int, vehicle_name: str
510
- ) -> dict[str, Any]:
511
- """Changes the name of a vehicle. This command also requires the Tesla Vehicle Command Protocol - for more information, please see refer to the documentation here."""
512
- return await self._request(
513
- Method.POST,
514
- f"api/1/vehicles/{vehicle_tag}/command/set_vehicle_name",
515
- json={"vehicle_name": vehicle_name},
516
- )
517
-
518
- async def speed_limit_activate(
519
- self, vehicle_tag: str | int, pin: str | int
520
- ) -> dict[str, Any]:
521
- """Activates Speed Limit Mode with a four-digit PIN."""
522
- return await self._request(
523
- Method.POST,
524
- f"api/1/vehicles/{vehicle_tag}/command/speed_limit_activate",
525
- json={"pin": str(pin)},
526
- )
527
-
528
- async def speed_limit_clear_pin(
529
- self, vehicle_tag: str | int, pin: str | int
530
- ) -> dict[str, Any]:
531
- """Deactivates Speed Limit Mode and resets the associated PIN."""
532
- return await self._request(
533
- Method.POST,
534
- f"api/1/vehicles/{vehicle_tag}/command/speed_limit_clear_pin",
535
- json={"pin": str(pin)},
536
- )
537
-
538
- async def speed_limit_clear_pin_admin(
539
- self, vehicle_tag: str | int
540
- ) -> dict[str, Any]:
541
- """Deactivates Speed Limit Mode and resets the associated PIN for vehicles running firmware versions 2023.38+. This command is only accessible to fleet managers or owners."""
542
- return await self._request(
543
- Method.POST,
544
- f"api/1/vehicles/{vehicle_tag}/command/speed_limit_clear_pin_admin",
545
- )
546
-
547
- async def speed_limit_deactivate(
548
- self, vehicle_tag: str | int, pin: str | int
549
- ) -> dict[str, Any]:
550
- """Deactivates Speed Limit Mode."""
551
- return await self._request(
552
- Method.POST,
553
- f"api/1/vehicles/{vehicle_tag}/command/speed_limit_deactivate",
554
- json={"pin": str(pin)},
555
- )
556
-
557
- async def speed_limit_set_limit(
558
- self, vehicle_tag: str | int, limit_mph: int
559
- ) -> dict[str, Any]:
560
- """Sets the maximum speed allowed when Speed Limit Mode is active."""
561
- return await self._request(
562
- Method.POST,
563
- f"api/1/vehicles/{vehicle_tag}/command/speed_limit_set_limit",
564
- json={"limit_mph": limit_mph},
565
- )
566
-
567
- async def sun_roof_control(
568
- self, vehicle_tag: str | int, state: str | SunRoofCommand
569
- ) -> dict[str, Any]:
570
- """Controls the panoramic sunroof on the Model S."""
571
- return await self._request(
572
- Method.POST,
573
- f"api/1/vehicles/{vehicle_tag}/command/sun_roof_control",
574
- json={"state": state},
575
- )
576
-
577
- async def take_drivenote(self, vehicle_tag: str | int, note: str) -> dict[str, Any]:
578
- """Records a drive note. The note parameter is truncated to 80 characters in length."""
579
- return await self._request(
580
- Method.POST,
581
- f"api/1/vehicles/{vehicle_tag}/command/take_drivenote",
582
- json={"note": note},
583
- )
584
-
585
- async def trigger_homelink(
586
- self,
587
- vehicle_tag: str | int,
588
- token: str | None = None,
589
- lat: float | None = None,
590
- lon: float | None = None,
591
- ) -> dict[str, Any]:
592
- """Turns on HomeLink (used to open and close garage doors)."""
593
- data: dict[str, str | float] = {}
594
- if token:
595
- data["token"] = token
596
- if lat and lon:
597
- data["lat"] = lat
598
- data["lon"] = lon
599
- return await self._request(
600
- Method.POST,
601
- f"api/1/vehicles/{vehicle_tag}/command/trigger_homelink",
602
- json=data,
603
- )
604
-
605
- async def upcoming_calendar_entries(
606
- self, vehicle_tag: str | int, calendar_data: str
607
- ) -> dict[str, Any]:
608
- """Upcoming calendar entries stored on the vehicle."""
609
- return await self._request(
610
- Method.POST,
611
- f"api/1/vehicles/{vehicle_tag}/command/upcoming_calendar_entries",
612
- json={"calendar_data": calendar_data},
613
- )
614
-
615
- async def window_control(
616
- self,
617
- vehicle_tag: str | int,
618
- command: str | WindowCommand,
619
- lat: float | None = None,
620
- lon: float | None = None,
621
- ) -> dict[str, Any]:
622
- """Control the windows of a parked vehicle. Supported commands: vent and close. When closing, specify lat and lon of user to ensure they are within range of vehicle (unless this is an M3 platform vehicle)."""
623
- return await self._request(
624
- Method.POST,
625
- f"api/1/vehicles/{vehicle_tag}/command/window_control",
626
- json={"lat": lat, "lon": lon, "command": command},
627
- )
628
-
629
- async def drivers(self, vehicle_tag: str | int) -> dict[str, Any]:
630
- """Returns all allowed drivers for a vehicle. This endpoint is only available for the vehicle owner."""
631
- return await self._request(Method.GET, f"api/1/vehicles/{vehicle_tag}/drivers")
632
-
633
- async def drivers_remove(
634
- self, vehicle_tag: str | int, share_user_id: str | int | None = None
635
- ) -> dict[str, Any]:
636
- """Removes driver access from a vehicle. Share users can only remove their own access. Owners can remove share access or their own."""
637
- return await self._request(
638
- Method.DELETE,
639
- f"api/1/vehicles/{vehicle_tag}/drivers",
640
- {"share_user_id": share_user_id},
641
- )
642
-
643
- async def list(
644
- self, page: int | None = None, per_page: int | None = None
645
- ) -> dict[str, Any]:
646
- """Returns vehicles belonging to the account."""
647
- return await self._request(
648
- Method.GET, "api/1/vehicles", {"page": page, "per_page": per_page}
649
- )
650
-
651
- async def mobile_enabled(self, vehicle_tag: str | int) -> dict[str, Any]:
652
- """Returns whether or not mobile access is enabled for the vehicle."""
653
- return await self._request(
654
- Method.GET, f"api/1/vehicles/{vehicle_tag}/mobile_enabled"
655
- )
656
-
657
- async def nearby_charging_sites(
658
- self,
659
- vehicle_tag: str | int,
660
- count: int | None = None,
661
- radius: int | None = None,
662
- detail: bool | None = None,
663
- ) -> dict[str, Any]:
664
- """Returns the charging sites near the current location of the vehicle."""
665
- return await self._request(
666
- Method.GET,
667
- f"api/1/vehicles/{vehicle_tag}/nearby_charging_sites",
668
- {"count": count, "radius": radius, "detail": detail},
669
- )
670
-
671
- async def options(self, vin: str) -> dict[str, Any]:
672
- """Returns vehicle option details."""
673
- return await self._request(
674
- Method.GET, "api/1/dx/vehicles/options", {"vin": vin}
675
- )
676
-
677
- async def recent_alerts(self, vehicle_tag: str | int) -> dict[str, Any]:
678
- """List of recent alerts"""
679
- return await self._request(
680
- Method.GET, f"api/1/vehicles/{vehicle_tag}/recent_alerts"
681
- )
682
-
683
- async def release_notes(
684
- self,
685
- vehicle_tag: str | int,
686
- staged: bool | None = None,
687
- language: int | None = None,
688
- ) -> dict[str, Any]:
689
- """Returns firmware release notes."""
690
- return await self._request(
691
- Method.GET,
692
- f"api/1/vehicles/{vehicle_tag}/release_notes",
693
- {"staged": staged, "language": language},
694
- )
695
-
696
- async def service_data(self, vehicle_tag: str | int) -> dict[str, Any]:
697
- """Returns service data."""
698
- return await self._request(
699
- Method.GET, f"api/1/vehicles/{vehicle_tag}/service_data"
700
- )
701
-
702
- async def share_invites(self, vehicle_tag: str | int) -> dict[str, Any]:
703
- """Returns the share invites for a vehicle."""
704
- return await self._request(
705
- Method.GET, f"api/1/vehicles/{vehicle_tag}/invitations"
706
- )
707
-
708
- async def share_invites_create(self, vehicle_tag: str | int) -> dict[str, Any]:
709
- """Creates a share invite for a vehicle."""
710
- return await self._request(
711
- Method.POST, f"api/1/vehicles/{vehicle_tag}/invitations"
712
- )
713
-
714
- async def share_invites_redeem(self, code: str) -> dict[str, Any]:
715
- """Redeems a share invite."""
716
- return await self._request(
717
- Method.POST, "api/1/invitations/redeem", {code: code}
718
- )
719
-
720
- async def share_invites_revoke(
721
- self, vehicle_tag: str | int, id: str
722
- ) -> dict[str, Any]:
723
- """Revokes a share invite."""
724
- return await self._request(
725
- Method.POST, f"api/1/vehicles/{vehicle_tag}/invitations/{id}/revoke"
726
- )
727
-
728
- async def signed_command(
729
- self, vehicle_tag: str | int, routable_message: str
730
- ) -> dict[str, Any]:
731
- """Signed Commands is a generic endpoint replacing legacy commands."""
732
- return await self._request(
733
- Method.POST,
734
- f"api/1/vehicles/{vehicle_tag}/signed_command",
735
- json={"routable_message": routable_message},
736
- )
737
-
738
- async def vehicle(self, vehicle_tag: str | int) -> dict[str, Any]:
739
- """Returns information about a vehicle."""
740
- return await self._request(Method.GET, f"api/1/vehicles/{vehicle_tag}")
741
-
742
- async def vehicle_data(
743
- self,
744
- vehicle_tag: str | int,
745
- endpoints: list[VehicleDataEndpoint | str] | None = None,
746
- ) -> dict[str, Any]:
747
- """Makes a live call to the vehicle. This may return cached data if the vehicle is offline. For vehicles running firmware versions 2023.38+, location_data is required to fetch vehicle location. This will result in a location sharing icon to show on the vehicle UI."""
748
- endpoint_payload = ";".join(endpoints) if endpoints else None
749
- return await self._request(
750
- Method.GET,
751
- f"api/1/vehicles/{vehicle_tag}/vehicle_data",
752
- {"endpoints": endpoint_payload},
753
- )
754
-
755
- async def wake_up(self, vehicle_tag: str | int) -> dict[str, Any]:
756
- """Wakes the vehicle from sleep, which is a state to minimize idle energy consumption."""
757
- return await self._request(Method.POST, f"api/1/vehicles/{vehicle_tag}/wake_up")
758
-
759
- async def warranty_details(self, vin: str | None) -> dict[str, Any]:
760
- """Returns warranty details."""
761
- return await self._request(
762
- Method.GET, "api/1/dx/warranty/details", {"vin": vin}
763
- )
764
-
765
- async def fleet_status(self, vins: List[str]) -> dict[str, Any]:
766
- """Checks whether vehicles can accept Tesla commands protocol for the partner's public key"""
767
- return await self._request(
768
- Method.POST, "api/1/vehicles/fleet_status", json={"vins": vins}
769
- )
770
-
771
- async def fleet_telemetry_config_create(
772
- self, config: dict[str, Any]
773
- ) -> dict[str, Any]:
774
- """Configures fleet telemetry."""
775
- return await self._request(
776
- Method.POST, "api/1/vehicles/fleet_telemetry_config", json=config
777
- )
778
-
779
- async def fleet_telemetry_config_get(
780
- self, vehicle_tag: str | int
781
- ) -> dict[str, Any]:
782
- """Configures fleet telemetry."""
783
- return await self._request(
784
- Method.GET, f"api/1/vehicles/{vehicle_tag}/fleet_telemetry_config"
785
- )
786
-
787
- async def fleet_telemetry_config_delete(
788
- self, vehicle_tag: str | int
789
- ) -> dict[str, Any]:
790
- """Configures fleet telemetry."""
791
- return await self._request(
792
- Method.DELETE, f"api/1/vehicles/{vehicle_tag}/fleet_telemetry_config"
793
- )
794
-
795
- async def add_charge_schedule(
796
- self,
797
- vehicle_tag: str | int,
798
- days_of_week: str | int,
799
- enabled: bool,
800
- lat: float,
801
- lon: float,
802
- start_time: int | None = None,
803
- end_time: int | None = None,
804
- one_time: bool | None = None,
805
- id: int | None = None,
806
- name: str | None = None,
807
-
808
- ) -> dict[str, Any]:
809
- """Add a schedule for vehicle charging."""
810
- if not start_time and not end_time:
811
- raise ValueError("Either start_time or end_time or both must be provided")
812
- json_payload = {
813
- "days_of_week": days_of_week,
814
- "enabled": enabled,
815
- "end_enabled": end_time is not None,
816
- "lat": lat,
817
- "lon": lon,
818
- "start_enabled": start_time is not None,
819
- }
820
- if start_time is not None:
821
- json_payload["start_time"] = start_time
822
- if end_time is not None:
823
- json_payload["end_time"] = end_time
824
- if id is not None:
825
- json_payload["id"] = id
826
- if one_time is not None:
827
- json_payload["one_time"] = one_time
828
-
829
- return await self._request(
830
- Method.POST,
831
- f"api/1/vehicles/{vehicle_tag}/command/add_charge_schedule",
832
- json=json_payload,
833
- )
834
-
835
- async def add_precondition_schedule(
836
- self,
837
- vehicle_tag: str | int,
838
- days_of_week: str | int,
839
- enabled: bool,
840
- lat: float,
841
- lon: float,
842
- precondition_time: int,
843
- id: int | None = None,
844
- one_time: bool | None = None,
845
- name: str | None = None,
846
- ) -> dict[str, Any]:
847
- """Add or modify a preconditioning schedule."""
848
- json_payload = {
849
- "days_of_week": days_of_week,
850
- "enabled": enabled,
851
- "lat": lat,
852
- "lon": lon,
853
- "precondition_time": precondition_time,
854
- }
855
- if id is not None:
856
- json_payload["id"] = id
857
- if one_time is not None:
858
- json_payload["one_time"] = one_time
859
-
860
- return await self._request(
861
- Method.POST,
862
- f"api/1/vehicles/{vehicle_tag}/command/add_precondition_schedule",
863
- json=json_payload,
864
- )
865
-
866
- async def remove_charge_schedule(
867
- self, vehicle_tag: str | int, id: int
868
- ) -> dict[str, Any]:
869
- """Removes the scheduled charging settings."""
870
- return await self._request(
871
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/remove_charge_schedule", json={"id": id}
872
- )
873
-
874
- async def remove_precondition_schedule(
875
- self, vehicle_tag: str | int, id: int
876
- ) -> dict[str, Any]:
877
- """Removes the scheduled precondition settings."""
878
- return await self._request(
879
- Method.POST, f"api/1/vehicles/{vehicle_tag}/command/remove_precondition_schedule", json={"id": id}
880
- )