Class: TeslaAPI::Vehicle
Overview
Defines a Model S vehicle returned from the API
Instance Attribute Summary collapse
-
#option_codes ⇒ Array
readonly
Option codes defining how the vehicle is configured.
Instance Method Summary collapse
-
#auto_conditioning_start! ⇒ Object
Turns on the temperature conditioning.
-
#auto_conditioning_stop! ⇒ Object
Turns off the temperature conditioning.
-
#charge_max_range! ⇒ Object
Charge the vehicle for maximum range.
-
#charge_standard! ⇒ Object
Charge the vehicle to standard range.
-
#charge_start! ⇒ Object
Starts the vehicle charging.
-
#charge_state ⇒ ChargeState
The vehicle’s charge state.
-
#charge_stop! ⇒ Object
Stops the vehicle charging.
-
#climate_state ⇒ ClimateState
The vehicle’s climate state.
-
#color ⇒ String
Should be car color but is always nil.
-
#display_name ⇒ String
Only observed as nil.
-
#drive_state ⇒ DriveState
The vehicle’s drive state.
-
#flash_lights! ⇒ Object
Flashes the vehicle lights.
-
#gui_settings ⇒ GUISettings
The vehicle’s gui settings.
-
#honk_horn! ⇒ Object
Honks the vehicles horn.
-
#id ⇒ Object
Vehicle ID used in other API calls.
-
#initialize(tesla, data) ⇒ Array
constructor
Option codes defining how the vehicle is configured.
-
#lock_door! ⇒ Object
Locks the vehicle doors.
-
#mobile_access? ⇒ Boolean
true if the vehicle allows mobile access.
-
#online_state ⇒ String
“online” if currently online with API (streaming?).
-
#open_charge_port! ⇒ Object
Opens the charging port.
-
#open_roof!(state) ⇒ Object
Opens the panoramic roof.
-
#option_code_descriptions ⇒ String
The option codes as human readable string.
-
#set_temperature!(driver_degrees_celcius, passenger_degrees_celcius) ⇒ Object
Sets the temperature for both the driver and passenger.
-
#state ⇒ VehicleState
The vehicle’s state.
-
#stream ⇒ Object
The streaming data interface.
-
#tokens ⇒ Array
API tokens (first is used for streaming API).
-
#unlock_door! ⇒ Object
Unlocks the vehicle doors.
-
#user_id ⇒ Integer
Logged in user ID.
-
#vehicle_id ⇒ Integer
Vehicle ID used in streaming API.
-
#vin ⇒ String
Vehicle Identification Number.
-
#wake_up! ⇒ Object
Wakes up the streaming API.
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_codes ⇒ Array (readonly)
Returns 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_state ⇒ ChargeState
Returns the vehicle’s charge state.
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_state ⇒ ClimateState
Returns the vehicle’s climate state.
163 164 165 |
# File 'lib/tesla-api/vehicle.rb', line 163 def climate_state @climate_state || tesla.api_climate_state_for_vehicle(self) end |
#color ⇒ String
Returns Should be car color but is always nil.
|
# File 'lib/tesla-api/vehicle.rb', line 7
|
#display_name ⇒ String
Returns Only observed as nil.
|
# File 'lib/tesla-api/vehicle.rb', line 11
|
#drive_state ⇒ DriveState
Returns the vehicle’s drive state.
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_settings ⇒ GUISettings
Returns the vehicle’s gui settings.
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 |
#id ⇒ Object
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
59 60 61 |
# File 'lib/tesla-api/vehicle.rb', line 59 def mobile_access? tesla.api_mobile_access?(self) end |
#online_state ⇒ String
Returns “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_descriptions ⇒ String
Returns 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 |
#state ⇒ VehicleState
Returns the vehicle’s state.
178 179 180 |
# File 'lib/tesla-api/vehicle.rb', line 178 def state @state ||= tesla.api_get_vehicle_state_for_vehicle(self) end |
#stream ⇒ Object
Returns the streaming data interface.
69 70 71 |
# File 'lib/tesla-api/vehicle.rb', line 69 def stream tesla.stream(self) end |
#tokens ⇒ Array
Returns 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_id ⇒ Integer
Returns Logged in user ID.
|
# File 'lib/tesla-api/vehicle.rb', line 19
|
#vehicle_id ⇒ Integer
Returns Vehicle ID used in streaming API.
|
# File 'lib/tesla-api/vehicle.rb', line 23
|
#vin ⇒ String
Returns 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 |