UNPKG

tesla-fleet-api

Version:

A library for the [Tesla Fleet API](https://developer.tesla.com/docs/fleet-api), and the third parties services [Teslemetry](https://teslemetry.com/docs/getting-started/api) and [Tessie](https://developer.tessie.com/docs/tesla-api-comparison), which provi

537 lines (536 loc) 25.1 kB
import TeslaFleetApi from "./teslafleetapi.js"; import { ClimateMode, CommandResponse, FleetTelemetryConfig, Level, Seat, Trunk, VehicleDataEndpoint } from "./types/commands.js"; import { OptionsResponse } from "./types/responses.js"; import { VehicleResponse } from "./types/vehicle.js"; import { VehicleDataResponse } from "./types/vehicle_data.js"; import VehicleSpecific from "./vehiclespecific.js"; export default class Vehicle { parent: TeslaFleetApi; constructor(parent: TeslaFleetApi); /** * Returns a class for a single vehicle. * @param vin * @returns */ specific(vin: string): VehicleSpecific; /** * Return the vehicle model name * @param vin * @returns */ model(vin: string): string; /** * Return if the vehicle was build before 2021 and cannot sleep without a break * @param vin * @returns */ pre2021(vin: string): boolean; /** * Controls the front (which_trunk: "front") or rear (which_trunk: "rear") trunk. * @param vehicle_tag VIN or id field of a vehicle * @param which_trunk "front" or "rear" */ actuate_truck(vehicle_tag: string | number, which_trunk: Trunk): Promise<CommandResponse>; /** * Adjusts vehicle media playback volume. * @param vehicle_tag VIN or id field of a vehicle * @param volume A floating point number from 0.0 to 11.0. */ adjust_volume(vehicle_tag: string | number, volume: number): Promise<CommandResponse>; /** * Starts climate preconditioning. * @param vehicle_tag VIN or id field of a vehicle */ auto_conditioning_start(vehicle_tag: string | number): Promise<CommandResponse>; /** * Stops climate preconditioning. * @param vehicle_tag VIN or id field of a vehicle */ auto_conditioning_stop(vehicle_tag: string | number): Promise<CommandResponse>; /** * Cancels the countdown to install the vehicle software update. * @param vehicle_tag VIN or id field of a vehicle */ cancel_software_update(vehicle_tag: string | number): Promise<CommandResponse>; /** * Charges in max range mode -- we recommend limiting the use of this mode to long trips. * @param vehicle_tag VIN or id field of a vehicle */ charge_max_range(vehicle_tag: string | number): Promise<CommandResponse>; /** * Closes the charge port door. * @param vehicle_tag VIN or id field of a vehicle */ charge_port_door_close(vehicle_tag: string | number): Promise<CommandResponse>; /** * Opens the charge port door. * @param vehicle_tag VIN or id field of a vehicle */ charge_port_door_open(vehicle_tag: string | number): Promise<CommandResponse>; /** * Charges in Standard mode. * @param vehicle_tag VIN or id field of a vehicle */ charge_standard(vehicle_tag: string | number): Promise<CommandResponse>; /** * Starts charging the vehicle. * @param vehicle_tag VIN or id field of a vehicle */ charge_start(vehicle_tag: string | number): Promise<CommandResponse>; /** * Stops charging the vehicle. * @param vehicle_tag VIN or id field of a vehicle */ charge_stop(vehicle_tag: string | number): Promise<CommandResponse>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle */ clear_pin_to_drive_admin(vehicle_tag: string | number): Promise<CommandResponse>; /** * Locks the vehicle. * @param vehicle_tag VIN or id field of a vehicle */ door_lock(vehicle_tag: string | number): Promise<CommandResponse>; /** * Unlocks the vehicle. * @param vehicle_tag VIN or id field of a vehicle */ door_unlock(vehicle_tag: string | number): Promise<CommandResponse>; /** * Erases user's data from the user interface. Requires the vehicle to be in park. * @param vehicle_tag VIN or id field of a vehicle */ erase_user_data(vehicle_tag: string | number): Promise<CommandResponse>; /** * Briefly flashes the vehicle headlights. Requires the vehicle to be in park. * @param vehicle_tag VIN or id field of a vehicle */ flash_lights(vehicle_tag: string | number): Promise<CommandResponse>; /** * Restricts certain vehicle UI functionality from guest users * @param vehicle_tag VIN or id field of a vehicle * @param enable `true` or `false` */ guest_mode(vehicle_tag: string | number, enable: boolean): Promise<CommandResponse>; /** * Honks the vehicle horn. Requires the vehicle to be in park. * @param vehicle_tag VIN or id field of a vehicle */ honk_horn(vehicle_tag: string | number): Promise<CommandResponse>; /** * Advances media player to next favorite track. * @param vehicle_tag VIN or id field of a vehicle */ media_next_fav(vehicle_tag: string | number): Promise<CommandResponse>; /** * Advances media player to next track. * @param vehicle_tag VIN or id field of a vehicle */ media_next_track(vehicle_tag: string | number): Promise<CommandResponse>; /** * Advances media player to previous favorite track. * @param vehicle_tag VIN or id field of a vehicle */ media_prev_fav(vehicle_tag: string | number): Promise<CommandResponse>; /** * Advances media player to previous track. * @param vehicle_tag VIN or id field of a vehicle */ media_prev_track(vehicle_tag: string | number): Promise<CommandResponse>; /** * Toggles current play/pause state. * @param vehicle_tag VIN or id field of a vehicle */ media_toggle_playback(vehicle_tag: string | number): Promise<CommandResponse>; /** * Turns the volume down by one. * @param vehicle_tag VIN or id field of a vehicle */ media_volume_down(vehicle_tag: string | number): Promise<CommandResponse>; /** * Start navigation to given coordinates. Order can be used to specify order of multiple stops. * @param vehicle_tag VIN or id field of a vehicle * @param lat Latitude * @param lon Longitude * @param order Order of multiple stops */ navigation_gps_request(vehicle_tag: string | number, lat: number, lon: number, order?: number): Promise<CommandResponse>; /** * Sends a location to the in-vehicle navigation system. * @param vehicle_tag VIN or id field of a vehicle * @param type "share_ext_content_raw" * @param locale ISO locale such as "en-US" * @param timestamp_ms */ navigation_request(vehicle_tag: string | number, value: string, locale: string, type?: string): Promise<CommandResponse>; /** * Start navigation to a supercharger. * @param vehicle_tag VIN or id field of a vehicle * @param id Supercharger ID * @param order Order of multiple stops * @returns */ navigation_sc_request(vehicle_tag: string | number, id: number, order?: number): Promise<CommandResponse>; /** * Sets automatic seat heating and cooling. * @param vehicle_tag VIN or id field of a vehicle * @param auto_seat_position Seat position * @param auto_climate_on `true` or `false` */ remote_auto_seat_climate_request(vehicle_tag: string | number, auto_seat_position: Seat | number, auto_climate_on: boolean): Promise<CommandResponse>; /** * Sets automatic steering wheel heating on/off. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` */ remote_auto_steering_wheel_heat_climate_request(vehicle_tag: string | number, on: boolean): Promise<CommandResponse>; /** * Plays a sound through the vehicle external speaker. * @param vehicle_tag VIN or id field of a vehicle * @param sound Fart is `0`, Locate ping is `2000` */ remote_boombox(vehicle_tag: string | number, sound?: number): Promise<CommandResponse>; /** * Sets seat cooling. * @param vehicle_tag VIN or id field of a vehicle * @param seat_position Seat position * @param seat_cooler_level Cooling level */ remote_seat_cooler_request(vehicle_tag: string | number, seat_position: Seat | number, seat_cooler_level: Level): Promise<CommandResponse>; /** * Sets seat heating. * @param vehicle_tag VIN or id field of a vehicle * @param seat_position Seat position * @param seat_heater_level Heating level */ remote_seat_heater_request(vehicle_tag: string | number, seat_position: Seat | number, seat_heater_level: Level): Promise<CommandResponse>; /** * Starts the vehicle remotely. Requires keyless driving to be enabled. * @param vehicle_tag VIN or id field of a vehicle */ remote_start_drive(vehicle_tag: string | number): Promise<CommandResponse>; /** * Sets steering wheel heat level. * @param vehicle_tag VIN or id field of a vehicle * @param level Heating level */ remote_steering_wheel_heat_level_request(vehicle_tag: string | number, level: Level): Promise<CommandResponse>; /** * Sets steering wheel heating on/off. For vehicles that do not support auto steering wheel heat. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` */ remote_steering_wheel_heater_request(vehicle_tag: string | number, on: boolean): Promise<CommandResponse>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle */ reset_pin_to_drive_pin(vehicle_tag: string | number): Promise<CommandResponse>; /** * Removes PIN for Valet Mode. * @param vehicle_tag VIN or id field of a vehicle */ reset_valet_pin(vehicle_tag: string | number): Promise<CommandResponse>; /** * Schedules a vehicle software update (over the air "OTA") to be installed in the future. * @param vehicle_tag VIN or id field of a vehicle * @param offset_sec Offset in seconds */ schedule_software_update(vehicle_tag: string | number, offset_sec: number): Promise<CommandResponse>; /** * Turns Bioweapon Defense Mode on and off. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` * @param manual_override `true` or `false` */ set_bioweapon_mode(vehicle_tag: string | number, on: boolean, manual_override: boolean): Promise<CommandResponse>; /** * Sets the vehicle overheat protection. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` * @param fan_only `true` or `false` */ set_cabin_overheat_protection(vehicle_tag: string | number, on: boolean, fan_only: boolean): Promise<CommandResponse>; /** * Sets the vehicle's charge limit to a custom percentage. * @param vehicle_tag VIN or id field of a vehicle * @param percent Charge limit percentage typically between 50-100 */ set_charge_limit(vehicle_tag: string | number, percent: number): Promise<CommandResponse>; /** * Sets the charge limit to the standard setting. * @param vehicle_tag VIN or id field of a vehicle * @param percent Current limit in Amps typically between 5-32 */ set_charging_amps(vehicle_tag: string | number, charging_amps: number): Promise<CommandResponse>; /** * Enables climate keeper mode. * @param vehicle_tag VIN or id field of a vehicle * @param climate_keeper_mode `0` is Off, `1` is Keep, `2` is Dog, `3` is Camp */ set_climate_keeper_mode(vehicle_tag: string | number, climate_keeper_mode: number | ClimateMode): Promise<CommandResponse>; /** * Adjusts the Cabin Overheat Protection temperature (COP). * @param vehicle_tag VIN or id field of a vehicle * @param cop_temp Integer representing Low (0/30C/90F), Medium (1/35C/95F), or High (2/40C/100F) */ set_cop_temp(vehicle_tag: string | number, cop_temp: 0 | 1 | 2 | 30 | 35 | 40 | 90 | 95 | 100): Promise<CommandResponse>; /** * Sets a four-digit passcode for PIN to Drive. This PIN must then be entered before the vehicle can be driven. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` * @param password Four-digit passcode */ set_pin_to_drive(vehicle_tag: string | number, on: boolean, password: string | number): Promise<CommandResponse>; /** * Sets an override for preconditioning — it should default to empty if no override is used. * Also known as "Defrost Mode" * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` * @param manual_override `true` or `false` */ set_preconditioning_max(vehicle_tag: string | number, on: boolean, manual_override: boolean): Promise<CommandResponse>; /** * 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). * @param vehicle_tag VIN or id field of a vehicle * @param enable `true` or `false` * @param time Minutes after midnight */ set_scheduled_charging(vehicle_tag: string | number, enable: boolean, time: number): Promise<CommandResponse>; /** * 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). * @param vehicle_tag VIN or id field of a vehicle * @param enable `true` or `false` * @param preconditioning_enabled `true` or `false` * @param preconditioning_weekdays_only `true` or `false` * @param departure_time Minutes after midnight * @param off_peak_charging_enabled `true` or `false` * @param off_peak_charging_weekdays_only `true` or `false` * @param end_off_peak_time Minutes after midnight */ set_scheduled_departure(vehicle_tag: string | number, enable?: boolean, preconditioning_enabled?: boolean, preconditioning_weekdays_only?: boolean, departure_time?: number, off_peak_charging_enabled?: boolean, off_peak_charging_weekdays_only?: boolean, end_off_peak_time?: number): Promise<CommandResponse>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` */ set_sentry_mode(vehicle_tag: string | number, on: boolean): Promise<CommandResponse>; /** * Sets the driver and/or passenger-side cabin temperature (and other zones if sync is enabled). * @param vehicle_tag VIN or id field of a vehicle * @param driver_temp Driver temperature * @param passenger_temp Passenger temperature */ set_temps(vehicle_tag: string | number, driver_temp: number, passenger_temp: number): Promise<CommandResponse>; /** * Turns on Valet Mode and sets a four-digit passcode that must then be entered to disable Valet Mode. * @param vehicle_tag VIN or id field of a vehicle * @param on `true` or `false` * @param password Four-digit passcode */ set_valet_mode(vehicle_tag: string | number, on: boolean, password: string | number): Promise<CommandResponse>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle * @param vehicle_name New name */ set_vehicle_name(vehicle_tag: string | number, vehicle_name: string): Promise<CommandResponse>; /** * Activates Speed Limit Mode with a four-digit PIN. * @param vehicle_tag VIN or id field of a vehicle * @param pin Four-digit PIN */ speed_limit_activate(vehicle_tag: string | number, pin: string | number): Promise<CommandResponse>; /** * Deactivates Speed Limit Mode and resets the associated PIN. * @param vehicle_tag VIN or id field of a vehicle * @param pin Four-digit PIN */ speed_limit_clear_pin(vehicle_tag: string | number, pin: string | number): Promise<CommandResponse>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle */ speed_limit_clear_pin_admin(vehicle_tag: string | number): Promise<CommandResponse>; /** * Deactivates Speed Limit Mode. * @param vehicle_tag VIN or id field of a vehicle * @param pin Four-digit PIN */ speed_limit_deactivate(vehicle_tag: string | number, pin: string | number): Promise<CommandResponse>; /** * Sets the maximum speed allowed when Speed Limit Mode is active. * @param vehicle_tag VIN or id field of a vehicle * @param limit_mph Maximum speed in MPH */ speed_limit_set_limit(vehicle_tag: string | number, limit_mph: number): Promise<CommandResponse>; /** * Controls the panoramic sunroof on the Model S. * @param vehicle_tag VIN or id field of a vehicle * @param state "stop", "close" or "vent" */ sun_roof_control(vehicle_tag: string | number, state: "stop" | "close" | "vent"): Promise<CommandResponse>; /** * Records a drive note. The note parameter is truncated to 80 characters in length. * @param vehicle_tag VIN or id field of a vehicle * @param note Drive note */ take_drivenote(vehicle_tag: string | number, note: string): Promise<CommandResponse>; /** * Turns on HomeLink (used to open and close garage doors). * @param vehicle_tag VIN or id field of a vehicle * @param token * @param lat Latitude * @param lon Longitude */ trigger_homelink(vehicle_tag: string | number, lat: number, lon: number, token?: string): Promise<CommandResponse>; /** * Upcoming calendar entries stored on the vehicle. * @param vehicle_tag VIN or id field of a vehicle * @param calendar_data Calendar data */ upcoming_calendar_entries(vehicle_tag: string | number, calendar_data: string): Promise<CommandResponse>; /** * 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). * @param vehicle_tag VIN or id field of a vehicle * @param command "vent" or "close" * @param lat Latitude * @param lon Longitude */ window_control(vehicle_tag: string | number, command: "vent" | "close", lat: number, lon: number): Promise<CommandResponse>; /** * Returns all allowed drivers for a vehicle. This endpoint is only available for the vehicle owner. * @param vehicle_tag VIN or id field of a vehicle */ drivers(vehicle_tag: string | number): Promise<Record<string, any>[]>; /** * Removes driver access from a vehicle. Share users can only remove their own access. Owners can remove share access or their own. * @param vehicle_tag VIN or id field of a vehicle * @param share_user_id */ drivers_remove(vehicle_tag: string | number, share_user_id?: number): Promise<Record<string, any>>; /** * Returns eligible vehicle subscriptions. * @param vin Vehicle Identification Number */ eligible_subscriptions(vin: string): Promise<Record<string, any>>; /** * Returns eligibile vehicle upgrades. * @param vin Vehicle Identification Number */ eligible_upgrades(vin: string): Promise<Record<string, any>>; /** * Checks whether vehicles can accept Tesla commands protocol for the partner's public key * @param vins list of Vehicle Identification Number * @returns */ fleet_status(vins: Array<string>): Promise<Record<string, any>>; /** * 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. * @param config A dictionary description the fleet telemetry configuration * @returns */ fleet_telemetry_config(config: FleetTelemetryConfig): Promise<Record<string, any>>; /** * Disconnects vehicles to stream telemetry data to self hosted fleet-telemetry server. * @param vehicle_tag VIN or id field of a vehicle * @returns */ fleet_telemetry_config_delete(vehicle_tag: string | number): Promise<Record<string, any>>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle * @returns */ fleet_telemetry_config_get(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Returns vehicles belonging to the account. * @param page Page number * @param per_page Number of items per page */ list(page?: number, per_page?: number): Promise<Record<string, any>>; /** * Returns whether or not mobile access is enabled for the vehicle. * @param vehicle_tag VIN or id field of a vehicle */ mobile_enabled(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Returns the charging sites near the current location of the vehicle. * @param vehicle_tag VIN or id field of a vehicle * @param count * @param radius * @param detail */ nearby_charging_sites(vehicle_tag: string | number, count?: number, radius?: number, detail?: boolean): Promise<Record<string, any>>; /** * Returns vehicle option details. * @param vin Vehicle Identification Number */ options(vin: string): Promise<OptionsResponse>; /** * List of recent alerts * @param vehicle_tag VIN or id field of a vehicle */ recent_alerts(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Returns firmware release notes. * @param vehicle_tag VIN or id field of a vehicle * @param staged * @param language */ release_notes(vehicle_tag: string | number, staged?: boolean, language?: string): Promise<Record<string, any>>; /** * Returns service data. * @param vehicle_tag VIN or id field of a vehicle */ service_data(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Returns the share invites for a vehicle. * @param vehicle_tag VIN or id field of a vehicle */ share_invites(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Creates a share invite for a vehicle. * @param vehicle_tag VIN or id field of a vehicle */ share_invites_create(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Redeems a share invite. * @param code */ share_invites_redeem(code: string): Promise<Record<string, any>>; /** * Revokes a share invite. * @param vehicle_tag VIN or id field of a vehicle * @param id */ share_invites_revoke(vehicle_tag: string | number, id: string): Promise<Record<string, any>>; /** * Signed Commands is a generic endpoint replacing legacy commands. * @param vehicle_tag VIN or id field of a vehicle * @param routable_message */ signed_command(vehicle_tag: string | number, routable_message: string): Promise<Record<string, any>>; /** * Returns information about a vehicle. * @param vehicle_tag VIN or id field of a vehicle */ vehicle(vehicle_tag: string | number): Promise<VehicleResponse>; /** * 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. * @param vehicle_tag VIN or id field of a vehicle * @param endpoints */ vehicle_data(vehicle_tag: string | number, endpoints?: VehicleDataEndpoint[] | string): Promise<VehicleDataResponse>; /** * Wakes the vehicle from sleep, which is a state to minimize idle energy consumption. * @param vehicle_tag VIN or id field of a vehicle */ wake_up(vehicle_tag: string | number): Promise<Record<string, any>>; /** * Returns warranty details. * @param vin */ warranty_details(vin: string): Promise<Record<string, any>>; }