tesla-fleet-api 0.0.4__py3-none-any.whl → 0.0.5__py3-none-any.whl

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