tesla-api 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/tesla-api/charge_state.rb +31 -31
- data/lib/tesla-api/climate_state.rb +19 -19
- data/lib/tesla-api/data.rb +10 -10
- data/lib/tesla-api/drive_state.rb +10 -9
- data/lib/tesla-api/errors.rb +4 -4
- data/lib/tesla-api/gui_settings.rb +9 -9
- data/lib/tesla-api/private_api.rb +1 -1
- data/lib/tesla-api/vehicle.rb +28 -28
- data/lib/tesla-api/vehicle_state.rb +34 -36
- data/lib/tesla-api/version.rb +2 -2
- metadata +2 -1
@@ -3,66 +3,66 @@ module TeslaAPI
|
|
3
3
|
# Defines the current charge state of the vehicle
|
4
4
|
class ChargeState < Data
|
5
5
|
##
|
6
|
-
#
|
7
|
-
# Charging state ("Complete", "Charging")
|
6
|
+
# @method charging_state
|
7
|
+
# @return Charging state ("Complete", "Charging")
|
8
8
|
|
9
9
|
##
|
10
|
-
#
|
11
|
-
# true if currently performing a range charge
|
10
|
+
# @method charging_to_max?
|
11
|
+
# @return [Boolean] true if currently performing a range charge
|
12
12
|
|
13
13
|
##
|
14
|
-
#
|
15
|
-
# Rated miles for the current charge
|
14
|
+
# @method battery_range_miles
|
15
|
+
# @return [Float] Rated miles for the current charge
|
16
16
|
|
17
17
|
##
|
18
|
-
#
|
19
|
-
# Range estimated from current driving
|
18
|
+
# @method estimated_battry_range_miles
|
19
|
+
# @return [Float] Range estimated from current driving
|
20
20
|
|
21
21
|
##
|
22
|
-
#
|
23
|
-
# Ideal range for the current charge
|
22
|
+
# @method ideal_battery_range_miles
|
23
|
+
# @return [Float] Ideal range for the current charge
|
24
24
|
|
25
25
|
##
|
26
|
-
#
|
27
|
-
# Percentage of battery charge
|
26
|
+
# @method battery_percentage
|
27
|
+
# @return [Integer] Percentage of battery charge
|
28
28
|
|
29
29
|
##
|
30
|
-
#
|
31
|
-
# Current flowing into the battery
|
30
|
+
# @method battery_current_flow
|
31
|
+
# @return [Float] Current flowing into the battery
|
32
32
|
|
33
33
|
##
|
34
|
-
#
|
35
|
-
# Current voltage being used to charge battery
|
34
|
+
# @method charger_voltage
|
35
|
+
# @return [Float] Current voltage being used to charge battery
|
36
36
|
|
37
37
|
##
|
38
|
-
#
|
39
|
-
# Max amperage allowed by the charger
|
38
|
+
# @method charger_pilot_amperage
|
39
|
+
# @return [Integer] Max amperage allowed by the charger
|
40
40
|
|
41
41
|
##
|
42
|
-
#
|
43
|
-
# Current amperage being drawn into battery
|
42
|
+
# @method charger_actual_amperage
|
43
|
+
# @return [Integer] Current amperage being drawn into battery
|
44
44
|
|
45
45
|
##
|
46
|
-
#
|
47
|
-
# Kilowatt of charger (rounded down)
|
46
|
+
# @method charger_power
|
47
|
+
# @return [Integer] Kilowatt of charger (rounded down)
|
48
48
|
|
49
49
|
##
|
50
|
-
#
|
51
|
-
# Hours remaining until the vehicle is fully charged
|
50
|
+
# @method hours_to_full_charge
|
51
|
+
# @return [Float] Hours remaining until the vehicle is fully charged
|
52
52
|
|
53
53
|
##
|
54
|
-
#
|
55
|
-
# Miles of range being added per hour
|
54
|
+
# @method charge_rate_miles_per_hour
|
55
|
+
# @return [Float] Miles of range being added per hour
|
56
56
|
|
57
57
|
##
|
58
|
-
#
|
59
|
-
#
|
58
|
+
# @method charge_port_open?
|
59
|
+
# @return [Boolean] charge port open state
|
60
60
|
|
61
61
|
##
|
62
|
-
#
|
63
|
-
#
|
62
|
+
# @method supercharging?
|
63
|
+
# @return [Boolean] charging via a Tesla SuperCharger
|
64
64
|
|
65
|
-
def initialize(data)
|
65
|
+
def initialize(data)
|
66
66
|
ivar_from_data("charging_state", "charging_state", data)
|
67
67
|
ivar_from_data("charging_to_max", "charge_to_max_range", data)
|
68
68
|
ivar_from_data("battery_range_miles", "battery_range", data)
|
@@ -3,42 +3,42 @@ module TeslaAPI
|
|
3
3
|
#
|
4
4
|
class ClimateState < Data
|
5
5
|
##
|
6
|
-
#
|
7
|
-
# Temperature (celcius) inside the vehicle
|
6
|
+
# @method inside_temp_celcius
|
7
|
+
# @return [Float] Temperature (celcius) inside the vehicle
|
8
8
|
|
9
9
|
##
|
10
|
-
#
|
11
|
-
# Temperature (celcius) outside the vehicle
|
10
|
+
# @method outside_temp_celcius
|
11
|
+
# @return [Float] Temperature (celcius) outside the vehicle
|
12
12
|
|
13
13
|
##
|
14
|
-
#
|
15
|
-
# Temperature (celcius) the driver has set
|
14
|
+
# @method driver_temp_setting_celcius
|
15
|
+
# @return [Float] Temperature (celcius) the driver has set
|
16
16
|
|
17
17
|
##
|
18
|
-
#
|
19
|
-
# Temperature (celcius) the passenger has set
|
18
|
+
# @method passenger_temp_setting_celcius
|
19
|
+
# @return [Float] Temperature (celcius) the passenger has set
|
20
20
|
|
21
21
|
##
|
22
|
-
#
|
23
|
-
# 0 to 6 (or nil)
|
22
|
+
# @method fan_speed
|
23
|
+
# @return [Integer] 0 to 6 (or nil)
|
24
24
|
|
25
25
|
##
|
26
|
-
#
|
27
|
-
#
|
26
|
+
# @method auto_conditioning_on?
|
27
|
+
# @return [Boolean] if auto air conditioning is on
|
28
28
|
|
29
29
|
##
|
30
|
-
#
|
31
|
-
#
|
30
|
+
# @method front_defroster_on?
|
31
|
+
# @return [Boolean] if the front defroster is on
|
32
32
|
|
33
33
|
##
|
34
|
-
#
|
35
|
-
#
|
34
|
+
# @method rear_defroster_on?
|
35
|
+
# @return [Boolean] if the rear defroster is on
|
36
36
|
|
37
37
|
##
|
38
|
-
#
|
39
|
-
#
|
38
|
+
# @method fan_on?
|
39
|
+
# @return [Boolean] if the fan is on
|
40
40
|
|
41
|
-
def initialize(data)
|
41
|
+
def initialize(data)
|
42
42
|
ivar_from_data("inside_temp_celcius", "inside_temp", data)
|
43
43
|
ivar_from_data("outside_temp_celcius", "outside_temp", data)
|
44
44
|
ivar_from_data("driver_temp_setting_celcius", "driver_temp_setting", data)
|
data/lib/tesla-api/data.rb
CHANGED
@@ -2,27 +2,27 @@ module TeslaAPI
|
|
2
2
|
# Base class for all data responses from the HTTP API
|
3
3
|
#
|
4
4
|
# Defines an instance_variable? method for each instance_variable defined allowing for
|
5
|
-
# methods such as
|
5
|
+
# methods such as #charge_port_open?
|
6
6
|
#
|
7
7
|
# Also overrides #inspect to elimiante the back reference to the connection object
|
8
8
|
class Data
|
9
|
-
def method_missing(method_name, *args, &block)
|
9
|
+
def method_missing(method_name, *args, &block)
|
10
10
|
if has_query_ivar_method?(method_name)
|
11
11
|
instance_variable_get(ivar_for_method_name(method_name))
|
12
12
|
else
|
13
|
-
super
|
13
|
+
super
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def respond_to_missing?(method_name, include_private = false)
|
17
|
+
def respond_to_missing?(method_name, include_private = false)
|
18
18
|
has_query_ivar_method?(method_name) || super
|
19
19
|
end
|
20
20
|
|
21
|
-
def inspect
|
21
|
+
def inspect
|
22
22
|
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{inspect_ivars}>"
|
23
23
|
end
|
24
24
|
|
25
|
-
def ivar_from_data(name, data_key, data)
|
25
|
+
def ivar_from_data(name, data_key, data)
|
26
26
|
instance_variable_set("@#{name}".to_sym, data[data_key])
|
27
27
|
|
28
28
|
self.class.send(:attr_reader, name.to_sym)
|
@@ -30,21 +30,21 @@ module TeslaAPI
|
|
30
30
|
|
31
31
|
protected
|
32
32
|
|
33
|
-
def ivar_for_method_name(method_name)
|
33
|
+
def ivar_for_method_name(method_name)
|
34
34
|
"@#{method_name.to_s.gsub(/\?$/,"")}".to_sym
|
35
35
|
end
|
36
36
|
|
37
|
-
def has_query_ivar_method?(method_name)
|
37
|
+
def has_query_ivar_method?(method_name)
|
38
38
|
method = method_name.to_s
|
39
39
|
|
40
40
|
method =~ /(.+)\?/ && instance_variables.include?(ivar_for_method_name(method_name))
|
41
41
|
end
|
42
42
|
|
43
|
-
def inspect_ivars
|
43
|
+
def inspect_ivars
|
44
44
|
ivars_for_inspect.map { |ivar| "#{ivar}=#{instance_variable_get(ivar)}" }.join(" ")
|
45
45
|
end
|
46
46
|
|
47
|
-
def ivars_for_inspect
|
47
|
+
def ivars_for_inspect
|
48
48
|
(instance_variables - [:@tesla])
|
49
49
|
end
|
50
50
|
end
|
@@ -5,26 +5,27 @@ module TeslaAPI
|
|
5
5
|
attr_reader :gps_timestamp
|
6
6
|
|
7
7
|
##
|
8
|
-
#
|
8
|
+
# @method shift_state
|
9
9
|
# Unknown
|
10
10
|
|
11
11
|
##
|
12
|
-
#
|
12
|
+
# @method speed
|
13
13
|
# Vehicle speed (units?)
|
14
14
|
|
15
15
|
##
|
16
|
-
#
|
17
|
-
# Lattitude of vehicle
|
16
|
+
# @method latitude
|
17
|
+
# @return [Float] Lattitude of vehicle
|
18
18
|
|
19
19
|
##
|
20
|
-
#
|
21
|
-
# Longitude of vehicle
|
20
|
+
# @method longitude
|
21
|
+
# @return [Float] Longitude of vehicle
|
22
22
|
|
23
23
|
##
|
24
|
-
#
|
25
|
-
# Compass heading (0 to 360) degrees
|
24
|
+
# @method heading
|
25
|
+
# @return [Integer] Compass heading (0 to 360) degrees
|
26
26
|
|
27
|
-
|
27
|
+
# initialize
|
28
|
+
def initialize(data)
|
28
29
|
ivar_from_data("shift_state", "shift_state", data)
|
29
30
|
ivar_from_data("speed", "speed", data)
|
30
31
|
ivar_from_data("latitude", "latitude", data)
|
data/lib/tesla-api/errors.rb
CHANGED
@@ -6,11 +6,11 @@ module TeslaAPI
|
|
6
6
|
# JSON parsing error details
|
7
7
|
attr_reader :error
|
8
8
|
|
9
|
-
def initialize(error)
|
9
|
+
def initialize(error)
|
10
10
|
@error = error
|
11
11
|
end
|
12
12
|
|
13
|
-
def to_s
|
13
|
+
def to_s
|
14
14
|
error.to_s
|
15
15
|
end
|
16
16
|
end
|
@@ -28,11 +28,11 @@ module TeslaAPI
|
|
28
28
|
# Response object from httpclient
|
29
29
|
attr_reader :response
|
30
30
|
|
31
|
-
def initialize(response)
|
31
|
+
def initialize(response)
|
32
32
|
@response = response
|
33
33
|
end
|
34
34
|
|
35
|
-
def to_s
|
35
|
+
def to_s
|
36
36
|
"Invalid Response: #{response.inspect}"
|
37
37
|
end
|
38
38
|
end
|
@@ -2,27 +2,27 @@ module TeslaAPI
|
|
2
2
|
# Defines the current user settings for the vehicle's graphical display
|
3
3
|
class GUISettings < Data
|
4
4
|
##
|
5
|
-
#
|
6
|
-
# Units ("mi/hr") for showing range
|
5
|
+
# @method gui_distance_units
|
6
|
+
# @return [String] Units ("mi/hr") for showing range
|
7
7
|
|
8
8
|
##
|
9
|
-
#
|
10
|
-
# Units ("F", "C") for showing temperaturs
|
9
|
+
# @method gui_temperature_units
|
10
|
+
# @return [String] Units ("F", "C") for showing temperaturs
|
11
11
|
|
12
12
|
##
|
13
|
-
#
|
14
|
-
# Units ("kW") for showing charge rage
|
13
|
+
# @method gui_charge_rate_units
|
14
|
+
# @return [String} Units ("kW") for showing charge rage
|
15
15
|
|
16
16
|
##
|
17
|
-
#
|
18
|
-
# Units ("Rated", "Ideal") for showing range
|
17
|
+
# @method gui_range_display
|
18
|
+
# @return [String] Units ("Rated", "Ideal") for showing range
|
19
19
|
|
20
20
|
# true if the UI show 24 hour time (e.g. 17:45)
|
21
21
|
def gui_24_hour_time?
|
22
22
|
@gui_24_hour_time
|
23
23
|
end
|
24
24
|
|
25
|
-
def initialize(data)
|
25
|
+
def initialize(data)
|
26
26
|
ivar_from_data("gui_distance_units", "gui_distance_units", data)
|
27
27
|
ivar_from_data("gui_temperature_units", "gui_temperature_units", data)
|
28
28
|
ivar_from_data("gui_charge_rate_units", "gui_charge_rate_units", data)
|
data/lib/tesla-api/vehicle.rb
CHANGED
@@ -5,42 +5,42 @@ module TeslaAPI
|
|
5
5
|
attr_reader :option_codes
|
6
6
|
|
7
7
|
##
|
8
|
-
#
|
9
|
-
# Should be car color but is always nil
|
8
|
+
# @method color
|
9
|
+
# @return [String] Should be car color but is always nil
|
10
10
|
|
11
11
|
##
|
12
|
-
#
|
13
|
-
# Only observed as nil
|
12
|
+
# @method display_name
|
13
|
+
# @return [String] Only observed as nil
|
14
14
|
|
15
15
|
##
|
16
|
-
#
|
17
|
-
# Vehicle ID used in other API calls
|
16
|
+
# @method id
|
17
|
+
# @return Vehicle ID used in other API calls
|
18
18
|
|
19
19
|
##
|
20
|
-
#
|
21
|
-
# Logged in user ID
|
20
|
+
# @method user_id
|
21
|
+
# @return [Integer] Logged in user ID
|
22
22
|
|
23
23
|
##
|
24
|
-
#
|
25
|
-
# Vehicle ID used in streaming API
|
24
|
+
# @method vehicle_id
|
25
|
+
# @return [Integer] Vehicle ID used in streaming API
|
26
26
|
|
27
27
|
##
|
28
|
-
#
|
29
|
-
# Vehicle Identification Number
|
28
|
+
# @method vin
|
29
|
+
# @return [String] Vehicle Identification Number
|
30
30
|
|
31
31
|
##
|
32
|
-
#
|
33
|
-
# API tokens (first is used for streaming API)
|
32
|
+
# @method tokens
|
33
|
+
# @return [Array] API tokens (first is used for streaming API)
|
34
34
|
|
35
35
|
##
|
36
|
-
#
|
37
|
-
# "online" if currently online with API (streaming?)
|
36
|
+
# @method online_state
|
37
|
+
# @return [String] "online" if currently online with API (streaming?)
|
38
38
|
|
39
39
|
##
|
40
|
-
#
|
41
|
-
# Array
|
40
|
+
# @method option_codes
|
41
|
+
# @return [Array] option codes defining how the vehicle is configured
|
42
42
|
|
43
|
-
def initialize(tesla, data)
|
43
|
+
def initialize(tesla, data)
|
44
44
|
@tesla = tesla
|
45
45
|
|
46
46
|
ivar_from_data("color", "color", data)
|
@@ -60,12 +60,12 @@ module TeslaAPI
|
|
60
60
|
tesla.api_mobile_access?(self)
|
61
61
|
end
|
62
62
|
|
63
|
-
#
|
63
|
+
# @return [String] the option codes as human readable string
|
64
64
|
def option_code_descriptions
|
65
65
|
option_codes.map { |code| codes_to_description.fetch(code, code) }.join(", ")
|
66
66
|
end
|
67
67
|
|
68
|
-
#
|
68
|
+
# @return [Object] the streaming data interface
|
69
69
|
def stream
|
70
70
|
tesla.stream(self)
|
71
71
|
end
|
@@ -154,38 +154,38 @@ module TeslaAPI
|
|
154
154
|
#
|
155
155
|
#################################
|
156
156
|
|
157
|
-
#
|
157
|
+
# @return [ChargeState] the vehicle's charge state
|
158
158
|
def charge_state
|
159
159
|
@charge_state ||= tesla.api_charge_state_for_vehicle(self)
|
160
160
|
end
|
161
161
|
|
162
|
-
#
|
162
|
+
# @return [ClimateState] the vehicle's climate state
|
163
163
|
def climate_state
|
164
164
|
@climate_state || tesla.api_climate_state_for_vehicle(self)
|
165
165
|
end
|
166
166
|
|
167
|
-
#
|
167
|
+
# @return [DriveState] the vehicle's drive state
|
168
168
|
def drive_state
|
169
169
|
@drive_state ||= tesla.api_drive_state_for_vehicle(self)
|
170
170
|
end
|
171
171
|
|
172
|
-
#
|
172
|
+
# @return [GUISettings] the vehicle's gui settings
|
173
173
|
def gui_settings
|
174
174
|
@gui_settings ||= tesla.api_gui_settings_for_vehicle(self)
|
175
175
|
end
|
176
176
|
|
177
|
-
#
|
177
|
+
# @return [VehicleState] the vehicle's state
|
178
178
|
def state
|
179
179
|
@state ||= tesla.api_get_vehicle_state_for_vehicle(self)
|
180
180
|
end
|
181
181
|
|
182
182
|
private
|
183
183
|
|
184
|
-
def tesla
|
184
|
+
def tesla
|
185
185
|
@tesla
|
186
186
|
end
|
187
187
|
|
188
|
-
def codes_to_description
|
188
|
+
def codes_to_description
|
189
189
|
{
|
190
190
|
"MS01" => "base",
|
191
191
|
"RENA" => "region_us",
|
@@ -2,73 +2,71 @@ module TeslaAPI
|
|
2
2
|
# Defines the current vehicle state
|
3
3
|
class VehicleState < Data
|
4
4
|
##
|
5
|
-
#
|
6
|
-
# Current firmware version
|
5
|
+
# @method firmware_version
|
6
|
+
# @return [String] Current firmware version
|
7
7
|
|
8
8
|
##
|
9
|
-
#
|
10
|
-
#
|
9
|
+
# @method sun_roof_installed?
|
10
|
+
# @return [Boolean] if the vehicle is configured with the panoramic sun roof
|
11
11
|
|
12
12
|
##
|
13
|
-
#
|
14
|
-
# Current state of the sun roof
|
15
|
-
# Potential values:
|
16
|
-
# unknown
|
17
|
-
# moving
|
13
|
+
# @method sun_roof_state
|
14
|
+
# @return [String] Current state of the sun roof
|
15
|
+
# Potential values: unknown, moving
|
18
16
|
|
19
17
|
##
|
20
|
-
#
|
21
|
-
# Percentage the sun roof is open
|
18
|
+
# @method sun_roof_percent_open
|
19
|
+
# @return [Integer] Percentage the sun roof is open
|
22
20
|
|
23
21
|
##
|
24
|
-
#
|
25
|
-
#
|
22
|
+
# @method driver_front_door_open?
|
23
|
+
# @return [Boolean] if the driver's side front door is open
|
26
24
|
|
27
25
|
##
|
28
|
-
#
|
29
|
-
#
|
26
|
+
# @method driver_rear_door_open?
|
27
|
+
# @return [Boolean] if the driver's side rear door is open
|
30
28
|
|
31
29
|
##
|
32
|
-
#
|
33
|
-
#
|
30
|
+
# @method passenger_front_door_open?
|
31
|
+
# @return [Boolean] if the passenger's side front door is open
|
34
32
|
|
35
33
|
##
|
36
|
-
#
|
37
|
-
#
|
34
|
+
# @method passenger_rear_door_open
|
35
|
+
# @return [Boolean] if the passenger's side rear door is open
|
38
36
|
|
39
37
|
##
|
40
|
-
#
|
41
|
-
#
|
38
|
+
# @method front_trunk_open?
|
39
|
+
# @return [Boolean] if the front trunk (frunk) is open
|
42
40
|
|
43
41
|
##
|
44
|
-
#
|
45
|
-
#
|
42
|
+
# method rear_trunk_open?
|
43
|
+
# @return [Boolean] if the rear trunk is open
|
46
44
|
|
47
45
|
##
|
48
|
-
#
|
49
|
-
#
|
46
|
+
# @method locked?
|
47
|
+
# @return [Boolean] if the doors are locked
|
50
48
|
|
51
49
|
##
|
52
|
-
#
|
53
|
-
#
|
50
|
+
# @method dark_rims?
|
51
|
+
# @return [Boolean] if configured with dark colored rims
|
54
52
|
|
55
53
|
##
|
56
|
-
#
|
57
|
-
#
|
54
|
+
# @method spoiler?
|
55
|
+
# @return [Boolean] if configured with a spoiler
|
58
56
|
|
59
57
|
##
|
60
|
-
#
|
61
|
-
#
|
58
|
+
# @method nineteen_inch_wheels?
|
59
|
+
# @return [Boolean] if configured with nineteen inch wheels
|
62
60
|
|
63
61
|
##
|
64
|
-
#
|
65
|
-
#
|
62
|
+
# @method panoramic?
|
63
|
+
# @return [Boolean] configured with a panoramic roof
|
66
64
|
|
67
65
|
##
|
68
|
-
#
|
69
|
-
#
|
66
|
+
# @method perf?
|
67
|
+
# @return [Boolean] if a performance configured vehicle
|
70
68
|
|
71
|
-
def initialize(data)
|
69
|
+
def initialize(data)
|
72
70
|
ivar_from_data("firmware_version", "car_version", data)
|
73
71
|
ivar_from_data("sun_roof_installed", "sun_roof_installed", data)
|
74
72
|
ivar_from_data("sun_roof_state", "sun_roof_state", data)
|
data/lib/tesla-api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tesla-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -133,3 +133,4 @@ test_files:
|
|
133
133
|
- test/test_gui_settings.rb
|
134
134
|
- test/test_vehicle.rb
|
135
135
|
- test/test_vehicle_state.rb
|
136
|
+
has_rdoc:
|