vehicle

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 16 Imported by: 12

Documentation

Overview

Package vehicle allows clients to send commands to Tesla vehicles over the Internet or BLE.

Index

Constants

Variables

View Source
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

This section is empty.

Types

type ChargeSchedule added in v0.2.1

type ChargeSchedule = carserver.ChargeSchedule

type ChargingPolicy

type ChargingPolicy int
const (
	ChargingPolicyOff ChargingPolicy = iota
	ChargingPolicyAllDays
	ChargingPolicyWeekdays
)

type Closure

type Closure string
const (
	ClosureTrunk   Closure = "trunk"
	ClosureFrunk   Closure = "frunk"
	ClosureTonneau Closure = "tonneau"
)

type Level

type Level int
const (
	LevelOff Level = iota
	LevelLow
	LevelMed
	LevelHigh
)

type PreconditionSchedule added in v0.2.1

type PreconditionSchedule = carserver.PreconditionSchedule

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 (v *Vehicle) ActivateSpeedLimit(ctx context.Context, speedLimitPin string) error

func (*Vehicle) ActuateTrunk

func (v *Vehicle) ActuateTrunk(ctx context.Context) error

func (*Vehicle) AddChargeSchedule added in v0.2.1

func (v *Vehicle) AddChargeSchedule(ctx context.Context, schedule *ChargeSchedule) error

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) AddKeyWithRole added in v0.1.0

func (v *Vehicle) AddKeyWithRole(ctx context.Context, publicKey *ecdh.PublicKey, role keys.Role, formFactor vcsec.KeyFormFactor) error

AddKeyWithRole adds a public key to the vehicle's whitelist. See Protocol Specification for more information on roles.

func (*Vehicle) AddPreconditionSchedule added in v0.2.1

func (v *Vehicle) AddPreconditionSchedule(ctx context.Context, schedule *PreconditionSchedule) error

func (*Vehicle) AutoSeatAndClimate

func (v *Vehicle) AutoSeatAndClimate(ctx context.Context, positions []SeatPosition, enabled bool) error

func (*Vehicle) AutoSecureVehicle

func (v *Vehicle) AutoSecureVehicle(ctx context.Context) error

func (*Vehicle) BatchRemoveChargeSchedules added in v0.2.1

func (v *Vehicle) BatchRemoveChargeSchedules(ctx context.Context, home, work, other bool) error

func (*Vehicle) BatchRemovePreconditionSchedules added in v0.2.1

func (v *Vehicle) BatchRemovePreconditionSchedules(ctx context.Context, home, work, other bool) error

func (*Vehicle) BodyControllerState added in v0.1.0

func (v *Vehicle) BodyControllerState(ctx context.Context) (*vcsec.VehicleStatus, error)

BodyControllerState returns information about closures, locks, and infotainment sleep status. This method works over BLE even when infotainment is asleep.

func (*Vehicle) CancelSoftwareUpdate

func (v *Vehicle) CancelSoftwareUpdate(ctx context.Context) error

func (*Vehicle) ChangeChargeLimit

func (v *Vehicle) ChangeChargeLimit(ctx context.Context, chargeLimitPercent int32) error

func (*Vehicle) ChangeClimateTemp

func (v *Vehicle) ChangeClimateTemp(ctx context.Context, driverCelsius float32, passengerCelsius float32) error

func (*Vehicle) ChangeSunroofState

func (v *Vehicle) ChangeSunroofState(ctx context.Context, sunroofLevel int32) error

func (*Vehicle) ChargeMaxRange

func (v *Vehicle) ChargeMaxRange(ctx context.Context) error

func (*Vehicle) ChargePortClose

func (v *Vehicle) ChargePortClose(ctx context.Context) error

func (*Vehicle) ChargePortOpen

func (v *Vehicle) ChargePortOpen(ctx context.Context) error

func (*Vehicle) ChargeStandardRange

func (v *Vehicle) ChargeStandardRange(ctx context.Context) error

func (*Vehicle) ChargeStart

func (v *Vehicle) ChargeStart(ctx context.Context) error

func (*Vehicle) ChargeStop

func (v *Vehicle) ChargeStop(ctx context.Context) error

func (*Vehicle) ClearScheduledDeparture

func (v *Vehicle) ClearScheduledDeparture(ctx context.Context) error

func (*Vehicle) ClearSpeedLimitPIN

func (v *Vehicle) ClearSpeedLimitPIN(ctx context.Context, speedLimitPin string) error

func (*Vehicle) ClimateOff

func (v *Vehicle) ClimateOff(ctx context.Context) error

func (*Vehicle) ClimateOn

func (v *Vehicle) ClimateOn(ctx context.Context) error

func (*Vehicle) CloseChargePort

func (v *Vehicle) CloseChargePort(ctx context.Context) error

func (*Vehicle) CloseTonneau added in v0.1.0

func (v *Vehicle) CloseTonneau(ctx context.Context) error

CloseTonneau closes a Cybetruck's tonneau. Has no effect on other vehicles.

func (*Vehicle) CloseTrunk

func (v *Vehicle) CloseTrunk(ctx context.Context) error

CloseTrunk is not available on all vehicle types.

func (*Vehicle) CloseWindows

func (v *Vehicle) CloseWindows(ctx context.Context) error

func (*Vehicle) Connect

func (v *Vehicle) Connect(ctx context.Context) error

Connect opens a connection to the vehicle.

func (*Vehicle) DeactivateSpeedLimit

func (v *Vehicle) DeactivateSpeedLimit(ctx context.Context, speedLimitPin string) error

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) EraseGuestData added in v0.1.0

func (v *Vehicle) EraseGuestData(ctx context.Context) error

EraseGuestData erases user data created while in Guest Mode. This command has no effect unless the vehicle is currently in Guest Mode.

func (*Vehicle) FlashLights

func (v *Vehicle) FlashLights(ctx context.Context) error

func (*Vehicle) GetNearbyCharging

func (v *Vehicle) GetNearbyCharging(ctx context.Context) error

func (*Vehicle) HonkHorn

func (v *Vehicle) HonkHorn(ctx context.Context) error

func (*Vehicle) KeyInfoBySlot

func (v *Vehicle) KeyInfoBySlot(ctx context.Context, slot uint32) (*vcsec.WhitelistEntryInfo, error)

func (*Vehicle) KeySummary

func (v *Vehicle) KeySummary(ctx context.Context) (*vcsec.WhitelistInfo, error)

func (*Vehicle) LoadCachedSessions

func (v *Vehicle) LoadCachedSessions(c *cache.SessionCache) error

func (*Vehicle) Lock

func (v *Vehicle) Lock(ctx context.Context) error

func (*Vehicle) OpenChargePort

func (v *Vehicle) OpenChargePort(ctx context.Context) error

func (*Vehicle) OpenFrunk

func (v *Vehicle) OpenFrunk(ctx context.Context) error

OpenTrunk opens the frunk. There is no remote way to close the frunk!

func (*Vehicle) OpenTonneau added in v0.1.0

func (v *Vehicle) OpenTonneau(ctx context.Context) error

OpenTonneau opens a Cybetruck's tonneau. Has no effect on other vehicles.

func (*Vehicle) OpenTrunk

func (v *Vehicle) OpenTrunk(ctx context.Context) error

OpenTrunk opens the trunk, but note that CloseTrunk is not available on all vehicle types.

func (*Vehicle) Ping

func (v *Vehicle) Ping(ctx context.Context) error

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 (v *Vehicle) PrivateKeyAvailable() bool

func (*Vehicle) RemoteDrive

func (v *Vehicle) RemoteDrive(ctx context.Context) error

func (*Vehicle) RemoveChargeSchedule added in v0.2.1

func (v *Vehicle) RemoveChargeSchedule(ctx context.Context, id uint64) error

func (*Vehicle) RemoveKey

func (v *Vehicle) RemoveKey(ctx context.Context, publicKey *ecdh.PublicKey) error

func (*Vehicle) RemovePreconditionSchedule added in v0.2.1

func (v *Vehicle) RemovePreconditionSchedule(ctx context.Context, id uint64) error

func (*Vehicle) ResetPIN

func (v *Vehicle) ResetPIN(ctx context.Context) error

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) ResetValetPin

func (v *Vehicle) ResetValetPin(ctx context.Context) error

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 (v *Vehicle) ScheduleSoftwareUpdate(ctx context.Context, delay time.Duration) error

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) SendAddKeyRequestWithRole added in v0.1.0

func (v *Vehicle) SendAddKeyRequestWithRole(ctx context.Context, publicKey *ecdh.PublicKey, role keys.Role, formFactor vcsec.KeyFormFactor) error

SendAddKeyRequestWithRole behaves like [SendAddKeyRequest] except the new key's role can be specified explicitly. See Protocol Specification for more information on roles.

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 (v *Vehicle) SetBioweaponDefenseMode(ctx context.Context, enabled bool, manualOverride bool) error

func (*Vehicle) SetCabinOverheatProtection

func (v *Vehicle) SetCabinOverheatProtection(ctx context.Context, enabled bool, fanOnly bool) error

func (*Vehicle) SetCabinOverheatProtectionTemperature

func (v *Vehicle) SetCabinOverheatProtectionTemperature(ctx context.Context, level Level) error

func (*Vehicle) SetChargingAmps

func (v *Vehicle) SetChargingAmps(ctx context.Context, amps int32) error

func (*Vehicle) SetClimateKeeperMode

func (v *Vehicle) SetClimateKeeperMode(ctx context.Context, mode ClimateKeeperMode, override bool) error

func (*Vehicle) SetGuestMode

func (v *Vehicle) SetGuestMode(ctx context.Context, enabled bool) error

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/endpoints/vehicle-commands#guest-mode

func (*Vehicle) SetMaxLatency added in v0.1.0

func (v *Vehicle) SetMaxLatency(latency time.Duration)

SetMaxLatency sets the threshold used by the client to discard clock-synchronization messages from the vehicle that take too long to arrive.

func (*Vehicle) SetPINToDrive

func (v *Vehicle) SetPINToDrive(ctx context.Context, enabled bool, pin string) error

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 (v *Vehicle) SetPreconditioningMax(ctx context.Context, enabled bool, manualOverride bool) error

func (*Vehicle) SetSeatCooler

func (v *Vehicle) SetSeatCooler(ctx context.Context, level Level, seat SeatPosition) error

SetSeatCooler sets seat cooling level.

func (*Vehicle) SetSeatHeater

func (v *Vehicle) SetSeatHeater(ctx context.Context, levels map[SeatPosition]Level) error

func (*Vehicle) SetSentryMode

func (v *Vehicle) SetSentryMode(ctx context.Context, state bool) error

func (*Vehicle) SetSteeringWheelHeater

func (v *Vehicle) SetSteeringWheelHeater(ctx context.Context, enabled bool) error

func (*Vehicle) SetValetMode

func (v *Vehicle) SetValetMode(ctx context.Context, on bool, valetPassword string) error

func (*Vehicle) SetVehicleName

func (v *Vehicle) SetVehicleName(ctx context.Context, name string) error

func (*Vehicle) SetVolume

func (v *Vehicle) SetVolume(ctx context.Context, volume float32) error

SetVolume to a value between 0 and 10.

func (*Vehicle) SpeedLimitSetLimitMPH

func (v *Vehicle) SpeedLimitSetLimitMPH(ctx context.Context, speedLimitMPH float64) error

func (*Vehicle) StartSession

func (v *Vehicle) StartSession(ctx context.Context, domains []universal.Domain) error

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) StopTonneau added in v0.1.0

func (v *Vehicle) StopTonneau(ctx context.Context) error

StopTonneau tells a Cybetruck to stop moving its tonneau. Has no effect on other vehicles.

func (*Vehicle) ToggleMediaPlayback added in v0.1.0

func (v *Vehicle) ToggleMediaPlayback(ctx context.Context) error
func (v *Vehicle) TriggerHomelink(ctx context.Context, latitude float32, longitude float32) error

func (*Vehicle) Unlock

func (v *Vehicle) Unlock(ctx context.Context) error

func (*Vehicle) UpdateCachedSessions

func (v *Vehicle) UpdateCachedSessions(c *cache.SessionCache) error

func (*Vehicle) VIN

func (v *Vehicle) VIN() string

func (*Vehicle) VentWindows

func (v *Vehicle) VentWindows(ctx context.Context) error

func (*Vehicle) Wakeup

func (v *Vehicle) Wakeup(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL