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

Constructor Details

#initialize(api, 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(api, email, id, vehicle)
  @api = api
  @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

#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



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

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

#auto_conditioning_startObject



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

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

#auto_conditioning_stopObject



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

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

#cancel_software_updateObject



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

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

#charge_max_rangeObject



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

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

#charge_port_door_closeObject



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

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

#charge_port_door_openObject



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

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

#charge_standardObject



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

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

#charge_startObject



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

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

#charge_stateObject



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

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

#charge_stopObject



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

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

#clear_speed_limit_pin(pin) ⇒ Object



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

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

#climate_stateObject



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

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

#dataObject

State



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

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

#deactivate_speed_limit(pin) ⇒ Object



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

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

#door_lockObject



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

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

#door_unlockObject



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

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

#drive_stateObject



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

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

#flash_lightsObject



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

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

#gui_settingsObject



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

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

#honk_hornObject



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

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

#mobile_enabledObject



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

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


168
169
170
171
172
173
174
175
# File 'lib/tesla_api/vehicle.rb', line 168

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



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

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

#open_frunkObject



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

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

#open_trunkObject



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

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

#remote_start_drive(password) ⇒ Object



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

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

#reset_valet_pinObject



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

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

#schedule_software_update(offset_sec = 0) ⇒ Object



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

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

#set_charge_limit(percent) ⇒ Object



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

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

#set_seat_heater(heater, level) ⇒ Object



185
186
187
# File 'lib/tesla_api/vehicle.rb', line 185

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

#set_sentry_mode(on) ⇒ Object



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

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

#set_speed_limit(limit_mph) ⇒ Object



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

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

#set_steering_wheel_heater(on) ⇒ Object



189
190
191
# File 'lib/tesla_api/vehicle.rb', line 189

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

#set_temps(driver_temp, passenger_temp) ⇒ Object



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

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



68
69
70
# File 'lib/tesla_api/vehicle.rb', line 68

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

#sun_roof_control(state) ⇒ Object



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

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

#sun_roof_move(percent) ⇒ Object



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

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

#vehicle_stateObject



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

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

#wake_upObject

Commands



64
65
66
# File 'lib/tesla_api/vehicle.rb', line 64

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