tesla

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 22 Imported by: 1

README

tesla-api-go

Test

This is an unofficial Go Tesla API client based on the documentation https://github.com/timdorr/tesla-api

Installation

go get github.com/maodijim/tesla-api-go

Usage

import "github.com/maodijim/tesla-api-go"
// with credential
teslaApi := tesla.NewTeslaApi(username, password, "", true)

// with refresh token
teslaApi := tesla.NewTeslaApi("", "", "eyJ...", true)

teslaApi.Login()
vehicles, err := teslaApi.ListVehicles()

teslaApi.SetActiveVehicle(vehicles[0])

teslaApi.WakeUp()
teslaApi.DoorUnlock()
teslaApi.DoorLock()
teslaApi.ChargeDoorOpen()
teslaApi.ChargeDoorClose()
teslaApi.ChargeMaxRange()
teslaApi.SetChargeLimit(50)
teslaApi.SetClimateTemp(23.5, 23.5)
teslaApi.SetSeatHeater(tesla.SeatFrontLeft, 3)
teslaApi.ActuateTrunk(tesla.FrontTrunkType)

Implemented

  • Auth
    • username & password
    • refresh token
    • MFA
  • Vehicle
  • /api/1/vehicles
  • /api/1/vehicles/{id}
  • State
    • /api/1/vehicles/{id}/vehicle_data
    • /api/1/vehicles/{id}/data_request/charge_state
    • /api/1/vehicles/{id}/data_request/climate_state
    • /api/1/vehicles/{id}/data_request/drive_state
    • /api/1/vehicles/{id}/data_request/gui_settings
    • /api/1/vehicles/{id}/data_request/vehicle_state
    • /api/1/vehicles/{id}/data_request/vehicle_config
    • /api/1/vehicles/{id}/mobile_enabled
    • /api/1/vehicles/{id}/nearby_charging_sites
  • Commands
    • Wake
      • /api/1/vehicles/{id}/wake_up
    • Alerts
      • /api/1/vehicles/{id}/command/honk_horn
      • /api/1/vehicles/{id}/command/flash_lights
    • Remote Start
      • /api/1/vehicles/{id}/command/remote_start_drive
    • Homelink
      • /api/1/vehicles/{id}/command/trigger_homelink
    • /api/1/vehicles/{id}/command/speed_limit_set_limit
      • /api/1/vehicles/{id}/command/speed_limit_set_limit
      • /api/1/vehicles/{id}/command/speed_limit_activate
      • /api/1/vehicles/{id}/command/speed_limit_deactivate
      • /api/1/vehicles/{id}/command/speed_limit_clear_pin
    • Valet Mode
      • /api/1/vehicles/{id}/command/set_valet_mode
      • /api/1/vehicles/{id}/command/reset_valet_pin
    • Sentry Mode
      • /api/1/vehicles/{id}/command/set_sentry_mode
    • Doors
      • /api/1/vehicles/{id}/command/door_unlock
      • /api/1/vehicles/{id}/command/door_lock
    • Trunk
      • /api/1/vehicles/{id}/command/actuate_trunk
    • Windows
      • /api/1/vehicles/{id}/command/window_control
    • Sunroof
      • /api/1/vehicles/{id}/command/sun_roof_control
    • Charging
      • /api/1/vehicles/{id}/command/charge_port_door_open
      • /api/1/vehicles/{id}/command/charge_port_door_close
      • /api/1/vehicles/{id}/command/charge_start
      • /api/1/vehicles/{id}/command/charge_stop
      • /api/1/vehicles/{id}/command/charge_standard
      • /api/1/vehicles/{id}/command/charge_max_range
      • /api/1/vehicles/{id}/command/set_charge_limit
      • /api/1/vehicles/{id}/command/set_charging_amps
      • /api/1/vehicles/{id}/command/set_scheduled_charging
      • /api/1/vehicles/{id}/command/set_scheduled_departure
      • api/1/vehicles/{vehicle_id}/charge_history
      • super charger history
    • Climate
      • /api/1/vehicles/{id}/command/auto_conditioning_start
      • /api/1/vehicles/{id}/command/auto_conditioning_stop
      • /api/1/vehicles/{id}/command/set_temps
      • /api/1/vehicles/{id}/command/set_preconditioning_max
      • /api/1/vehicles/{id}/command/remote_seat_heater_request
      • /api/1/vehicles/{id}/command/remote_steering_wheel_heater_request
    • Media
      • /api/1/vehicles/{id}/command/media_toggle_playback
      • /api/1/vehicles/{id}/command/media_next_track
      • /api/1/vehicles/{id}/command/media_prev_track
      • /api/1/vehicles/{id}/command/media_next_fav
      • /api/1/vehicles/{id}/command/media_prev_fav
      • /api/1/vehicles/{id}/command/media_volume_up
      • /api/1/vehicles/{id}/command/media_volume_down
    • Sharing
      • /api/1/vehicles/{id}/command/share
    • Software Updates
      • /api/1/vehicles/{id}/command/schedule_software_update
      • /api/1/vehicles/{id}/command/cancel_software_update
    • Remote Toybox
      • /api/1/vehicles/{id}/command/remote_boombox
  • Streaming
  • Autopark/Summon
  • Solar
  • Powerwall

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAmps          = errors.New("invalid charge amps must be within 1 to 1000")
	ErrInvalidChargePercent = errors.New("invalid charge limit must be within 0 to 100")
	ErrInvalidChargeTime    = errors.New("invalid charge time must be within 0 to 1440")
)
View Source
var (
	ErrInvalidSeatHeater   = errors.New("invalid heater must be between 0 to 5")
	ErrInvalidSeatHeaterLv = errors.New("invalid heater level must be between 0 to 3")
)
View Source
var (
	ErrVehicleInSleep     = errors.New(`vehicle unavailable: {:error=>"vehicle unavailable:"}`)
	ErrInvalidToken       = errors.New("invalid bearer token")
	ErrNoActiveVehicle    = errors.New("no active vehicle please run SetActiveVehicle")
	ErrWakeTimeout        = errors.New("wake up vehicle timed out")
	ErrCmdNotSupportedVer = errors.New("not supported on this version")
	ErrNoWebRefreshToken  = errors.New("no web refresh token provided")
	WakeTimeoutSec        = 30
	// AutoWakeUp Automatically wake up vehicle if vehicle in sleep
	AutoWakeUp = true

	ChargeStateReqInterval   = defaultReqInterval
	DriveStateReqInterval    = defaultReqInterval
	ClimateStateReqInterval  = defaultReqInterval
	VehicleStateReqInterval  = defaultReqInterval
	VehicleConfigReqInterval = defaultReqInterval
	GuiSettingReqInterval    = defaultReqInterval
)
View Source
var (
	ErrInvalidPinFormat = errors.New("invalid pin must be 4 digit pin")
)
View Source
var ErrNoHomeLinkNearBy = errors.New("no homelink nearby")

Functions

This section is empty.

Types

type AuthReq

type AuthReq struct {
	AuthBaseUrl   string
	CodeVerifier  string
	CodeChallenge string
	// contains filtered or unexported fields
}

type AuthRes

type AuthRes struct {
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	State        string `json:"state,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	CreatedAt    int    `json:"created_at,omitempty"`
	IdToken      string `json:"id_token,omitempty"`
	BaseRes
}

type BaseRes

type BaseRes struct {
	Err    string `json:"error,omitempty"`
	ErrDes string `json:"error_description,omitempty"`
	ErrUri string `json:"error_uri,omitempty"`
	// fields for tesla.com/teslaaccount response
	Message string `json:"message,omitempty"`
	Code    int    `json:"code,omitempty"`
	Success bool   `json:"success,omitempty"`
}

type ChargeHistory

type ChargeHistory struct {
	ScreenTitle  string `json:"screen_title"`
	TotalCharged struct {
		Value          string `json:"value"`
		RawValue       int    `json:"raw_value"`
		AfterAdornment string `json:"after_adornment"`
		Title          string `json:"title"`
	} `json:"total_charged"`
	TotalChargedBreakdown struct {
		Home struct {
			Value          string `json:"value"`
			AfterAdornment string `json:"after_adornment"`
			SubTitle       string `json:"sub_title"`
		} `json:"home"`
		SuperCharger struct {
			Value          string `json:"value"`
			AfterAdornment string `json:"after_adornment"`
			SubTitle       string `json:"sub_title"`
		} `json:"super_charger"`
		Other struct {
			Value          string `json:"value"`
			RawValue       int    `json:"raw_value"`
			AfterAdornment string `json:"after_adornment"`
			SubTitle       string `json:"sub_title"`
		} `json:"other"`
	} `json:"total_charged_breakdown"`
	ChargingHistoryGraph ChargingHistoryGraph `json:"charging_history_graph"`
}

type ChargeSite

type ChargeSite struct {
	Location struct {
		Lat  float64 `json:"lat"`
		Long float64 `json:"long"`
	} `json:"location"`
	Name            string  `json:"name"`
	Type            string  `json:"type"`
	DistanceMiles   float64 `json:"distance_miles"`
	AvailableStalls int     `json:"available_stalls"`
	TotalStalls     int     `json:"total_stalls"`
	SiteClosed      bool    `json:"site_closed"`
}

type ChargeSiteRes

type ChargeSiteRes struct {
	BaseRes
	Response struct {
		CongestionSyncTimeUtcSecs int          `json:"congestion_sync_time_utc_secs"`
		DestinationCharging       []ChargeSite `json:"destination_charging"`
		Superchargers             []ChargeSite `json:"superchargers"`
	} `json:"response"`
}

type ChargeState

type ChargeState struct {
	BatteryHeaterOn             bool        `json:"battery_heater_on"`
	BatteryLevel                int         `json:"battery_level"`
	BatteryRange                float64     `json:"battery_range"`
	ChargeAmps                  int         `json:"charge_amps"`
	ChargeCurrentRequest        int         `json:"charge_current_request"`
	ChargeCurrentRequestMax     int         `json:"charge_current_request_max"`
	ChargeEnableRequest         bool        `json:"charge_enable_request"`
	ChargeEnergyAdded           float64     `json:"charge_energy_added"`
	ChargeLimitSoc              int         `json:"charge_limit_soc"`
	ChargeLimitSocMax           int         `json:"charge_limit_soc_max"`
	ChargeLimitSocMin           int         `json:"charge_limit_soc_min"`
	ChargeLimitSocStd           int         `json:"charge_limit_soc_std"`
	ChargeMilesAddedIdeal       float64     `json:"charge_miles_added_ideal"`
	ChargeMilesAddedRated       float64     `json:"charge_miles_added_rated"`
	ChargePortColdWeatherMode   interface{} `json:"charge_port_cold_weather_mode"`
	ChargePortDoorOpen          bool        `json:"charge_port_door_open"`
	ChargePortLatch             string      `json:"charge_port_latch"`
	ChargeRate                  float64     `json:"charge_rate"`
	ChargeToMaxRange            bool        `json:"charge_to_max_range"`
	ChargerActualCurrent        int         `json:"charger_actual_current"`
	ChargerPhases               int         `json:"charger_phases"`
	ChargerPilotCurrent         int         `json:"charger_pilot_current"`
	ChargerPower                int         `json:"charger_power"`
	ChargerVoltage              int         `json:"charger_voltage"`
	ChargingState               string      `json:"charging_state"`
	ConnChargeCable             string      `json:"conn_charge_cable"`
	EstBatteryRange             float64     `json:"est_battery_range"`
	FastChargerBrand            string      `json:"fast_charger_brand"`
	FastChargerPresent          bool        `json:"fast_charger_present"`
	FastChargerType             string      `json:"fast_charger_type"`
	IdealBatteryRange           float64     `json:"ideal_battery_range"`
	ManagedChargingActive       bool        `json:"managed_charging_active"`
	ManagedChargingStartTime    int         `json:"managed_charging_start_time"`
	ManagedChargingUserCanceled bool        `json:"managed_charging_user_canceled"`
	MaxRangeChargeCounter       int         `json:"max_range_charge_counter"`
	MinutesToFullCharge         int         `json:"minutes_to_full_charge"`
	NotEnoughPowerToHeat        bool        `json:"not_enough_power_to_heat"`
	ScheduledChargingPending    bool        `json:"scheduled_charging_pending"`
	ScheduledChargingStartTime  int         `json:"scheduled_charging_start_time"`
	TimeToFullCharge            float64     `json:"time_to_full_charge"`
	Timestamp                   int64       `json:"timestamp"`
	TripCharging                bool        `json:"trip_charging"`
	UsableBatteryLevel          int         `json:"usable_battery_level"`
	UserChargeEnableRequest     interface{} `json:"user_charge_enable_request"`
}

func (ChargeState) GetMaxAmps

func (c ChargeState) GetMaxAmps() int

func (ChargeState) GetState

func (c ChargeState) GetState() string

type ChargingHistoryGraph

type ChargingHistoryGraph struct {
	DataPoints []struct {
		Timestamp struct {
			Timestamp struct {
				Seconds int `json:"seconds"`
			} `json:"timestamp"`
			DisplayString string `json:"display_string"`
		} `json:"timestamp"`
		Values []struct {
			Value          string `json:"value"`
			RawValue       int    `json:"raw_value,omitempty"`
			AfterAdornment string `json:"after_adornment"`
			SubTitle       string `json:"sub_title,omitempty"`
		} `json:"values"`
	} `json:"data_points"`
	Period struct {
		StartTimestamp struct {
			Seconds int `json:"seconds"`
		} `json:"start_timestamp"`
		EndTimestamp struct {
			Seconds int `json:"seconds"`
		} `json:"end_timestamp"`
	} `json:"period"`
	Interval int `json:"interval"`
	XLabels  []struct {
		Value    string `json:"value"`
		RawValue int    `json:"raw_value"`
	} `json:"x_labels"`
	YLabels []struct {
		Value          string  `json:"value"`
		RawValue       float64 `json:"raw_value,omitempty"`
		AfterAdornment string  `json:"after_adornment,omitempty"`
	} `json:"y_labels"`
	HorizontalGridLines []float64 `json:"horizontal_grid_lines"`
	VerticalGridLines   []float64 `json:"vertical_grid_lines"`
	DiscreteX           bool      `json:"discrete_x"`
	YRangeMax           int       `json:"y_range_max"`
}

type ClimateState

type ClimateState struct {
	BatteryHeater              bool    `json:"battery_heater"`
	BatteryHeaterNoPower       bool    `json:"battery_heater_no_power"`
	ClimateKeeperMode          string  `json:"climate_keeper_mode"`
	DefrostMode                int     `json:"defrost_mode"`
	DriverTempSetting          float64 `json:"driver_temp_setting"`
	FanStatus                  int     `json:"fan_status"`
	InsideTemp                 float64 `json:"inside_temp"`
	IsAutoConditioningOn       bool    `json:"is_auto_conditioning_on"`
	IsClimateOn                bool    `json:"is_climate_on"`
	IsFrontDefrosterOn         bool    `json:"is_front_defroster_on"`
	IsPreconditioning          bool    `json:"is_preconditioning"`
	IsRearDefrosterOn          bool    `json:"is_rear_defroster_on"`
	LeftTempDirection          int     `json:"left_temp_direction"`
	MaxAvailTemp               float64 `json:"max_avail_temp"`
	MinAvailTemp               float64 `json:"min_avail_temp"`
	OutsideTemp                float64 `json:"outside_temp"`
	PassengerTempSetting       float64 `json:"passenger_temp_setting"`
	RemoteHeaterControlEnabled bool    `json:"remote_heater_control_enabled"`
	RightTempDirection         int     `json:"right_temp_direction"`
	SeatHeaterLeft             int     `json:"seat_heater_left"`
	SeatHeaterRight            int     `json:"seat_heater_right"`
	SideMirrorHeaters          bool    `json:"side_mirror_heaters"`
	Timestamp                  int64   `json:"timestamp"`
	WiperBladeHeater           bool    `json:"wiper_blade_heater"`
}

type CommandsRes

type CommandsRes struct {
	BaseRes
	Response struct {
		Reason string `json:"reason"`
		Result bool   `json:"result"`
	} `json:"response"`
}

type CommonRes added in v0.3.0

type CommonRes struct {
	BaseRes
	Response struct {
		ReleaseNotes    []ReleaseNote `json:"release_notes"`
		DeployedVersion string        `json:"deployed_version"`
		StagedVersion   string        `json:"staged_version"`
	} `json:"response"`
}

type DriveState

type DriveState struct {
	GpsAsOf                 int     `json:"gps_as_of"`
	Heading                 int     `json:"heading"`
	Latitude                float64 `json:"latitude"`
	Longitude               float64 `json:"longitude"`
	NativeLatitude          float64 `json:"native_latitude"`
	NativeLocationSupported int     `json:"native_location_supported"`
	NativeLongitude         float64 `json:"native_longitude"`
	NativeType              string  `json:"native_type"`
	Power                   int     `json:"power"`
	ShiftState              string  `json:"shift_state"`
	Speed                   int     `json:"speed"`
	Timestamp               int64   `json:"timestamp"`
}

type GuiSettings

type GuiSettings struct {
	Gui24HourTime       bool   `json:"gui_24_hour_time"`
	GuiChargeRateUnits  string `json:"gui_charge_rate_units"`
	GuiDistanceUnits    string `json:"gui_distance_units"`
	GuiRangeDisplay     string `json:"gui_range_display"`
	GuiTemperatureUnits string `json:"gui_temperature_units"`
	ShowRangeUnits      bool   `json:"show_range_units"`
	Timestamp           int64  `json:"timestamp"`
}

type JwtAccessClaims

type JwtAccessClaims struct {
	Aud  interface{}            `json:"aud"`
	Azp  string                 `json:"azp"`
	Sub  string                 `json:"sub"`
	Scp  []string               `json:"scp"`
	Amr  []string               `json:"amr"`
	Data map[string]interface{} `json:"data,omitempty"`
	jwt.StandardClaims
}

func UnmarshallJWT

func UnmarshallJWT(token string) (result *JwtAccessClaims)

type MediaInfo added in v0.2.6

type MediaInfo struct {
	AudioVolume          float64 `json:"audio_volume"`
	AudioVolumeIncrement float64 `json:"audio_volume_increment"`
	AudioVolumeMax       float64 `json:"audio_volume_max"`
	MediaPlaybackStatus  string  `json:"media_playback_status"`
	NowPlayingAlbum      string  `json:"now_playing_album"`
	NowPlayingArtist     string  `json:"now_playing_artist"`
	NowPlayingDuration   int     `json:"now_playing_duration"`
	NowPlayingElapsed    int     `json:"now_playing_elapsed"`
	NowPlayingSource     string  `json:"now_playing_source"`
	NowPlayingStation    string  `json:"now_playing_station"`
	NowPlayingTitle      string  `json:"now_playing_title"`
}

type ReleaseNote added in v0.3.0

type ReleaseNote struct {
	Title           string `json:"title,omitempty"`
	Subtitle        string `json:"subtitle,omitempty"`
	Description     string `json:"description,omitempty"`
	CustomerVersion string `json:"customer_version,omitempty"`
	ImageUrl        string `json:"image_url,omitempty"`
}

type SeatType

type SeatType int
const (
	SeatFrontLeft  SeatType = 0
	SeatFrontRight SeatType = 1
	SeatRearLeft   SeatType = 2
	SeatRearCenter SeatType = 4
	SeatRearRight  SeatType = 5
)

type SoftwareUpdate added in v0.2.0

type SoftwareUpdate struct {
	DownloadPerc           int    `json:"download_perc"`
	ExpectedDurationSec    int    `json:"expected_duration_sec"`
	InstallPerc            int    `json:"install_perc"`
	Status                 string `json:"status"`
	Version                string `json:"version"`
	WarningTimeRemainingMs int    `json:"warning_time_remaining_ms"`
	ScheduledTimeMs        int64  `json:"scheduled_time_ms"`
}

SoftwareUpdate Status: scheduled, available, installing, downloading

type Solar

type Solar struct {
	EnergySiteId         int64  `json:"energy_site_id"`
	ResourceType         string `json:"resource_type"`
	Id                   string `json:"id"`
	AssetSiteId          string `json:"asset_site_id"`
	SolarPower           int    `json:"solar_power"`
	SolarType            string `json:"solar_type"`
	SyncGridAlertEnabled bool   `json:"sync_grid_alert_enabled"`
	BreakerAlertEnabled  bool   `json:"breaker_alert_enabled"`
	Components           struct {
		Battery    bool   `json:"battery"`
		Solar      bool   `json:"solar"`
		SolarType  string `json:"solar_type"`
		Grid       bool   `json:"grid"`
		LoadMeter  bool   `json:"load_meter"`
		MarketType string `json:"market_type"`
	} `json:"components"`
}

type SuperChargingHistory

type SuperChargingHistory struct {
	BillingType         string      `json:"billingType"`
	CabinetId           string      `json:"cabinetId"`
	ChargeSessionId     string      `json:"chargeSessionId"`
	ChargeStartDateTime time.Time   `json:"chargeStartDateTime"`
	ChargeStopDateTime  time.Time   `json:"chargeStopDateTime"`
	ChargingPackage     interface{} `json:"chargingPackage"`
	ChargingSiteType    string      `json:"chargingSiteType"`
	CountryCode         string      `json:"countryCode"`
	Credit              interface{} `json:"credit"`
	Din                 string      `json:"din"`
	DisputeDetails      interface{} `json:"disputeDetails"`
	FapiaoDetails       interface{} `json:"fapiaoDetails"`
	Fees                []struct {
		SessionFeeId  int     `json:"sessionFeeId"`
		FeeType       string  `json:"feeType"`
		CurrencyCode  string  `json:"currencyCode"`
		PricingType   string  `json:"pricingType"`
		RateBase      float64 `json:"rateBase"`
		RateTier1     int     `json:"rateTier1"`
		RateTier2     int     `json:"rateTier2"`
		RateTier3     int     `json:"rateTier3"`
		RateTier4     int     `json:"rateTier4"`
		UsageBase     int     `json:"usageBase"`
		UsageTier1    int     `json:"usageTier1"`
		UsageTier2    int     `json:"usageTier2"`
		UsageTier3    int     `json:"usageTier3"`
		UsageTier4    int     `json:"usageTier4"`
		TotalBase     float64 `json:"totalBase"`
		TotalTier1    int     `json:"totalTier1"`
		TotalTier2    int     `json:"totalTier2"`
		TotalTier3    int     `json:"totalTier3"`
		TotalTier4    int     `json:"totalTier4"`
		TotalDue      float64 `json:"totalDue"`
		NetDue        float64 `json:"netDue"`
		Uom           string  `json:"uom"`
		IsPaid        bool    `json:"isPaid"`
		Status        string  `json:"status"`
		ProcessFlagId int     `json:"processFlagId"`
	} `json:"fees"`
	Invoices []struct {
		FileName    string `json:"fileName"`
		ContentId   string `json:"contentId"`
		InvoiceType string `json:"invoiceType"`
		BeInvoiceId string `json:"beInvoiceId"`
		ProcessFlag int    `json:"processFlag"`
	} `json:"invoices"`
	IsDcEnforced     bool      `json:"isDcEnforced"`
	PostId           string    `json:"postId"`
	ProgramType      string    `json:"programType"`
	SessionId        int       `json:"sessionId"`
	SiteLocationName string    `json:"siteLocationName"`
	SurveyCompleted  bool      `json:"surveyCompleted"`
	SurveyType       string    `json:"surveyType"`
	UnlatchDateTime  time.Time `json:"unlatchDateTime"`
	VehicleMakeType  string    `json:"vehicleMakeType"`
	Vin              string    `json:"vin"`
}

type TeslaAcctRes

type TeslaAcctRes struct {
	BaseRes
	Data interface{} `json:"data"`
}

type TeslaApi

type TeslaApi struct {
	AuthReq
	// contains filtered or unexported fields
}

func NewTeslaApi

func NewTeslaApi(username, password, refreshToken string, global bool) *TeslaApi

NewTeslaApi when using username and password will log in via browser

func (*TeslaApi) ActivateSpeedLimit

func (t *TeslaApi) ActivateSpeedLimit(pin string) (cmdRes *CommandsRes, err error)

func (*TeslaApi) ActuateTrunk

func (t *TeslaApi) ActuateTrunk(trunk TrunkType) (cmdRes *CommandsRes, err error)

func (*TeslaApi) CancelSoftwareUpdate added in v0.2.0

func (t *TeslaApi) CancelSoftwareUpdate() (cmdRes *CommandsRes, err error)

func (*TeslaApi) ChargeDoorClose

func (t *TeslaApi) ChargeDoorClose() (o *CommandsRes, err error)

func (*TeslaApi) ChargeDoorOpen

func (t *TeslaApi) ChargeDoorOpen() (o *CommandsRes, err error)

func (*TeslaApi) ChargeMaxRange

func (t *TeslaApi) ChargeMaxRange() (o *CommandsRes, err error)

func (*TeslaApi) ChargeStandard

func (t *TeslaApi) ChargeStandard() (o *CommandsRes, err error)

func (*TeslaApi) ChargeStart

func (t *TeslaApi) ChargeStart() (o *CommandsRes, err error)

func (*TeslaApi) ChargeState

func (t *TeslaApi) ChargeState() (cd *ChargeState, err error)

ChargeState get vehicle charge state

func (*TeslaApi) ChargeStop

func (t *TeslaApi) ChargeStop() (o *CommandsRes, err error)

func (*TeslaApi) ClearSpeedLimitPin

func (t *TeslaApi) ClearSpeedLimitPin(pin string) (cmdRes *CommandsRes, err error)

func (*TeslaApi) ClimateAutoAcStart

func (t *TeslaApi) ClimateAutoAcStart() (o *CommandsRes, err error)

func (*TeslaApi) ClimateAutoAcStop

func (t *TeslaApi) ClimateAutoAcStop() (o *CommandsRes, err error)

func (*TeslaApi) ClimateState

func (t *TeslaApi) ClimateState() (cs *ClimateState, err error)

func (*TeslaApi) DeactivateSpeedLimit

func (t *TeslaApi) DeactivateSpeedLimit(pin string) (cmdRes *CommandsRes, err error)

func (*TeslaApi) DoorLock

func (t *TeslaApi) DoorLock() (cmdRes *CommandsRes, err error)

func (*TeslaApi) DoorUnlock

func (t *TeslaApi) DoorUnlock() (cmdRes *CommandsRes, err error)

DoorUnlock Unlocks the doors to the car. Extends the handles on the S and X.

func (*TeslaApi) DriveState

func (t *TeslaApi) DriveState() (ds *DriveState, err error)

func (*TeslaApi) FlashLights

func (t *TeslaApi) FlashLights() (cmdRes *CommandsRes, err error)

FlashLights Flashes the headlights once

func (*TeslaApi) GetActiveVehicle added in v0.1.0

func (t *TeslaApi) GetActiveVehicle() Vehicle

func (*TeslaApi) GetChargeHistory

func (t *TeslaApi) GetChargeHistory() (ch *ChargeHistory, err error)

func (*TeslaApi) GetId added in v0.1.0

func (t *TeslaApi) GetId() int64

func (*TeslaApi) GetSuperChargingHistory

func (t *TeslaApi) GetSuperChargingHistory() (ch []SuperChargingHistory, err error)

GetSuperChargingHistory only works when logging in via username and password

func (*TeslaApi) GetVehicleId added in v0.1.0

func (t *TeslaApi) GetVehicleId() int

func (*TeslaApi) GetVehicleName added in v0.1.0

func (t *TeslaApi) GetVehicleName() string

func (*TeslaApi) GetVehicleOptions added in v0.1.0

func (t *TeslaApi) GetVehicleOptions() string

func (*TeslaApi) GetVin added in v0.1.0

func (t *TeslaApi) GetVin() string

func (*TeslaApi) GuiSetting

func (t *TeslaApi) GuiSetting() (gs *GuiSettings, err error)

func (*TeslaApi) HasSoftwareUpdate added in v0.2.0

func (t *TeslaApi) HasSoftwareUpdate() (version string, result bool)

func (*TeslaApi) HonkHorn

func (t *TeslaApi) HonkHorn() (cmdRes *CommandsRes, err error)

HonkHorn Honks the horn twice.

func (*TeslaApi) IsCharging

func (t *TeslaApi) IsCharging() bool

func (*TeslaApi) IsFastCharging added in v0.1.1

func (t *TeslaApi) IsFastCharging() bool

func (*TeslaApi) IsSoftwareInstalling added in v0.2.0

func (t *TeslaApi) IsSoftwareInstalling() (su SoftwareUpdate, yes bool)

func (*TeslaApi) ListVehicleById

func (t *TeslaApi) ListVehicleById(id string) (v Vehicle, err error)

func (*TeslaApi) ListVehicles

func (t *TeslaApi) ListVehicles() (vs []Vehicle, err error)

func (*TeslaApi) Login

func (t *TeslaApi) Login() (err error)

Login Log in with username & password will require browser pop up, for No GUI environment use refresh token

func (*TeslaApi) MediaNextFav

func (t *TeslaApi) MediaNextFav() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MediaNextTrack

func (t *TeslaApi) MediaNextTrack() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MediaPrevFav

func (t *TeslaApi) MediaPrevFav() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MediaPrevTrack

func (t *TeslaApi) MediaPrevTrack() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MediaToggle

func (t *TeslaApi) MediaToggle() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MediaVolDown

func (t *TeslaApi) MediaVolDown() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MediaVolUp

func (t *TeslaApi) MediaVolUp() (cmdRes *CommandsRes, err error)

func (*TeslaApi) MobileEnable

func (t *TeslaApi) MobileEnable() (isEnabled bool, err error)

func (*TeslaApi) NearByChargingSites

func (t *TeslaApi) NearByChargingSites() (cs []ChargeSite, err error)

NearByChargingSites return list of superchargers and destination chargers

func (*TeslaApi) RefreshToken

func (t *TeslaApi) RefreshToken() string

RefreshToken Return stored refresh token

func (*TeslaApi) ReleaseNotes added in v0.3.0

func (t *TeslaApi) ReleaseNotes(staged bool) (noteRes *CommonRes, err error)

func (*TeslaApi) RemoteBoomBox added in v0.3.0

func (t *TeslaApi) RemoteBoomBox() (cmdRes *CommandsRes, err error)

RemoteBoomBox Let the car fart remotely on version 2022.44.25.1 and above.

func (*TeslaApi) RemoteStartDrive

func (t *TeslaApi) RemoteStartDrive() (cmdRes *CommandsRes, err error)

func (*TeslaApi) ResetValetPin

func (t *TeslaApi) ResetValetPin() (cmdRes *CommandsRes, err error)

func (*TeslaApi) ScheduleSoftwareUpdate added in v0.2.0

func (t *TeslaApi) ScheduleSoftwareUpdate(offsetSec int) (cmdRes *CommandsRes, err error)

func (*TeslaApi) SetActiveVehicle

func (t *TeslaApi) SetActiveVehicle(vehicle Vehicle) (err error)

func (*TeslaApi) SetActiveVehicleByName added in v0.3.0

func (t *TeslaApi) SetActiveVehicleByName(vehicleName string) (err error)

func (*TeslaApi) SetCabinOverheatProtectionTemp added in v0.3.0

func (t *TeslaApi) SetCabinOverheatProtectionTemp(temp int) (cmdRes *CommandsRes, err error)

SetCabinOverheatProtectionTemp set cabin overheat protection temperature in Celsius

func (*TeslaApi) SetChargeAmps

func (t *TeslaApi) SetChargeAmps(amps int) (o *CommandsRes, err error)

func (*TeslaApi) SetChargeLimit

func (t *TeslaApi) SetChargeLimit(percent int) (o *CommandsRes, err error)

func (*TeslaApi) SetClimatePreConditionMax

func (t *TeslaApi) SetClimatePreConditionMax(on bool) (o *CommandsRes, err error)

func (*TeslaApi) SetClimateTemp

func (t *TeslaApi) SetClimateTemp(driverTemp, passengerTemp float64) (o *CommandsRes, err error)

SetClimateTemp temperature in celcius

func (*TeslaApi) SetScheduledCharge

func (t *TeslaApi) SetScheduledCharge(enable bool, time int) (o *CommandsRes, err error)

func (*TeslaApi) SetScheduledDeparture

func (t *TeslaApi) SetScheduledDeparture(enable bool, departureTime, endOffPeakTime int, preconditioningEnabled,
	preconditioningWeekdaysOnly, offPeakChargingEnabled, offPeakChargingWeekdaysOnly bool) (o *CommandsRes, err error)

SetScheduledDeparture departureTime in min end_off_peak_time in min

func (*TeslaApi) SetSeatHeater

func (t *TeslaApi) SetSeatHeater(heater SeatType, level int) (o *CommandsRes, err error)

SetSeatHeater heater 0-5 , heat level 0-3 heater seat 0 Front Left 1 Front right 2 Rear left 4 Rear center 5 Rear right

func (*TeslaApi) SetSentryMode

func (t *TeslaApi) SetSentryMode(on bool) (cmdRes *CommandsRes, err error)

func (*TeslaApi) SetSpeedLimit

func (t *TeslaApi) SetSpeedLimit(limitMph int) (cmdRes *CommandsRes, err error)

SetSpeedLimit speed limit between 50 - 90

func (*TeslaApi) SetSteeringHeater

func (t *TeslaApi) SetSteeringHeater(on bool) (cmdRes *CommandsRes, err error)

func (*TeslaApi) SetTeslaWebRefreshToken added in v0.3.0

func (t *TeslaApi) SetTeslaWebRefreshToken(webRefreshToken string)

SetTeslaWebRefreshToken web refresh token from tesla.com teslaSSORefreshToken cookie

func (*TeslaApi) SetValetMode

func (t *TeslaApi) SetValetMode(on bool, password string) (cmdRes *CommandsRes, err error)

SetValetMode Valet Mode limits the car's top speed to 70MPH and 80kW of acceleration power. It also disables Homelink, Bluetooth and Wifi settings, and the ability to disable mobile access to the car. It also hides your favorites, home, and work locations in navigation.

Note: the password parameter isn't required to turn on or off Valet Mode, even with a previous PIN set. If you clear the PIN and activate Valet Mode without the parameter,

you will only be able to deactivate it from your car's screen by signing into your Tesla account.

func (*TeslaApi) SoftwareUpdate added in v0.2.0

func (t *TeslaApi) SoftwareUpdate() (su SoftwareUpdate, err error)

func (*TeslaApi) SunRoofControl

func (t *TeslaApi) SunRoofControl(winCmd WindowCmd) (cmdRes *CommandsRes, err error)
func (t *TeslaApi) TriggerHomeLink() (cmdRes *CommandsRes, err error)

TriggerHomeLink Trigger homelink with current vehicle

func (*TeslaApi) VehicleConfig

func (t *TeslaApi) VehicleConfig() (vc *VehicleConfig, err error)

func (*TeslaApi) VehicleData

func (t *TeslaApi) VehicleData() (vd *VehicleData, err error)

func (*TeslaApi) VehicleState

func (t *TeslaApi) VehicleState() (vs *VehicleState, err error)

func (*TeslaApi) WaitForWakeUp

func (t *TeslaApi) WaitForWakeUp(timeout int) (err error)

func (*TeslaApi) WakeUp

func (t *TeslaApi) WakeUp() (v *Vehicle, err error)

func (*TeslaApi) WindowControl

func (t *TeslaApi) WindowControl(winCmd WindowCmd, lat, lon float64) (cmdRes *CommandsRes, err error)

type TrunkType

type TrunkType string
const (
	FrontTrunkType TrunkType = "front"
	RearTrunkType  TrunkType = "rear"
)

func (TrunkType) String

func (t TrunkType) String() string

type Vehicle

type Vehicle struct {
	Id                     int64    `json:"id"`
	VehicleId              int      `json:"vehicle_id"`
	Vin                    string   `json:"vin"`
	DisplayName            string   `json:"display_name"`
	OptionCodes            string   `json:"option_codes"`
	Color                  string   `json:"color"`
	AccessType             string   `json:"access_type"`
	Tokens                 []string `json:"tokens"`
	State                  string   `json:"state"`
	InService              bool     `json:"in_service"`
	IdS                    string   `json:"id_s"`
	CalendarEnabled        bool     `json:"calendar_enabled"`
	ApiVersion             int      `json:"api_version"`
	BackseatToken          string   `json:"backseat_token"`
	BackseatTokenUpdatedAt int      `json:"backseat_token_updated_at"`
}

func (Vehicle) GetIdStr

func (v Vehicle) GetIdStr() string

func (Vehicle) GetVehicleIdStr added in v0.3.0

func (v Vehicle) GetVehicleIdStr() string

func (Vehicle) IsInService

func (v Vehicle) IsInService() bool

func (Vehicle) IsInSleep

func (v Vehicle) IsInSleep() bool

type VehicleConfig

type VehicleConfig struct {
	CanAcceptNavigationRequests bool   `json:"can_accept_navigation_requests"`
	CanActuateTrunks            bool   `json:"can_actuate_trunks"`
	CarSpecialType              string `json:"car_special_type"`
	CarType                     string `json:"car_type"`
	ChargePortType              string `json:"charge_port_type"`
	DefaultChargeToMax          bool   `json:"default_charge_to_max"`
	EceRestrictions             bool   `json:"ece_restrictions"`
	EuVehicle                   bool   `json:"eu_vehicle"`
	ExteriorColor               string `json:"exterior_color"`
	HasAirSuspension            bool   `json:"has_air_suspension"`
	HasLudicrousMode            bool   `json:"has_ludicrous_mode"`
	MotorizedChargePort         bool   `json:"motorized_charge_port"`
	Plg                         bool   `json:"plg"`
	RearSeatHeaters             int    `json:"rear_seat_heaters"`
	RearSeatType                int    `json:"rear_seat_type"`
	Rhd                         bool   `json:"rhd"`
	RoofColor                   string `json:"roof_color"`
	SeatType                    int    `json:"seat_type"`
	SpoilerType                 string `json:"spoiler_type"`
	SunRoofInstalled            int    `json:"sun_roof_installed"`
	ThirdRowSeats               string `json:"third_row_seats"`
	Timestamp                   int64  `json:"timestamp"`
	TrimBadging                 string `json:"trim_badging"`
	UseRangeBadging             bool   `json:"use_range_badging"`
	WheelType                   string `json:"wheel_type"`
}

type VehicleData

type VehicleData struct {
	Vehicle
	DriveState    DriveState    `json:"drive_state"`
	ClimateState  ClimateState  `json:"climate_state"`
	ChargeState   ChargeState   `json:"charge_state"`
	GuiSettings   GuiSettings   `json:"gui_settings"`
	VehicleState  VehicleState  `json:"vehicle_state"`
	VehicleConfig VehicleConfig `json:"vehicle_config"`
}

type VehicleDataRes

type VehicleDataRes struct {
	BaseRes
	Response VehicleData `json:"response"`
}

type VehicleRes

type VehicleRes struct {
	BaseRes
	Response interface{} `json:"response,omitempty"`
	Count    int         `json:"count,omitempty"`
}

type VehicleState

type VehicleState struct {
	ApiVersion          int    `json:"api_version"`
	AutoparkStateV2     string `json:"autopark_state_v2"`
	AutoparkStyle       string `json:"autopark_style"`
	CalendarSupported   bool   `json:"calendar_supported"`
	CarVersion          string `json:"car_version"`
	CenterDisplayState  int    `json:"center_display_state"`
	Df                  int    `json:"df"`
	Dr                  int    `json:"dr"`
	FdWindow            int    `json:"fd_window"`
	FpWindow            int    `json:"fp_window"`
	Ft                  int    `json:"ft"`
	HomelinkDeviceCount int    `json:"homelink_device_count"`
	HomelinkNearby      bool   `json:"homelink_nearby"`
	IsUserPresent       bool   `json:"is_user_present"`
	LastAutoparkError   string `json:"last_autopark_error"`
	Locked              bool   `json:"locked"`
	MediaState          struct {
		RemoteControlEnabled bool `json:"remote_control_enabled"`
	} `json:"media_state"`
	MediaInfo               MediaInfo      `json:"media_info"`
	NotificationsSupported  bool           `json:"notifications_supported"`
	Odometer                float64        `json:"odometer"`
	ParsedCalendarSupported bool           `json:"parsed_calendar_supported"`
	Pf                      int            `json:"pf"`
	Pr                      int            `json:"pr"`
	RdWindow                int            `json:"rd_window"`
	RemoteStart             bool           `json:"remote_start"`
	RemoteStartEnabled      bool           `json:"remote_start_enabled"`
	RemoteStartSupported    bool           `json:"remote_start_supported"`
	RpWindow                int            `json:"rp_window"`
	Rt                      int            `json:"rt"`
	SentryMode              bool           `json:"sentry_mode"`
	SentryModeAvailable     bool           `json:"sentry_mode_available"`
	SmartSummonAvailable    bool           `json:"smart_summon_available"`
	SoftwareUpdate          SoftwareUpdate `json:"software_update"`
	SpeedLimitMode          struct {
		Active          bool    `json:"active"`
		CurrentLimitMph float64 `json:"current_limit_mph"`
		MaxLimitMph     float64 `json:"max_limit_mph"`
		MinLimitMph     float64 `json:"min_limit_mph"`
		PinCodeSet      bool    `json:"pin_code_set"`
	} `json:"speed_limit_mode"`
	SummonStandbyModeEnabled   bool        `json:"summon_standby_mode_enabled"`
	SunRoofPercentOpen         int         `json:"sun_roof_percent_open"`
	SunRoofState               string      `json:"sun_roof_state"`
	Timestamp                  int64       `json:"timestamp"`
	ValetMode                  bool        `json:"valet_mode"`
	ValetPinNeeded             bool        `json:"valet_pin_needed"`
	VehicleName                interface{} `json:"vehicle_name"`
	VehicleSelfTestProgress    int         `json:"vehicle_self_test_progress"`
	VehicleSelfTestRequested   bool        `json:"vehicle_self_test_requested"`
	WebcamAvailable            bool        `json:"webcam_available"`
	TpmsHardWarningFl          bool        `json:"tpms_hard_warning_fl"`
	TpmsHardWarningFr          bool        `json:"tpms_hard_warning_fr"`
	TpmsHardWarningRl          bool        `json:"tpms_hard_warning_rl"`
	TpmsHardWarningRr          bool        `json:"tpms_hard_warning_rr"`
	TpmsLastSeenPressureTimeFl int         `json:"tpms_last_seen_pressure_time_fl"`
	TpmsLastSeenPressureTimeFr int         `json:"tpms_last_seen_pressure_time_fr"`
	TpmsLastSeenPressureTimeRl int         `json:"tpms_last_seen_pressure_time_rl"`
	TpmsLastSeenPressureTimeRr int         `json:"tpms_last_seen_pressure_time_rr"`
	TpmsPressureFl             float64     `json:"tpms_pressure_fl"`
	TpmsPressureFr             float64     `json:"tpms_pressure_fr"`
	TpmsPressureRl             float64     `json:"tpms_pressure_rl"`
	TpmsPressureRr             float64     `json:"tpms_pressure_rr"`
	TpmsRcpFrontValue          float64     `json:"tpms_rcp_front_value"`
	TpmsRcpRearValue           float64     `json:"tpms_rcp_rear_value"`
	TpmsSoftWarningFl          bool        `json:"tpms_soft_warning_fl"`
	TpmsSoftWarningFr          bool        `json:"tpms_soft_warning_fr"`
	TpmsSoftWarningRl          bool        `json:"tpms_soft_warning_rl"`
	TpmsSoftWarningRr          bool        `json:"tpms_soft_warning_rr"`
}

type WindowCmd

type WindowCmd string
const (
	WinCloseCmd WindowCmd = "close"
	WinVentCmd  WindowCmd = "vent"
)

func (WindowCmd) String

func (w WindowCmd) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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