Class: TeslaAPI::Vehicle

Inherits:
Data
  • Object
show all
Defined in:
lib/tesla-api/vehicle.rb

Overview

Defines a Model S vehicle returned from the API

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#inspect, #ivar_from_data, #method_missing, #respond_to_missing?

Constructor Details

#initialize(tesla, data) ⇒ Array

Returns option codes defining how the vehicle is configured.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tesla-api/vehicle.rb', line 43

def initialize(tesla, data)
  @tesla = tesla

  ivar_from_data("color",        "color",        data)
  ivar_from_data("display_name", "display_name", data)
  ivar_from_data("id",           "id",           data)
  ivar_from_data("user_id",      "user_id",      data)
  ivar_from_data("vehicle_id",   "vehicle_id",   data)
  ivar_from_data("vin",          "vin",          data)
  ivar_from_data("tokens",       "tokens",       data)
  ivar_from_data("online_state", "state",        data)

  @option_codes = data["option_codes"].split(",")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class TeslaAPI::Data

Instance Attribute Details

#option_codesArray (readonly)

Returns option codes defining how the vehicle is configured.

Returns:

  • (Array)

    option codes defining how the vehicle is configured



5
6
7
# File 'lib/tesla-api/vehicle.rb', line 5

def option_codes
  @option_codes
end

Instance Method Details

#auto_conditioning_start!Object

Turns on the temperature conditioning



90
91
92
# File 'lib/tesla-api/vehicle.rb', line 90

def auto_conditioning_start!
  tesla.auto_conditioning_start!(self)
end

#auto_conditioning_stop!Object

Turns off the temperature conditioning



95
96
97
# File 'lib/tesla-api/vehicle.rb', line 95

def auto_conditioning_stop!
  tesla.auto_conditioning_stop!(self)
end

#charge_max_range!Object

Charge the vehicle for maximum range



142
143
144
# File 'lib/tesla-api/vehicle.rb', line 142

def charge_max_range!
  tesla.charge_max_range!(self)
end

#charge_standard!Object

Charge the vehicle to standard range



147
148
149
# File 'lib/tesla-api/vehicle.rb', line 147

def charge_standard!
  tesla.charge_standard!(self)
end

#charge_start!Object

Starts the vehicle charging



137
138
139
# File 'lib/tesla-api/vehicle.rb', line 137

def charge_start!
  tesla.charge_start!(self)
end

#charge_stateChargeState

Returns the vehicle’s charge state.

Returns:



158
159
160
# File 'lib/tesla-api/vehicle.rb', line 158

def charge_state
  @charge_state ||= tesla.api_charge_state_for_vehicle(self)
end

#charge_stop!Object

Stops the vehicle charging



132
133
134
# File 'lib/tesla-api/vehicle.rb', line 132

def charge_stop!
  tesla.charge_stop!(self)
end

#climate_stateClimateState

Returns the vehicle’s climate state.

Returns:



163
164
165
# File 'lib/tesla-api/vehicle.rb', line 163

def climate_state
  @climate_state || tesla.api_climate_state_for_vehicle(self)
end

#colorString

Returns Should be car color but is always nil.

Returns:

  • (String)

    Should be car color but is always nil



# File 'lib/tesla-api/vehicle.rb', line 7

#display_nameString

Returns Only observed as nil.

Returns:

  • (String)

    Only observed as nil



# File 'lib/tesla-api/vehicle.rb', line 11

#drive_stateDriveState

Returns the vehicle’s drive state.

Returns:



168
169
170
# File 'lib/tesla-api/vehicle.rb', line 168

def drive_state
  @drive_state ||= tesla.api_drive_state_for_vehicle(self)
end

#flash_lights!Object

Flashes the vehicle lights



127
128
129
# File 'lib/tesla-api/vehicle.rb', line 127

def flash_lights!
  tesla.flash_lights!(self)
end

#gui_settingsGUISettings

Returns the vehicle’s gui settings.

Returns:



173
174
175
# File 'lib/tesla-api/vehicle.rb', line 173

def gui_settings
  @gui_settings ||= tesla.api_gui_settings_for_vehicle(self)
end

#honk_horn!Object

Honks the vehicles horn



122
123
124
# File 'lib/tesla-api/vehicle.rb', line 122

def honk_horn!
  tesla.honk_horn!(self)
end

#idObject

Returns Vehicle ID used in other API calls.

Returns:

  • Vehicle ID used in other API calls



# File 'lib/tesla-api/vehicle.rb', line 15

#lock_door!Object

Locks the vehicle doors



112
113
114
# File 'lib/tesla-api/vehicle.rb', line 112

def lock_door!
  tesla.lock_door!(self)
end

#mobile_access?Boolean

true if the vehicle allows mobile access

Returns:

  • (Boolean)


59
60
61
# File 'lib/tesla-api/vehicle.rb', line 59

def mobile_access?
  tesla.api_mobile_access?(self)
end

#online_stateString

Returns “online” if currently online with API (streaming?).

Returns:

  • (String)

    “online” if currently online with API (streaming?)



# File 'lib/tesla-api/vehicle.rb', line 35

#open_charge_port!Object

Opens the charging port



85
86
87
# File 'lib/tesla-api/vehicle.rb', line 85

def open_charge_port!
  tesla.open_charge_port!(self)
end

#open_roof!(state) ⇒ Object

Opens the panoramic roof

state may be “open”, “close”, “comfort”, or “vent”



107
108
109
# File 'lib/tesla-api/vehicle.rb', line 107

def open_roof!(state)
  tesla.open_roof!(self, state)
end

#option_code_descriptionsString

Returns the option codes as human readable string.

Returns:

  • (String)

    the option codes as human readable string



64
65
66
# File 'lib/tesla-api/vehicle.rb', line 64

def option_code_descriptions
  option_codes.map { |code| codes_to_description.fetch(code, code) }.join(", ")
end

#set_temperature!(driver_degrees_celcius, passenger_degrees_celcius) ⇒ Object

Sets the temperature for both the driver and passenger



100
101
102
# File 'lib/tesla-api/vehicle.rb', line 100

def set_temperature!(driver_degrees_celcius, passenger_degrees_celcius)
  tesla.set_temperature!(self, driver_degrees_celcius, passenger_degrees_celcius)
end

#stateVehicleState

Returns the vehicle’s state.

Returns:



178
179
180
# File 'lib/tesla-api/vehicle.rb', line 178

def state
  @state ||= tesla.api_get_vehicle_state_for_vehicle(self)
end

#streamObject

Returns the streaming data interface.

Returns:

  • (Object)

    the streaming data interface



69
70
71
# File 'lib/tesla-api/vehicle.rb', line 69

def stream
  tesla.stream(self)
end

#tokensArray

Returns API tokens (first is used for streaming API).

Returns:

  • (Array)

    API tokens (first is used for streaming API)



# File 'lib/tesla-api/vehicle.rb', line 31

#unlock_door!Object

Unlocks the vehicle doors



117
118
119
# File 'lib/tesla-api/vehicle.rb', line 117

def unlock_door!
  tesla.unlock_door!(self)
end

#user_idInteger

Returns Logged in user ID.

Returns:

  • (Integer)

    Logged in user ID



# File 'lib/tesla-api/vehicle.rb', line 19

#vehicle_idInteger

Returns Vehicle ID used in streaming API.

Returns:

  • (Integer)

    Vehicle ID used in streaming API



# File 'lib/tesla-api/vehicle.rb', line 23

#vinString

Returns Vehicle Identification Number.

Returns:

  • (String)

    Vehicle Identification Number



# File 'lib/tesla-api/vehicle.rb', line 27

#wake_up!Object

Wakes up the streaming API



80
81
82
# File 'lib/tesla-api/vehicle.rb', line 80

def wake_up!
  tesla.wake_up!(self)
end