Skip to content

Commit e037e97

Browse files
committed
Updates documentation
1 parent d0e99ad commit e037e97

15 files changed

+355
-51
lines changed

README.md renamed to README.rdoc

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# TeslaAPI
1+
= TeslaAPI
2+
3+
== DESCRIPTION
24

35
Allows access to the Tesla REST API for reading car telemetry and controlling basic
46
vehicle features such as locking doors, opening the roof and controlling the AC system.
57

68
Implements the API documented here: https://github.com/timdorr/model-s-api
79

8-
## Installation
10+
== Installation
911

1012
Add this line to your application's Gemfile:
1113

@@ -19,7 +21,7 @@ Or install it yourself as:
1921

2022
$ gem install tesla-api
2123

22-
## Usage
24+
== Usage
2325

2426
tesla = TeslaAPI::Connection.new("[email protected]", "password")
2527

@@ -29,7 +31,7 @@ Or install it yourself as:
2931

3032
puts mycar.drive_state.speed # => 65
3133

32-
## Contributing
34+
== Contributing
3335

3436
1. Fork it
3537
2. Create your feature branch (`git checkout -b my-new-feature`)

lib/tesla-api.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'json'
22
require 'httpclient'
33

4+
require "tesla-api/tesla_api"
45
require "tesla-api/version"
56
require "tesla-api/private_api"
67
require "tesla-api/connection"

lib/tesla-api/charge_state.rb

+63-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,68 @@
11
module TeslaAPI
2+
3+
# Defines the current charge state of the vehicle
24
class ChargeState < Data
3-
def initialize(data)
5+
##
6+
# :method: charging_state
7+
# Charging state ("Complete", "Charging")
8+
9+
##
10+
# :method charging_to_max?
11+
# true if currently performing a range charge
12+
13+
##
14+
# :method: battery_range_miles
15+
# Rated miles for the current charge
16+
17+
##
18+
# :method: estimated_battry_range_miles
19+
# Range estimated from current driving
20+
21+
##
22+
# :method: ideal_battery_range_miles
23+
# Ideal range for the current charge
24+
25+
##
26+
# :method: battery_percentage
27+
# Percentage of battery charge
28+
29+
##
30+
# :method: battery_current_flow
31+
# Current flowing into the battery
32+
33+
##
34+
# :method: charger_voltage
35+
# Current voltage being used to charge battery
36+
37+
##
38+
# :method: charger_pilot_amperage
39+
# Max amperage allowed by the charger
40+
41+
##
42+
# :method: charger_actual_amperage
43+
# Current amperage being drawn into battery
44+
45+
##
46+
# :method: charger_power
47+
# Kilowatt of charger (rounded down)
48+
49+
##
50+
# :method: hours_to_full_charge
51+
# Hours remaining until the vehicle is fully charged
52+
53+
##
54+
# :method: charge_rate_miles_per_hour
55+
# Miles of range being added per hour
56+
57+
##
58+
# :method: charge_port_open?
59+
# true if the charge port is open
60+
61+
##
62+
# :method: supercharging?
63+
# true if charging via a Tesla SuperCharger
64+
65+
def initialize(data) # :nodoc:
466
ivar_from_data("charging_state", "charging_state", data)
567
ivar_from_data("charging_to_max", "charge_to_max_range", data)
668
ivar_from_data("battery_range_miles", "battery_range", data)

lib/tesla-api/climate_state.rb

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
module TeslaAPI
2+
# Defines the climate state of the vehicle.
3+
#
24
class ClimateState < Data
3-
def initialize(data)
5+
##
6+
# :method: inside_temp_celcius
7+
# Temperature (celcius) inside the vehicle
8+
9+
##
10+
# :method: outside_temp_celcius
11+
# Temperature (celcius) outside the vehicle
12+
13+
##
14+
# :method: driver_temp_setting_celcius
15+
# Temperature (celcius) the driver has set
16+
17+
##
18+
# :method: passenger_temp_setting_celcius
19+
# Temperature (celcius) the passenger has set
20+
21+
##
22+
# :method: fan_speed
23+
# 0 to 6 (or nil)
24+
25+
##
26+
# :method: auto_conditioning_on?
27+
# true if auto air conditioning is on
28+
29+
##
30+
# :method: front_defroster_on?
31+
# true if the front defroster is on
32+
33+
##
34+
# :method: rear_defroster_on?
35+
# true if the rear defroster is on
36+
37+
##
38+
# :method: fan_on?
39+
# true if the fan is on
40+
41+
def initialize(data) # :nodoc:
442
ivar_from_data("inside_temp_celcius", "inside_temp", data)
543
ivar_from_data("outside_temp_celcius", "outside_temp", data)
644
ivar_from_data("driver_temp_setting_celcius", "driver_temp_setting", data)

lib/tesla-api/connection.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
module TeslaAPI
2+
# Connection object to the Tesla Model S HTTP API endpoint.
23
class Connection
34
include PrivateAPI
45

5-
attr_reader :email, :password
6+
# email address of logged in user
7+
attr_reader :email
68

7-
HOST = "https://portal.vn.teslamotors.com"
9+
# password of logged in user
10+
attr_reader :password
11+
12+
# Host for status/command related API
13+
HOST = "https://portal.vn.teslamotors.com"
14+
15+
# Host for streaming API
816
STREAMING_HOST = "https://streaming.vn.teslamotors.com"
917

18+
# Supply the email and password for login to teslamotors.com
1019
def initialize(email, password)
1120
@email = email
1221
@password = password
@@ -17,25 +26,30 @@ def initialize(email, password)
1726
login(email, password)
1827
end
1928

29+
# Call to see all HTTP traffic to and from the API
2030
def debug!
2131
@client.debug_dev = STDOUT
2232
end
2333

34+
# Convenience method to return the first Vehicle
2435
def vehicle
2536
vehicles.first
2637
end
2738

39+
# Returns Vehicle objects for all vehicles the account contains
2840
def vehicles
2941
@vehicles ||= begin
3042
_, json = get_json("/vehicles")
3143
json.map { |data| Vehicle.new(self, data) }
3244
end
3345
end
3446

47+
# Force the vehicles to reload (in case some of the data has changed)
3548
def reload!
3649
@vehicles = nil
3750
end
3851

52+
# Logged into the API
3953
def logged_in?
4054
@logged_in
4155
end

lib/tesla-api/data.rb

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
module TeslaAPI
2+
# Base class for all data responses from the HTTP API
3+
#
4+
# Defines an instance_variable? method for each instance_variable defined allowing for
5+
# methods such as __________?
6+
#
7+
# Also overrides #inspect to elimiante the back reference to the connection object
28
class Data
3-
def method_missing(method_name, *args, &block)
9+
def method_missing(method_name, *args, &block) # :nodoc:
410
if has_query_ivar_method?(method_name)
511
instance_variable_get(instance_var)
612
else
713
super(symbol, *args, &block)
814
end
915
end
1016

11-
def respond_to_missing?(method_name, include_private = false)
17+
def respond_to_missing?(method_name, include_private = false) # :nodoc:
1218
has_query_ivar_method?(method_name) || super
1319
end
1420

15-
def inspect
21+
def inspect # :nodoc:
1622
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{inspect_ivars}>"
1723
end
1824

19-
def ivar_from_data(name, data_key, data)
25+
def ivar_from_data(name, data_key, data) # :nodoc:
2026
instance_variable_set("@#{name}".to_sym, data[data_key])
2127

2228
self.class.send(:attr_reader, name.to_sym)
2329
end
2430

2531
protected
2632

27-
def has_query_ivar_method?(method_name)
33+
def has_query_ivar_method?(method_name) # :nodoc:
2834
method = method_name.to_s
2935
instance_var = "@#{method.gsub(/\?$/,"")}".to_sym
3036

3137
method =~ /(.+)\?/ && instance_variables.include?(instance_var)
3238
end
3339

34-
def inspect_ivars
40+
def inspect_ivars # :nodoc:
3541
ivars_for_inspect.map { |ivar| "#{ivar}=#{instance_variable_get(ivar)}" }.join(" ")
3642
end
3743

38-
def ivars_for_inspect
44+
def ivars_for_inspect # :nodoc:
3945
(instance_variables - [:@tesla])
4046
end
4147
end

lib/tesla-api/drive_state.rb

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
module TeslaAPI
2+
# Data defining the driving state of the the vehicle
23
class DriveState < Data
4+
# Time when GPS data was recorded
35
attr_reader :gps_timestamp
46

5-
def initialize(data)
7+
##
8+
# :method: shift_state
9+
# Unknown
10+
11+
##
12+
# :method: speed
13+
# Vehicle speed (units?)
14+
15+
##
16+
# :method: latitude
17+
# Lattitude of vehicle
18+
19+
##
20+
# :method: longitude
21+
# Longitude of vehicle
22+
23+
##
24+
# :method: heading
25+
# Compass heading (0 to 360) degrees
26+
27+
def initialize(data) # :nodoc:
628
ivar_from_data("shift_state", "shift_state", data)
729
ivar_from_data("speed", "speed", data)
830
ivar_from_data("latitude", "latitude", data)

lib/tesla-api/errors.rb

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
module TeslaAPI
2-
class InvalidJSON < StandardError
3-
attr_reader :error
4-
5-
def initialize(error)
6-
@error = error
2+
# Exceptions thrown by the TeslaAPI
3+
module Errors
4+
# JSON cannot be parsed
5+
class InvalidJSON < StandardError
6+
# JSON parsing error details
7+
attr_reader :error
8+
9+
def initialize(error) # :nodoc:
10+
@error = error
11+
end
12+
13+
def to_s # :nodoc:
14+
error.to_s
15+
end
716
end
817

9-
def to_s
10-
error.to_s
18+
# Thrown when the action requires a logged in connection
19+
class NotLoggedIn < StandardError
1120
end
12-
end
13-
14-
class NotLoggedIn < StandardError
15-
end
1621

17-
class APIFailure < StandardError
18-
end
22+
# Thrown when the API returns a failure state
23+
class APIFailure < StandardError
24+
end
1925

20-
class InvalidResponse < StandardError
21-
attr_reader :response
26+
# Thrown when the response is invalid (non 200-OK HTTP result)
27+
class InvalidResponse < StandardError
28+
# Response object from httpclient
29+
attr_reader :response
2230

23-
def initialize(response)
24-
@response = response
25-
end
31+
def initialize(response) # :nodoc:
32+
@response = response
33+
end
2634

27-
def to_s
28-
"Invalid Response: #{response.inspect}"
35+
def to_s # :nodoc:
36+
"Invalid Response: #{response.inspect}"
37+
end
2938
end
3039
end
3140
end

lib/tesla-api/gui_settings.rb

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
module TeslaAPI
2+
# Defines the current user settings for the vehicle's graphical display
23
class GUISettings < Data
4+
##
5+
# :method: gui_distance_units
6+
# Units ("mi", "hr") for showing range
7+
8+
##
9+
# :method: gui_temperature_units
10+
# Units ("F", "C") for showing temperaturs
11+
12+
##
13+
# :method: gui_charge_rate_units
14+
# Units ("mi", "hr") for showing charge rage
15+
16+
##
17+
# :method: gui_range_display
18+
# Units ("Rated", "Ideal") for showing range
19+
20+
# true if the UI show 24 hour time (e.g. 17:45)
321
def gui_24_hour_time?
422
@gui_24_hour_time
523
end
624

7-
def initialize(data)
25+
def initialize(data) # :nodoc:
826
ivar_from_data("gui_distance_units", "gui_distance_units", data)
927
ivar_from_data("gui_temperature_units", "gui_temperature_units", data)
1028
ivar_from_data("gui_charge_rate_units", "gui_charge_rate_units", data)

0 commit comments

Comments
 (0)