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

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