Class: TeslaApi::Vehicle

Inherits:
Object
  • Object
show all
Includes:
Autopark, Stream
Defined in:
lib/tesla_api/vehicle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Autopark

#start_autopark

Methods included from Stream

#stream, streaming_endpoint, streaming_endpoint_url

Constructor Details

#initialize(client, email, id, vehicle) ⇒ Vehicle

Returns a new instance of Vehicle.



7
8
9
10
11
12
# File 'lib/tesla_api/vehicle.rb', line 7

def initialize(client, email, id, vehicle)
  @client = client
  @email = email
  @id = id
  @vehicle = vehicle
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/tesla_api/vehicle.rb', line 20

def method_missing(name)
  if vehicle.keys.include?(name.to_s)
    vehicle[name.to_s]
  else
    raise NoMethodError.new("Vehicle does not have property `#{name}`", name)
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



5
6
7
# File 'lib/tesla_api/vehicle.rb', line 5

def api
  @api
end

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/tesla_api/vehicle.rb', line 5

def client
  @client
end

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/tesla_api/vehicle.rb', line 5

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/tesla_api/vehicle.rb', line 5

def id
  @id
end

#vehicleObject (readonly)

Returns the value of attribute vehicle.



5
6
7
# File 'lib/tesla_api/vehicle.rb', line 5

def vehicle
  @vehicle
end

Instance Method Details

#[](key) ⇒ Object

Properties



16
17
18
# File 'lib/tesla_api/vehicle.rb', line 16

def [](key)
  vehicle[key]
end

#activate_speed_limit(pin) ⇒ Object



168
169
170
# File 'lib/tesla_api/vehicle.rb', line 168

def activate_speed_limit(pin)
  command('speed_limit_activate', body: {pin: pin})['response']
end

#auto_conditioning_startObject



136
137
138
# File 'lib/tesla_api/vehicle.rb', line 136

def auto_conditioning_start
  command('auto_conditioning_start')['response']
end

#auto_conditioning_stopObject



140
141
142
# File 'lib/tesla_api/vehicle.rb', line 140

def auto_conditioning_stop
  command('auto_conditioning_stop')['response']
end

#cancel_software_updateObject



201
202
203
# File 'lib/tesla_api/vehicle.rb', line 201

def cancel_software_update
  command('cancel_software_update')['response']
end

#charge_max_rangeObject



96
97
98
# File 'lib/tesla_api/vehicle.rb', line 96

def charge_max_range
  command('charge_max_range')['response']
end

#charge_port_door_closeObject



88
89
90
# File 'lib/tesla_api/vehicle.rb', line 88

def charge_port_door_close
  command('charge_port_door_close')['response']
end

#charge_port_door_openObject



84
85
86
# File 'lib/tesla_api/vehicle.rb', line 84

def charge_port_door_open
  command('charge_port_door_open')['response']
end

#charge_standardObject



92
93
94
# File 'lib/tesla_api/vehicle.rb', line 92

def charge_standard
  command('charge_standard')['response']
end

#charge_startObject



104
105
106
# File 'lib/tesla_api/vehicle.rb', line 104

def charge_start
  command('charge_start')['response']
end

#charge_stateObject



50
51
52
# File 'lib/tesla_api/vehicle.rb', line 50

def charge_state
  data_request('charge_state')['response']
end

#charge_stopObject



108
109
110
# File 'lib/tesla_api/vehicle.rb', line 108

def charge_stop
  command('charge_stop')['response']
end

#clear_speed_limit_pin(pin) ⇒ Object



180
181
182
# File 'lib/tesla_api/vehicle.rb', line 180

def clear_speed_limit_pin(pin)
  command('speed_limit_clear_pin', body: {pin: pin})['response']
end

#climate_stateObject



54
55
56
# File 'lib/tesla_api/vehicle.rb', line 54

def climate_state
  data_request('climate_state')['response']
end

#dataObject



34
35
36
# File 'lib/tesla_api/vehicle.rb', line 34

def data
  client.get("/vehicles/#{id}/data")['response']
end

#deactivate_speed_limit(pin) ⇒ Object



172
173
174
# File 'lib/tesla_api/vehicle.rb', line 172

def deactivate_speed_limit(pin)
  command('speed_limit_deactivate', body: {pin: pin})['response']
end

#door_lockObject



124
125
126
# File 'lib/tesla_api/vehicle.rb', line 124

def door_lock
  command('door_lock')['response']
end

#door_unlockObject



120
121
122
# File 'lib/tesla_api/vehicle.rb', line 120

def door_unlock
  command('door_unlock')['response']
end

#drive_stateObject



58
59
60
# File 'lib/tesla_api/vehicle.rb', line 58

def drive_state
  data_request('drive_state')['response']
end

#flash_lightsObject



112
113
114
# File 'lib/tesla_api/vehicle.rb', line 112

def flash_lights
  command('flash_lights')['response']
end

#gui_settingsObject



46
47
48
# File 'lib/tesla_api/vehicle.rb', line 46

def gui_settings
  data_request('gui_settings')['response']
end

#honk_hornObject



116
117
118
# File 'lib/tesla_api/vehicle.rb', line 116

def honk_horn
  command('honk_horn')['response']
end

#media_next_favObject



233
234
235
# File 'lib/tesla_api/vehicle.rb', line 233

def media_next_fav
  command('media_next_fav')['response']
end

#media_next_trackObject



225
226
227
# File 'lib/tesla_api/vehicle.rb', line 225

def media_next_track
  command('media_next_track')['response']
end

#media_prev_favObject



237
238
239
# File 'lib/tesla_api/vehicle.rb', line 237

def media_prev_fav
  command('media_prev_fav')['response']
end

#media_prev_trackObject



229
230
231
# File 'lib/tesla_api/vehicle.rb', line 229

def media_prev_track
  command('media_prev_track')['response']
end

#media_toggle_playbackObject



221
222
223
# File 'lib/tesla_api/vehicle.rb', line 221

def media_toggle_playback
  command('media_toggle_playback')['response']
end

#media_volume_downObject



245
246
247
# File 'lib/tesla_api/vehicle.rb', line 245

def media_volume_down
  command('media_volume_down')['response']
end

#media_volume_upObject



241
242
243
# File 'lib/tesla_api/vehicle.rb', line 241

def media_volume_up
  command('media_volume_up')['response']
end

#mobile_enabledObject



38
39
40
# File 'lib/tesla_api/vehicle.rb', line 38

def mobile_enabled
  client.get("/vehicles/#{id}/mobile_enabled")['response']
end


184
185
186
187
188
189
190
191
# File 'lib/tesla_api/vehicle.rb', line 184

def navigation_request(address)
  command('navigation_request', body: {
      type: 'share_ext_content_raw',
      locale: 'en-US',
      timestamp_ms: Time.now.to_i,
      value: {'android.intent.extra.TEXT' => address}
  })['response']
end

#nearby_charging_sitesObject



42
43
44
# File 'lib/tesla_api/vehicle.rb', line 42

def nearby_charging_sites
  client.get("/vehicles/#{id}/nearby_charging_sites")['response']
end

#open_frunkObject



164
165
166
# File 'lib/tesla_api/vehicle.rb', line 164

def open_frunk
  command('actuate_trunk', body: {which_trunk: 'front'})['response']
end

#open_trunkObject



160
161
162
# File 'lib/tesla_api/vehicle.rb', line 160

def open_trunk
  command('actuate_trunk', body: {which_trunk: 'rear'})['response']
end

#remote_start_drive(password) ⇒ Object



156
157
158
# File 'lib/tesla_api/vehicle.rb', line 156

def remote_start_drive(password)
  command('remote_start_drive', body: {password: password})['response']
end

#reset_valet_pinObject



80
81
82
# File 'lib/tesla_api/vehicle.rb', line 80

def reset_valet_pin
  command('reset_valet_pin')['response']
end

#schedule_software_update(offset_sec = 0) ⇒ Object



197
198
199
# File 'lib/tesla_api/vehicle.rb', line 197

def schedule_software_update(offset_sec = 0)
  command('schedule_software_update', body: {offset_sec: offset_sec})['response']
end

#set_charge_limit(percent) ⇒ Object



100
101
102
# File 'lib/tesla_api/vehicle.rb', line 100

def set_charge_limit(percent)
  command('set_charge_limit', body: {percent: percent.to_i})['response']
end

#set_preconditioning_max(on) ⇒ Object



132
133
134
# File 'lib/tesla_api/vehicle.rb', line 132

def set_preconditioning_max(on)
  command('set_preconditioning_max', body: {on: on})['response']
end

#set_seat_heater(heater, level) ⇒ Object



205
206
207
# File 'lib/tesla_api/vehicle.rb', line 205

def set_seat_heater(heater, level)
  command('remote_seat_heater_request', body: {heater: heater, level: level})['response']
end

#set_sentry_mode(on) ⇒ Object



213
214
215
# File 'lib/tesla_api/vehicle.rb', line 213

def set_sentry_mode(on)
  command('set_sentry_mode', body: {on: on})['response']
end

#set_speed_limit(limit_mph) ⇒ Object



176
177
178
# File 'lib/tesla_api/vehicle.rb', line 176

def set_speed_limit(limit_mph)
  command('speed_limit_set_limit', body: {limit_mph: limit_mph})['response']
end

#set_steering_wheel_heater(on) ⇒ Object



209
210
211
# File 'lib/tesla_api/vehicle.rb', line 209

def set_steering_wheel_heater(on)
  command('remote_steering_wheel_heater_request', body: {on: on})['response']
end

#set_temps(driver_temp, passenger_temp) ⇒ Object



128
129
130
# File 'lib/tesla_api/vehicle.rb', line 128

def set_temps(driver_temp, passenger_temp)
  command('set_temps', body: {driver_temp: driver_temp, passenger_temp: passenger_temp})['response']
end

#set_valet_mode(on, password = nil) ⇒ Object



76
77
78
# File 'lib/tesla_api/vehicle.rb', line 76

def set_valet_mode(on, password=nil)
  command('set_valet_mode', body: {on: on, password: password})['response']
end

#share(text) ⇒ Object



193
194
195
# File 'lib/tesla_api/vehicle.rb', line 193

def share(text)
  navigation_request(text)
end

#sun_roof_control(state) ⇒ Object



144
145
146
# File 'lib/tesla_api/vehicle.rb', line 144

def sun_roof_control(state)
  command('sun_roof_control', body: {state: state})['response']
end

#sun_roof_move(percent) ⇒ Object



148
149
150
# File 'lib/tesla_api/vehicle.rb', line 148

def sun_roof_move(percent)
  command('sun_roof_control', body: {state: 'move', percent: percent})['response']
end


217
218
219
# File 'lib/tesla_api/vehicle.rb', line 217

def trigger_homelink(lat, lon)
  command('trigger_homelink', body: {lat: lat, lon: lon})['response']
end

#vehicle_configObject



66
67
68
# File 'lib/tesla_api/vehicle.rb', line 66

def vehicle_config
  data_request('vehicle_config')['response']
end

#vehicle_dataObject

State



30
31
32
# File 'lib/tesla_api/vehicle.rb', line 30

def vehicle_data
  client.get("/vehicles/#{id}/vehicle_data")['response']
end

#vehicle_stateObject



62
63
64
# File 'lib/tesla_api/vehicle.rb', line 62

def vehicle_state
  data_request('vehicle_state')['response']
end

#wake_upObject

Commands



72
73
74
# File 'lib/tesla_api/vehicle.rb', line 72

def wake_up
  @vehicle = client.post("/vehicles/#{id}/wake_up")['response']
end

#window_control(command) ⇒ Object



152
153
154
# File 'lib/tesla_api/vehicle.rb', line 152

def window_control(command)
  command('window_control', body: {command: command, lat: 0, lon: 0})['response']
end