account

package
v0.0.0-...-81a5b18 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package account implements functions for managing a Tesla account.

Index

Constants

This section is empty.

Variables

View Source
var (

	// UserAgent is sent in HTTP requests.
	//
	// The default value is "<main package name>/<commit hash> tesla-sdk/<version>".
	UserAgent = buildUserAgent()
)

Functions

This section is empty.

Types

type Account

type Account struct {
	// The default UserAgent is constructed from the global UserAgent, but can be overridden.
	UserAgent string

	Host string
	// contains filtered or unexported fields
}

Account allows interaction with a Tesla account.

func New

func New(oauthToken string) (*Account, error)

New returns an Account that can be used to fetch a vehicle.Vehicle.

func (*Account) Get

func (a *Account) Get(ctx context.Context, endpoint string) ([]byte, error)

Get sends an HTTP GET request to endpoint.

The endpoint should contain only the path (e.g., "api/1/vehicles/foo"); the domain is determined by the a.Host.

func (*Account) GetVehicle

func (a *Account) GetVehicle(ctx context.Context, vin string, privateKey authentication.ECDHPrivateKey, sessions *cache.SessionCache) (*vehicle.Vehicle, error)

GetVehicle returns the Vehicle belonging to the account with the provided vin.

Providing a nil privateKey is allowed, but a privateKey is required for most Vehicle interactions. Typically, the privateKey will only be nil when connecting to the Vehicle to send an AddKeyRequest; see documentation in pkg/github.com/Nikola-Software/tesla-vehicle-command/pkg/vehicle. The sessions parameter may also be nil, but providing a cache.SessionCache avoids a round-trip handshake with the Vehicle in subsequent connections.

func (*Account) Post

func (a *Account) Post(ctx context.Context, endpoint string, data []byte) ([]byte, error)

Post sends an HTTP POST request to endpoint.

The endpoint should contain only the path (e.g., "api/1/vehicles/foo"); the domain is determined by the ServerConfig used to create the Account. Returns the HTTP body of the response.

func (*Account) SendVehicleFleetAPICommand

func (a *Account) SendVehicleFleetAPICommand(ctx context.Context, vin, endpoint string, command interface{}) ([]byte, error)

SendVehicleFleetAPICommand sends a command to a vehicle through the REST API.

The command must support JSON serialization.

func (*Account) UpdateKey

func (a *Account) UpdateKey(ctx context.Context, publicKey *ecdh.PublicKey, name string) error

UpdateKey sends metadata about a public key to Tesla's servers.

Vehicles query this information when displaying the list of paired mobile devices and NFC cards in the vehicle's Locks screen. Only the account that first registers a public key can modify its metadata.

Jump to

Keyboard shortcuts

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