account

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: Apache-2.0 Imports: 17 Imported by: 6

Documentation

Overview

Package account implements functions for managing a Tesla account.

Index

Constants

This section is empty.

Variables

This section is empty.

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, userAgent string) (*Account, error)

New returns an Account that can be used to fetch a vehicle.Vehicle. Optional userAgent can be passed in - otherwise it will be generated from code

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/teslamotors/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