Class: TeslaAPI::Connection

Inherits:
Object
  • Object
show all
Includes:
PrivateAPI
Defined in:
lib/tesla-api/connection.rb

Overview

Connection object to the Tesla Model S HTTP API endpoint.

Constant Summary collapse

HOST =

Host for status/command related API

"https://portal.vn.teslamotors.com"
STREAMING_HOST =

Host for streaming API

"https://streaming.vn.teslamotors.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PrivateAPI

#api_charge_state_for_vehicle, #api_climate_state_for_vehicle, #api_drive_state_for_vehicle, #api_get_vehicle_state_for_vehicle, #api_gui_settings_for_vehicle, #api_mobile_access?, #auto_conditioning_start!, #auto_conditioning_stop!, #charge_max_range!, #charge_standard!, #charge_start!, #charge_stop!, #flash_lights!, #honk_horn!, #lock_door!, #login, #open_charge_port!, #open_roof!, #set_temperature!, #stream, #unlock_door!, #wake_up!

Constructor Details

#initialize(email, password) ⇒ Connection

Supply the email and password for login to teslamotors.com



19
20
21
22
23
24
25
26
27
# File 'lib/tesla-api/connection.rb', line 19

def initialize(email, password)
  @email    = email
  @password = password

  @client = HTTPClient.new
  @client.set_cookie_store("cookie.dat")

  (email, password)
end

Instance Attribute Details

#emailObject (readonly)

email address of logged in user



7
8
9
# File 'lib/tesla-api/connection.rb', line 7

def email
  @email
end

#passwordObject (readonly)

password of logged in user



10
11
12
# File 'lib/tesla-api/connection.rb', line 10

def password
  @password
end

Instance Method Details

#debug!Object

Call to see all HTTP traffic to and from the API



30
31
32
# File 'lib/tesla-api/connection.rb', line 30

def debug!
  @client.debug_dev = STDOUT
end

#logged_in?Boolean

Logged into the API

Returns:

  • (Boolean)


53
54
55
# File 'lib/tesla-api/connection.rb', line 53

def logged_in?
  @logged_in
end

#reload!Object

Force the vehicles to reload (in case some of the data has changed)



48
49
50
# File 'lib/tesla-api/connection.rb', line 48

def reload!
  @vehicles = nil
end

#vehicleObject

Convenience method to return the first Vehicle



35
36
37
# File 'lib/tesla-api/connection.rb', line 35

def vehicle
  vehicles.first
end

#vehiclesObject

Returns Vehicle objects for all vehicles the account contains



40
41
42
43
44
45
# File 'lib/tesla-api/connection.rb', line 40

def vehicles
  @vehicles ||= begin
    _, json = get_json("/vehicles")
    json.map { |data| Vehicle.new(self, data) }
  end
end