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, id, vehicle) ⇒ Vehicle

Returns a new instance of Vehicle.



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

def initialize(api, id, vehicle)
  @api = api
  @id = id
  @vehicle = vehicle
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



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

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

#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



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

def [](key)
  vehicle[key]
end

#activate_speed_limit(pin) ⇒ Object



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

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

#auto_conditioning_startObject



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

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

#auto_conditioning_stopObject



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

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

#charge_max_rangeObject



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

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

#charge_port_door_openObject



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

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

#charge_standardObject



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

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

#charge_startObject



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

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

#charge_stateObject



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

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

#charge_stopObject



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

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

#clear_speed_limit_pin(pin) ⇒ Object



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

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

#climate_stateObject



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

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

#dataObject

State



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

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

#deactivate_speed_limit(pin) ⇒ Object



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

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

#door_lockObject



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

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

#door_unlockObject



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

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

#drive_stateObject



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

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

#flash_lightsObject



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

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

#gui_settingsObject



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

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

#honk_hornObject



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

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

#mobile_enabledObject



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

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

#open_frunkObject



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

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

#open_trunkObject



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

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

#remote_start_drive(password) ⇒ Object



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

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

#reset_valet_pinObject



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

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

#set_charge_limit(percent) ⇒ Object



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

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

#set_speed_limit(limit_mph) ⇒ Object



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

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

#set_temps(driver_temp, passenger_temp) ⇒ Object



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

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



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

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

#sun_roof_control(state) ⇒ Object



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

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

#sun_roof_move(percent) ⇒ Object



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

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

#vehicle_stateObject



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

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

#wake_upObject

Commands



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

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