tesla-fleet-api 0.0.1

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