Documentation ¶
Overview ¶
Package vehicle allows clients to send commands to Tesla vehicles over the Internet or BLE.
Index ¶
- Constants
- Variables
- func IsWhitelistOperationComplete(fromVCSEC *vcsec.FromVCSECMessage) (bool, error)
- func UnmarshalVCSECResponse(message *universal.RoutableMessage) (*vcsec.FromVCSECMessage, error)
- type ChargingPolicy
- type ClimateKeeperMode
- type Closure
- type Level
- type SeatPosition
- type Vehicle
- func (v *Vehicle) ActivateSpeedLimit(ctx context.Context, speedLimitPin string) error
- func (v *Vehicle) ActuateTrunk(ctx context.Context) error
- func (v *Vehicle) AddKey(ctx context.Context, publicKey *ecdh.PublicKey, isOwner bool, ...) error
- func (v *Vehicle) AutoSeatAndClimate(ctx context.Context, positions []SeatPosition, enabled bool) error
- func (v *Vehicle) AutoSecureVehicle(ctx context.Context) error
- func (v *Vehicle) CancelSoftwareUpdate(ctx context.Context) error
- func (v *Vehicle) ChangeChargeLimit(ctx context.Context, chargeLimitPercent int32) error
- func (v *Vehicle) ChangeClimateTemp(ctx context.Context, driverCelsius float32, passengerCelsius float32) error
- func (v *Vehicle) ChangeSunroofState(ctx context.Context, sunroofLevel int32) error
- func (v *Vehicle) ChargeMaxRange(ctx context.Context) error
- func (v *Vehicle) ChargePortClose(ctx context.Context) error
- func (v *Vehicle) ChargePortOpen(ctx context.Context) error
- func (v *Vehicle) ChargeStandardRange(ctx context.Context) error
- func (v *Vehicle) ChargeStart(ctx context.Context) error
- func (v *Vehicle) ChargeStop(ctx context.Context) error
- func (v *Vehicle) ClearScheduledDeparture(ctx context.Context) error
- func (v *Vehicle) ClearSpeedLimitPIN(ctx context.Context, speedLimitPin string) error
- func (v *Vehicle) ClimateOff(ctx context.Context) error
- func (v *Vehicle) ClimateOn(ctx context.Context) error
- func (v *Vehicle) CloseChargePort(ctx context.Context) error
- func (v *Vehicle) CloseTrunk(ctx context.Context) error
- func (v *Vehicle) CloseWindows(ctx context.Context) error
- func (v *Vehicle) Connect(ctx context.Context) error
- func (v *Vehicle) DeactivateSpeedLimit(ctx context.Context, speedLimitPin string) error
- func (v *Vehicle) Disconnect()
- func (v *Vehicle) FlashLights(ctx context.Context) error
- func (v *Vehicle) GetNearbyCharging(ctx context.Context) error
- func (v *Vehicle) HonkHorn(ctx context.Context) error
- func (v *Vehicle) KeyInfoBySlot(ctx context.Context, slot uint32) (*vcsec.WhitelistEntryInfo, error)
- func (v *Vehicle) KeySummary(ctx context.Context) (*vcsec.WhitelistInfo, error)
- func (v *Vehicle) LoadCachedSessions(c *cache.SessionCache) error
- func (v *Vehicle) Lock(ctx context.Context) error
- func (v *Vehicle) OpenChargePort(ctx context.Context) error
- func (v *Vehicle) OpenFrunk(ctx context.Context) error
- func (v *Vehicle) OpenTrunk(ctx context.Context) error
- func (v *Vehicle) Ping(ctx context.Context) error
- func (v *Vehicle) PrivateKeyAvailable() bool
- func (v *Vehicle) RemoteDrive(ctx context.Context) error
- func (v *Vehicle) RemoveKey(ctx context.Context, publicKey *ecdh.PublicKey) error
- func (v *Vehicle) ResetPIN(ctx context.Context) error
- func (v *Vehicle) ResetValetPin(ctx context.Context) error
- func (v *Vehicle) ScheduleCharging(ctx context.Context, enabled bool, timeAfterMidnight time.Duration) error
- func (v *Vehicle) ScheduleDeparture(ctx context.Context, departAt, offPeakEndTime time.Duration, ...) error
- func (v *Vehicle) ScheduleSoftwareUpdate(ctx context.Context, delay time.Duration) error
- func (v *Vehicle) Send(ctx context.Context, domain universal.Domain, payload []byte, ...) ([]byte, error)
- func (v *Vehicle) SendAddKeyRequest(ctx context.Context, publicKey *ecdh.PublicKey, isOwner bool, ...) error
- func (v *Vehicle) SendMessage(ctx context.Context, message *universal.RoutableMessage) (protocol.Receiver, error)
- func (v *Vehicle) SessionInfo(ctx context.Context, publicKey *ecdh.PublicKey, domain universal.Domain) (*signatures.SessionInfo, error)
- func (v *Vehicle) SetBioweaponDefenseMode(ctx context.Context, enabled bool, manualOverride bool) error
- func (v *Vehicle) SetCabinOverheatProtection(ctx context.Context, enabled bool, fanOnly bool) error
- func (v *Vehicle) SetCabinOverheatProtectionTemperature(ctx context.Context, level Level) error
- func (v *Vehicle) SetChargingAmps(ctx context.Context, amps int32) error
- func (v *Vehicle) SetClimateKeeperMode(ctx context.Context, mode ClimateKeeperMode, override bool) error
- func (v *Vehicle) SetGuestMode(ctx context.Context, enabled bool) error
- func (v *Vehicle) SetPINToDrive(ctx context.Context, enabled bool, pin string) error
- func (v *Vehicle) SetPreconditioningMax(ctx context.Context, enabled bool, manualOverride bool) error
- func (v *Vehicle) SetSeatCooler(ctx context.Context, level Level, seat SeatPosition) error
- func (v *Vehicle) SetSeatHeater(ctx context.Context, levels map[SeatPosition]Level) error
- func (v *Vehicle) SetSentryMode(ctx context.Context, state bool) error
- func (v *Vehicle) SetSteeringWheelHeater(ctx context.Context, enabled bool) error
- func (v *Vehicle) SetValetMode(ctx context.Context, on bool, valetPassword string) error
- func (v *Vehicle) SetVehicleName(ctx context.Context, name string) error
- func (v *Vehicle) SetVolume(ctx context.Context, volume float32) error
- func (v *Vehicle) SpeedLimitSetLimitMPH(ctx context.Context, speedLimitMPH float64) error
- func (v *Vehicle) StartSession(ctx context.Context, domains []universal.Domain) error
- func (v *Vehicle) TriggerHomelink(ctx context.Context, latitude float32, longitude float32) error
- func (v *Vehicle) Unlock(ctx context.Context) error
- func (v *Vehicle) UpdateCachedSessions(c *cache.SessionCache) error
- func (v *Vehicle) VIN() string
- func (v *Vehicle) VentWindows(ctx context.Context) error
- func (v *Vehicle) Wakeup(ctx context.Context) error
Constants ¶
const ( ClimateKeeperModeOff = carserver.HvacClimateKeeperAction_ClimateKeeperAction_Off ClimateKeeperModeOn = carserver.HvacClimateKeeperAction_ClimateKeeperAction_On ClimateKeeperModeDog = carserver.HvacClimateKeeperAction_ClimateKeeperAction_Dog ClimateKeeperModeCamp = carserver.HvacClimateKeeperAction_ClimateKeeperAction_Camp )
Variables ¶
var ( // ErrNoFleetAPIConnection indicates the client attempted to send a command that terminates on // Tesla's backend (rather than a vehicle), but the Vehicle Connection does not use connector/inet. ErrNoFleetAPIConnection = errors.New("not connected to Fleet API") // ErrVehicleStateUnknown indicates the client attempt to determine if a vehicle supported a // feature before calling vehicle.GetState. ErrVehicleStateUnknown = errors.New("could not determine vehicle state") )
Functions ¶
func IsWhitelistOperationComplete ¶
func IsWhitelistOperationComplete(fromVCSEC *vcsec.FromVCSECMessage) (bool, error)
func UnmarshalVCSECResponse ¶
func UnmarshalVCSECResponse(message *universal.RoutableMessage) (*vcsec.FromVCSECMessage, error)
Types ¶
type ChargingPolicy ¶
type ChargingPolicy int
const ( ChargingPolicyOff ChargingPolicy = iota ChargingPolicyAllDays ChargingPolicyWeekdays )
type ClimateKeeperMode ¶
type ClimateKeeperMode = carserver.HvacClimateKeeperAction_ClimateKeeperAction_E
type SeatPosition ¶
type SeatPosition int64
const ( SeatUnknown SeatPosition = iota SeatFrontLeft SeatFrontRight SeatSecondRowLeft SeatSecondRowLeftBack SeatSecondRowCenter SeatSecondRowRight SeatSecondRowRightBack SeatThirdRowLeft SeatThirdRowRight )
Enumerated type for seats. Values with the Back suffix are used for seat heater/cooler commands, and refer to the backrest. Backrest heaters are only available on some Model S vehicles.
type Vehicle ¶
type Vehicle struct { Flags uint32 // contains filtered or unexported fields }
A Vehicle represents a Tesla vehicle.
func NewVehicle ¶
func NewVehicle(conn connector.Connector, privateKey authentication.ECDHPrivateKey, sessionCache *cache.SessionCache) (*Vehicle, error)
NewVehicle creates a new Vehicle. The privateKey and sessionCache may be nil.
func (*Vehicle) ActivateSpeedLimit ¶
func (*Vehicle) AddKey ¶
func (v *Vehicle) AddKey(ctx context.Context, publicKey *ecdh.PublicKey, isOwner bool, formFactor vcsec.KeyFormFactor) error
AddKey adds a public key to the vehicle's whitelist. If isOwner is true, the new key can authorize changes to vehicle access controls, such as adding/removing other keys.
func (*Vehicle) AutoSeatAndClimate ¶
func (*Vehicle) CancelSoftwareUpdate ¶
func (*Vehicle) ChangeChargeLimit ¶
func (*Vehicle) ChangeClimateTemp ¶
func (*Vehicle) ChangeSunroofState ¶
func (*Vehicle) ChargeStandardRange ¶
func (*Vehicle) ClearScheduledDeparture ¶
func (*Vehicle) ClearSpeedLimitPIN ¶
func (*Vehicle) CloseTrunk ¶
CloseTrunk is not available on all vehicle types.
func (*Vehicle) DeactivateSpeedLimit ¶
func (*Vehicle) Disconnect ¶
func (v *Vehicle) Disconnect()
Disconnect closes the connection to v. Calling this method invokes the underlying connector.Connector.Close method. The connector.Connector interface definition requires that multiple calls to Close() are safe, and so it is safe to defer both this method and the Connector's Close() method; however, Disconnect must be invoked first.
func (*Vehicle) KeyInfoBySlot ¶
func (*Vehicle) KeySummary ¶
func (*Vehicle) LoadCachedSessions ¶
func (v *Vehicle) LoadCachedSessions(c *cache.SessionCache) error
func (*Vehicle) OpenTrunk ¶
OpenTrunk opens the trunk, but note that CloseTrunk is not available on all vehicle types.
func (*Vehicle) Ping ¶
Ping sends an authenticated "no-op" command to the vehicle. If the method returns an non-nil error, then the vehicle is online and recognizes the client's public key.
The error is a protocol.RoutableMessageError then the vehicle is online, but rejected the command for some other reason (for example, it may not recognize the client's public key or may have mobile access disabled).
func (*Vehicle) PrivateKeyAvailable ¶
func (*Vehicle) ResetPIN ¶
ResetPIN clears the saved PIN. You must disable PIN to drive before clearing the PIN. This allows setting a new PIN using SetPINToDrive.
func (*Vehicle) ScheduleCharging ¶
func (v *Vehicle) ScheduleCharging(ctx context.Context, enabled bool, timeAfterMidnight time.Duration) error
ScheduleCharging controls scheduled charging. To start charging at 2:00 AM every day, for example, set timeAfterMidnight to 2*time.Hour.
See the Owner's Manual for more information.
func (*Vehicle) ScheduleDeparture ¶
func (v *Vehicle) ScheduleDeparture(ctx context.Context, departAt, offPeakEndTime time.Duration, preconditioning, offpeak ChargingPolicy) error
ScheduledDeparture tells the vehicle to charge based on an expected departure time.
Set departAt and offPeakEndTime relative to midnight.
func (*Vehicle) ScheduleSoftwareUpdate ¶
func (*Vehicle) Send ¶
func (v *Vehicle) Send(ctx context.Context, domain universal.Domain, payload []byte, auth connector.AuthMethod) ([]byte, error)
Send a payload to a Vehicle. This is a low-level method that most clients will not need.
The method retries until vehicle responds with a terminal result (success or non-transient failure) or the provided context expires.
The domain controls what vehicle subsystem receives the message, and auth controls how the message is authenticated (if it all).
func (*Vehicle) SendAddKeyRequest ¶
func (v *Vehicle) SendAddKeyRequest(ctx context.Context, publicKey *ecdh.PublicKey, isOwner bool, formFactor vcsec.KeyFormFactor) error
SendAddKeyRequest sends an add-key request to the vehicle over BLE. The user must approve the request by tapping their NFC card on the center console and then confirming their intent on the vehicle UI.
If isOwner is true, the new key can authorize changes to vehicle access controls, such as adding/removing other keys.
This function returns nil as soon as the request is transmitted. A nil return value does not guarantee the user has approved the request.
Clients can check if publicKey has been enrolled and synchronized with the infotainment system by attempting to call v.SessionInfo with the domain argument set to universal.Domain_DOMAIN_INFOTAINMENT.
func (*Vehicle) SendMessage ¶
func (v *Vehicle) SendMessage(ctx context.Context, message *universal.RoutableMessage) (protocol.Receiver, error)
SendMessage sends a routable message to the vehicle.
This interface is intended to be used when proxying commands that were authorized by a different entity, notably when using cardless key pairing over BLE. In most cases, you'll want to use Send instead, which automatically resynchronises session state and tries again when encountering certain types of errors.
The SendMessage method only retries on errors for which retransmission of the same message (without modifying anti-replay counters, etc.) is safe and might resolve a transient error.
func (*Vehicle) SessionInfo ¶
func (v *Vehicle) SessionInfo(ctx context.Context, publicKey *ecdh.PublicKey, domain universal.Domain) (*signatures.SessionInfo, error)
func (*Vehicle) SetBioweaponDefenseMode ¶
func (*Vehicle) SetCabinOverheatProtection ¶
func (*Vehicle) SetCabinOverheatProtectionTemperature ¶
func (*Vehicle) SetChargingAmps ¶
func (*Vehicle) SetClimateKeeperMode ¶
func (*Vehicle) SetGuestMode ¶
SetGuestMode enables or disables the vehicle's guest mode.
We recommend users avoid this command unless they are managing a fleet of vehicles and understand the implications of enabling the mode. See official API documentation at https://developer.tesla.com/docs/fleet-api#guest_mode.
func (*Vehicle) SetPINToDrive ¶
SetPINToDrive controls whether the PIN to Drive feature is enabled or not. It is also used to set the PIN.
Once a PIN is set, the vehicle remembers its value even when PIN to Drive is disabled and discards any new PIN provided using this method. To change an existing PIN, first call v.ResetPIN.
func (*Vehicle) SetPreconditioningMax ¶
func (*Vehicle) SetSeatCooler ¶
SetSeatCooler sets seat cooling level.
func (*Vehicle) SetSeatHeater ¶
func (*Vehicle) SetSentryMode ¶
func (*Vehicle) SetSteeringWheelHeater ¶
func (*Vehicle) SetValetMode ¶
func (*Vehicle) SetVehicleName ¶
func (*Vehicle) SpeedLimitSetLimitMPH ¶
func (*Vehicle) StartSession ¶
StartSession performs a handshake with the vehicle that allows the client to begin sending authenticated commands. This will fail if the client's public key has not been paired with the vehicle. If domains is nil, then the client will establish connections with all supported vehicle subsystems. The client may specify a subset of domains if it does not need to connect to all of them; for example, a client that only interacts with VCSEC can avoid waking infotainment.
func (*Vehicle) TriggerHomelink ¶
func (*Vehicle) UpdateCachedSessions ¶
func (v *Vehicle) UpdateCachedSessions(c *cache.SessionCache) error