diff --git a/lib/tesla_api/client.rb b/lib/tesla_api/client.rb index c2b5486e..9818b9a2 100644 --- a/lib/tesla_api/client.rb +++ b/lib/tesla_api/client.rb @@ -1,13 +1,13 @@ module TeslaApi class Client include HTTParty - base_uri "https://owner-api.teslamotors.com/api/1" - headers "User-Agent" => "github.com/timdorr/tesla-api v:#{VERSION}" + base_uri 'https://owner-api.teslamotors.com/api/1' + headers 'User-Agent' => "github.com/timdorr/tesla-api v:#{VERSION}" format :json attr_reader :email, :token, :client_id, :client_secret - def initialize(email, client_id = ENV["TESLA_CLIENT_ID"], client_secret = ENV["TESLA_CLIENT_SECRET"]) + def initialize(email, client_id = ENV['TESLA_CLIENT_ID'], client_secret = ENV['TESLA_CLIENT_SECRET']) @email = email @client_id = client_id @client_secret = client_secret @@ -15,7 +15,7 @@ def initialize(email, client_id = ENV["TESLA_CLIENT_ID"], client_secret = ENV["T def token=(token) @token = token - self.class.headers "Authorization" => "Bearer #{token}" + self.class.headers 'Authorization' => "Bearer #{token}" end def expires_in=(seconds) @@ -38,23 +38,23 @@ def expired? def login!(password) response = self.class.post( - "https://owner-api.teslamotors.com/oauth/token", + 'https://owner-api.teslamotors.com/oauth/token', body: { - "grant_type" => "password", - "client_id" => client_id, - "client_secret" => client_secret, - "email" => email, - "password" => password + grant_type: 'password', + client_id: client_id, + client_secret: client_secret, + email: email, + password: password } ) - self.expires_in = response["expires_in"] - self.created_at = response["created_at"] - self.token = response["access_token"] + self.expires_in = response['expires_in'] + self.created_at = response['created_at'] + self.token = response['access_token'] end def vehicles - self.class.get("/vehicles")["response"].map { |v| Vehicle.new(self.class, v["id"], v) } + self.class.get('/vehicles')['response'].map { |v| Vehicle.new(self.class, v['id'], v) } end end end diff --git a/lib/tesla_api/stream.rb b/lib/tesla_api/stream.rb index 3c35c4a5..b77007da 100644 --- a/lib/tesla_api/stream.rb +++ b/lib/tesla_api/stream.rb @@ -6,7 +6,7 @@ def stream(&reciever) attributes = chunk.split(",") reciever.call({ - time: DateTime.strptime((attributes[0].to_i/1000).to_s, "%s"), + time: DateTime.strptime((attributes[0].to_i/1000).to_s, '%s'), speed: attributes[1].to_f, odometer: attributes[2].to_f, soc: attributes[3].to_f, @@ -31,23 +31,23 @@ def stream(&reciever) def request @request ||= EventMachine::HttpRequest.new( - "#{stream_endpoint}/stream/#{self["vehicle_id"]}/?values=#{stream_params}") + "#{stream_endpoint}/stream/#{self['vehicle_id']}/?values=#{stream_params}") end def http request.get( head: { - "authorization" => [email, self["tokens"].first] + 'authorization' => [email, self['tokens'].first] }, inactivity_timeout: 15) end def stream_endpoint - "https://streaming.vn.teslamotors.com" + 'https://streaming.vn.teslamotors.com' end def stream_params - "speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading" + 'speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading' end end end diff --git a/lib/tesla_api/vehicle.rb b/lib/tesla_api/vehicle.rb index 929d46fc..a3d6cf12 100644 --- a/lib/tesla_api/vehicle.rb +++ b/lib/tesla_api/vehicle.rb @@ -27,133 +27,133 @@ def method_missing(name) # State def data - api.get("/vehicles/#{id}/data")["response"] + api.get("/vehicles/#{id}/data")['response'] end def mobile_enabled - api.get("/vehicles/#{id}/mobile_enabled")["response"] + api.get("/vehicles/#{id}/mobile_enabled")['response'] end def gui_settings - data_request("gui_settings")["response"] + data_request('gui_settings')['response'] end def charge_state - data_request("charge_state")["response"] + data_request('charge_state')['response'] end def climate_state - data_request("climate_state")["response"] + data_request('climate_state')['response'] end def drive_state - data_request("drive_state")["response"] + data_request('drive_state')['response'] end def vehicle_state - data_request("vehicle_state")["response"] + data_request('vehicle_state')['response'] end # Commands def wake_up - @vehicle = api.post("/vehicles/#{id}/wake_up")["response"] + @vehicle = api.post("/vehicles/#{id}/wake_up")['response'] end def set_valet_mode(on, password=nil) - command("set_valet_mode", body: {on: on, password: password})["response"] + command('set_valet_mode', body: {on: on, password: password})['response'] end def reset_valet_pin - command("reset_valet_pin")["response"] + command('reset_valet_pin')['response'] end def charge_port_door_open - command("charge_port_door_open")["response"] + command('charge_port_door_open')['response'] end def charge_standard - command("charge_standard")["response"] + command('charge_standard')['response'] end def charge_max_range - command("charge_max_range")["response"] + command('charge_max_range')['response'] end def set_charge_limit(percent) - command("set_charge_limit", body: {percent: percent})["response"] + command('set_charge_limit', body: {percent: percent})['response'] end def charge_start - command("charge_start")["response"] + command('charge_start')['response'] end def charge_stop - command("charge_stop")["response"] + command('charge_stop')['response'] end def flash_lights - command("flash_lights")["response"] + command('flash_lights')['response'] end def honk_horn - command("honk_horn")["response"] + command('honk_horn')['response'] end def door_unlock - command("door_unlock")["response"] + command('door_unlock')['response'] end def door_lock - command("door_lock")["response"] + command('door_lock')['response'] end def set_temps(driver_temp, passenger_temp) - command("set_temps", body: {driver_temp: driver_temp, passenger_temp: passenger_temp})["response"] + command('set_temps', body: {driver_temp: driver_temp, passenger_temp: passenger_temp})['response'] end def auto_conditioning_start - command("auto_conditioning_start")["response"] + command('auto_conditioning_start')['response'] end def auto_conditioning_stop - command("auto_conditioning_stop")["response"] + command('auto_conditioning_stop')['response'] end def sun_roof_control(state) - command("sun_roof_control", body: {state: state})["response"] + command('sun_roof_control', body: {state: state})['response'] end def sun_roof_move(percent) - command("sun_roof_control", body: {state: "move", percent: percent})["response"] + command('sun_roof_control', body: {state: 'move', percent: percent})['response'] end def remote_start_drive(password) - command("remote_start_drive", body: {password: password})["response"] + command('remote_start_drive', body: {password: password})['response'] end def open_trunk - command("actuate_trunk", body: {which_trunk: "rear"})["response"] + command('actuate_trunk', body: {which_trunk: 'rear'})['response'] end def open_frunk - command("actuate_trunk", body: {which_trunk: "front"})["response"] + command('actuate_trunk', body: {which_trunk: 'front'})['response'] end def activate_speed_limit(pin) - command("speed_limit_activate", body: {pin: pin})["response"] + command('speed_limit_activate', body: {pin: pin})['response'] end def deactivate_speed_limit(pin) - command("speed_limit_deactivate", body: {pin: pin})["response"] + command('speed_limit_deactivate', body: {pin: pin})['response'] end def set_speed_limit(limit_mph) - command("speed_limit_set_limit", body: {limit_mph: limit_mph})["response"] + command('speed_limit_set_limit', body: {limit_mph: limit_mph})['response'] end def clear_speed_limit_pin(pin) - command("speed_limit_clear_pin", body: {pin: pin})["response"] + command('speed_limit_clear_pin', body: {pin: pin})['response'] end private diff --git a/spec/lib/tesla_api/client_spec.rb b/spec/lib/tesla_api/client_spec.rb index e1ed7aac..8c977ee3 100644 --- a/spec/lib/tesla_api/client_spec.rb +++ b/spec/lib/tesla_api/client_spec.rb @@ -1,63 +1,63 @@ require 'spec_helper' RSpec.describe TeslaApi::Client do - subject(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"]) } + subject(:tesla_api) { TeslaApi::Client.new(ENV['TESLA_EMAIL']) } - describe "#new client" do - it "has no expiry date" do + describe '#new client' do + it 'has no expiry date' do expect(tesla_api.expired_at).to eq(nil) end - it "has a expiry status set to true" do + it 'has a expiry status set to true' do expect(tesla_api.expired?).to eq(true) end end - describe "#token=" do - it "sets a Bearer token" do + describe '#token=' do + it 'sets a Bearer token' do tesla_api.token = Faker::Lorem.characters(32) - expect(tesla_api.class.headers).to include({"Authorization" => /Bearer [a-z0-9]{32}/}) + expect(tesla_api.class.headers).to include({'Authorization' => /Bearer [a-z0-9]{32}/}) end end - describe "#login!", vcr: { cassette_name: "client-login" } do + describe '#login!', vcr: { cassette_name: 'client-login' } do it { is_expected.to be_a(TeslaApi::Client) } - it "logs into the API" do - tesla_api.login!(ENV["TESLA_PASS"]) + it 'logs into the API' do + tesla_api.login!(ENV['TESLA_PASS']) expect(a_request(:post, "https://#{URI.parse(tesla_api.class.base_uri).host}/oauth/token")).to have_been_made.once end - it "set a expiry date" do - tesla_api.login!(ENV["TESLA_PASS"]) + it 'set a expiry date' do + tesla_api.login!(ENV['TESLA_PASS']) expect(tesla_api.expired_at).to eq(Time.at(1475777133 + 7776000).to_datetime) end - it "expose expiry status" do - tesla_api.login!(ENV["TESLA_PASS"]) + it 'expose expiry status' do + tesla_api.login!(ENV['TESLA_PASS']) tesla_api.created_at = (Time.now - 1).to_i expect(tesla_api.expired?).to eq(false) end - it "is expired when has a 90+ days old date" do - tesla_api.login!(ENV["TESLA_PASS"]) + it 'is expired when has a 90+ days old date' do + tesla_api.login!(ENV['TESLA_PASS']) tesla_api.created_at = (Time.now - 7776000 - 1).to_i expect(tesla_api.expired?).to eq(true) end - it "sets a Bearer token header" do - tesla_api.login!(ENV["TESLA_PASS"]) - expect(tesla_api.class.headers).to include({"Authorization" => /Bearer [a-z0-9]{32}/}) + it 'sets a Bearer token header' do + tesla_api.login!(ENV['TESLA_PASS']) + expect(tesla_api.class.headers).to include({'Authorization' => /Bearer [a-z0-9]{32}/}) end - it "obtains a Bearer token" do - tesla_api.login!(ENV["TESLA_PASS"]) + it 'obtains a Bearer token' do + tesla_api.login!(ENV['TESLA_PASS']) expect(tesla_api.token).to match(/[a-z0-9]{32}/) end end - describe "#vehicles", vcr: {cassette_name: "client-vehicles"} do - it "lists the vehicles on the account" do + describe '#vehicles', vcr: {cassette_name: 'client-vehicles'} do + it 'lists the vehicles on the account' do expect(tesla_api.vehicles).to include(TeslaApi::Vehicle) end end diff --git a/spec/lib/tesla_api/vehicle_spec.rb b/spec/lib/tesla_api/vehicle_spec.rb index 92176bde..afa8381b 100644 --- a/spec/lib/tesla_api/vehicle_spec.rb +++ b/spec/lib/tesla_api/vehicle_spec.rb @@ -1,295 +1,295 @@ require 'spec_helper' RSpec.describe TeslaApi::Vehicle do - let(:tesla_api) { TeslaApi::Client.new(ENV["TESLA_EMAIL"]) } + let(:tesla_api) { TeslaApi::Client.new(ENV['TESLA_EMAIL']) } before do - tesla_api.token = ENV["TESLA_API_TOKEN"] + tesla_api.token = ENV['TESLA_API_TOKEN'] end subject(:vehicle) { tesla_api.vehicles.first } - describe "#[]", vcr: { cassette_name: "vehicle" } do - it "contains the vehicle name" do - expect(vehicle["display_name"]).to eq("Nikola") + describe '#[]', vcr: { cassette_name: 'vehicle' } do + it 'contains the vehicle name' do + expect(vehicle['display_name']).to eq('Nikola') end end - describe "#method_missing", vcr: {cassette_name: "vehicle"} do - it "doesn't provide dynamic methods for nonexistent properties" do + describe '#method_missing', vcr: {cassette_name: 'vehicle'} do + it 'doesn\'t provide dynamic methods for nonexistent properties' do expect{vehicle.gas_level}.to raise_exception(NoMethodError) end - it "provides a dynamic method for the display_name" do - expect(vehicle.display_name).to eq("Nikola") + it 'provides a dynamic method for the display_name' do + expect(vehicle.display_name).to eq('Nikola') end end - describe "#mobile_enabled", vcr: {cassette_name: "vehicle-mobile_enabled"} do - it "indicates if mobile app access is enabled" do + describe '#mobile_enabled', vcr: {cassette_name: 'vehicle-mobile_enabled'} do + it 'indicates if mobile app access is enabled' do expect(vehicle.mobile_enabled).to eq(true) end end - describe "#gui_settings", vcr: {cassette_name: "vehicle-gui_settings"} do - context "details for a GUI built on the API" do + describe '#gui_settings', vcr: {cassette_name: 'vehicle-gui_settings'} do + context 'details for a GUI built on the API' do subject { vehicle.gui_settings } - it { should include("gui_charge_rate_units") } - it { should include("gui_distance_units") } - it { should include("gui_temperature_units") } - it { should include("gui_range_display") } - it { should include("gui_24_hour_time") } + it { should include('gui_charge_rate_units') } + it { should include('gui_distance_units') } + it { should include('gui_temperature_units') } + it { should include('gui_range_display') } + it { should include('gui_24_hour_time') } end end - describe "#charge_state", vcr: {cassette_name: "vehicle-charge_state"} do - context "data about the vehicle's charging state" do + describe '#charge_state', vcr: {cassette_name: 'vehicle-charge_state'} do + context 'data about the vehicle\'s charging state' do subject { vehicle.charge_state } - it { should include("battery_level") } - it { should include("charge_rate") } - it { should include("charging_state") } - it { should include("est_battery_range") } - it { should include("fast_charger_present") } + it { should include('battery_level') } + it { should include('charge_rate') } + it { should include('charging_state') } + it { should include('est_battery_range') } + it { should include('fast_charger_present') } end end - describe "#climate_state", vcr: {cassette_name: "vehicle-climate_state"} do - context "data about the vehicle's climate controls and internal climate" do + describe '#climate_state', vcr: {cassette_name: 'vehicle-climate_state'} do + context 'data about the vehicle\'s climate controls and internal climate' do subject { vehicle.climate_state } - it { should include("inside_temp") } - it { should include("outside_temp") } - it { should include("driver_temp_setting") } - it { should include("passenger_temp_setting") } - it { should include("is_auto_conditioning_on") } + it { should include('inside_temp') } + it { should include('outside_temp') } + it { should include('driver_temp_setting') } + it { should include('passenger_temp_setting') } + it { should include('is_auto_conditioning_on') } end end - describe "#drive_state", vcr: {cassette_name: "vehicle-drive_state"} do - context "data about the vehicle's driving state" do + describe '#drive_state', vcr: {cassette_name: 'vehicle-drive_state'} do + context 'data about the vehicle\'s driving state' do subject { vehicle.drive_state } - it { should include("heading") } - it { should include("latitude") } - it { should include("longitude") } - it { should include("speed") } + it { should include('heading') } + it { should include('latitude') } + it { should include('longitude') } + it { should include('speed') } end end - describe "#vehicle_state", vcr: {cassette_name: "vehicle-vehicle_state"} do - context "data about the vehicle's overall state" do + describe '#vehicle_state', vcr: {cassette_name: 'vehicle-vehicle_state'} do + context 'data about the vehicle\'s overall state' do subject { vehicle.vehicle_state } - it { should include("vehicle_name") } - it { should include("exterior_color") } - it { should include("wheel_type") } - it { should include("has_spoiler") } - it { should include("calendar_supported") } - it { should include("locked") } + it { should include('vehicle_name') } + it { should include('exterior_color') } + it { should include('wheel_type') } + it { should include('has_spoiler') } + it { should include('calendar_supported') } + it { should include('locked') } end end - describe "#wake_up", vcr: {cassette_name: "vehicle-wake_up"} do - it "wakes up the car from sleep mode" do + describe '#wake_up', vcr: {cassette_name: 'vehicle-wake_up'} do + it 'wakes up the car from sleep mode' do vehicle.wake_up - expect(vehicle.state).to eq("online") + expect(vehicle.state).to eq('online') end end - describe "#set_valet_mode", vcr: {cassette_name: "vehicle-set_valet_mode"} do - it "enables valet mode on the car" do - expect(vehicle.set_valet_mode(true, 1234)["result"]).to eq(true) + describe '#set_valet_mode', vcr: {cassette_name: 'vehicle-set_valet_mode'} do + it 'enables valet mode on the car' do + expect(vehicle.set_valet_mode(true, 1234)['result']).to eq(true) end - it "enables valet mode with a previous PIN" do - expect(vehicle.set_valet_mode(true)["result"]).to eq(true) + it 'enables valet mode with a previous PIN' do + expect(vehicle.set_valet_mode(true)['result']).to eq(true) end end - describe "#reset_valet_pin", vcr: {cassette_name: "vehicle-reset_valet_pin"} do - it "resets the valet mode PIN" do - expect(vehicle.reset_valet_pin["result"]).to eq(true) + describe '#reset_valet_pin', vcr: {cassette_name: 'vehicle-reset_valet_pin'} do + it 'resets the valet mode PIN' do + expect(vehicle.reset_valet_pin['result']).to eq(true) end end - describe "#charge_port_door_open", vcr: {cassette_name: "vehicle-charge_port_door_open"} do - it "opens the charge port door" do - expect(vehicle.charge_port_door_open["result"]).to eq(true) + describe '#charge_port_door_open', vcr: {cassette_name: 'vehicle-charge_port_door_open'} do + it 'opens the charge port door' do + expect(vehicle.charge_port_door_open['result']).to eq(true) end end - describe "#charge_standard" do - it "sets the charge limit to standard (90%)", vcr: {cassette_name: "vehicle-charge_standard"} do - expect(vehicle.charge_standard["result"]).to eq(true) + describe '#charge_standard' do + it 'sets the charge limit to standard (90%)', vcr: {cassette_name: 'vehicle-charge_standard'} do + expect(vehicle.charge_standard['result']).to eq(true) end - it "doesn't set the charge rate to standard twice", vcr: {cassette_name: "vehicle-charge_standard-twice"} do - expect(vehicle.charge_standard["result"]).to eq(true) - expect(vehicle.charge_standard).to eq({"result" => false, "reason" => "already_standard"}) + it 'doesn\'t set the charge rate to standard twice', vcr: {cassette_name: 'vehicle-charge_standard-twice'} do + expect(vehicle.charge_standard['result']).to eq(true) + expect(vehicle.charge_standard).to eq({'result' => false, 'reason' => 'already_standard'}) end end - describe "#charge_max_range" do - it "sets the charge limit to max range (100%)", vcr: {cassette_name: "vehicle-charge_max_range"} do - expect(vehicle.charge_max_range["result"]).to eq(true) + describe '#charge_max_range' do + it 'sets the charge limit to max range (100%)', vcr: {cassette_name: 'vehicle-charge_max_range'} do + expect(vehicle.charge_max_range['result']).to eq(true) end - it "doesn't set the charge rate to max range twice", vcr: {cassette_name: "vehicle-charge_max_range-twice"} do - expect(vehicle.charge_max_range["result"]).to eq(true) - expect(vehicle.charge_max_range).to eq({"result" => false, "reason" => "already_max_range"}) + it 'doesn\'t set the charge rate to max range twice', vcr: {cassette_name: 'vehicle-charge_max_range-twice'} do + expect(vehicle.charge_max_range['result']).to eq(true) + expect(vehicle.charge_max_range).to eq({'result' => false, 'reason' => 'already_max_range'}) end end - describe "#set_charge_limit" do - it "sets the charge limit to 100%", vcr: {cassette_name: "vehicle-set_charge_limit-100"} do - expect(vehicle.set_charge_limit(100)["result"]).to eq(true) + describe '#set_charge_limit' do + it 'sets the charge limit to 100%', vcr: {cassette_name: 'vehicle-set_charge_limit-100'} do + expect(vehicle.set_charge_limit(100)['result']).to eq(true) end - it "sets the charge limit to 90%", vcr: {cassette_name: "vehicle-set_charge_limit-90"} do - expect(vehicle.set_charge_limit(90)["result"]).to eq(true) + it 'sets the charge limit to 90%', vcr: {cassette_name: 'vehicle-set_charge_limit-90'} do + expect(vehicle.set_charge_limit(90)['result']).to eq(true) end - it "sets the charge limit to 50%", vcr: {cassette_name: "vehicle-set_charge_limit-50"} do - expect(vehicle.set_charge_limit(50)["result"]).to eq(true) + it 'sets the charge limit to 50%', vcr: {cassette_name: 'vehicle-set_charge_limit-50'} do + expect(vehicle.set_charge_limit(50)['result']).to eq(true) end - it "doesn't actually set the charge limit to 1%", vcr: {cassette_name: "vehicle-set_charge_limit-1"} do - expect(vehicle.set_charge_limit(1)["result"]).to eq(true) - expect(vehicle.charge_state["charge_limit_soc"]).to eq(50) + it 'doesn\'t actually set the charge limit to 1%', vcr: {cassette_name: 'vehicle-set_charge_limit-1'} do + expect(vehicle.set_charge_limit(1)['result']).to eq(true) + expect(vehicle.charge_state['charge_limit_soc']).to eq(50) end end - describe "#charge_start", vcr: {cassette_name: "vehicle-charge_start"} do - it "starts charging" do - expect(vehicle.charge_start["result"]).to eq(true) + describe '#charge_start', vcr: {cassette_name: 'vehicle-charge_start'} do + it 'starts charging' do + expect(vehicle.charge_start['result']).to eq(true) end end - describe "#charge_stop", vcr: {cassette_name: "vehicle-charge_stop"} do - it "stops charging" do - expect(vehicle.charge_stop["result"]).to eq(true) + describe '#charge_stop', vcr: {cassette_name: 'vehicle-charge_stop'} do + it 'stops charging' do + expect(vehicle.charge_stop['result']).to eq(true) end end - describe "#flash_lights", vcr: {cassette_name: "vehicle-flash_lights"} do - it "flashes the vehicle's lights" do - expect(vehicle.flash_lights["result"]).to eq(true) + describe '#flash_lights', vcr: {cassette_name: 'vehicle-flash_lights'} do + it 'flashes the vehicle\'s lights' do + expect(vehicle.flash_lights['result']).to eq(true) end end - describe "#honk_horn", vcr: {cassette_name: "vehicle-honk_horn"} do - it "honks the vehicle's horn" do - expect(vehicle.honk_horn["result"]).to eq(true) + describe '#honk_horn', vcr: {cassette_name: 'vehicle-honk_horn'} do + it 'honks the vehicle\'s horn' do + expect(vehicle.honk_horn['result']).to eq(true) end end - describe "#door_unlock", vcr: {cassette_name: "vehicle-door_unlock"} do - it "unlocks the vehicle's doors" do - expect(vehicle.door_unlock["result"]).to eq(true) + describe '#door_unlock', vcr: {cassette_name: 'vehicle-door_unlock'} do + it 'unlocks the vehicle\'s doors' do + expect(vehicle.door_unlock['result']).to eq(true) end end - describe "#door_lock", vcr: {cassette_name: "vehicle-door_lock"} do - it "locks the vehicle's doors" do - expect(vehicle.door_lock["result"]).to eq(true) + describe '#door_lock', vcr: {cassette_name: 'vehicle-door_lock'} do + it 'locks the vehicle\'s doors' do + expect(vehicle.door_lock['result']).to eq(true) end end - describe "#set_temps" do - it "sets the desired temperature in the car to 70", vcr: {cassette_name: "vehicle-set_temps-70-70"} do - expect(vehicle.set_temps(20.9, 20.9)["result"]).to eq(true) + describe '#set_temps' do + it 'sets the desired temperature in the car to 70', vcr: {cassette_name: 'vehicle-set_temps-70-70'} do + expect(vehicle.set_temps(20.9, 20.9)['result']).to eq(true) end - it "sets the desired temperature in the car to 75 and 65", vcr: {cassette_name: "vehicle-set_temps-75-65"} do - expect(vehicle.set_temps(23.7, 23.7)["result"]).to eq(true) + it 'sets the desired temperature in the car to 75 and 65', vcr: {cassette_name: 'vehicle-set_temps-75-65'} do + expect(vehicle.set_temps(23.7, 23.7)['result']).to eq(true) end end - describe "#auto_conditioning_start", vcr: {cassette_name: "vehicle-auto_conditioning_start"} do - it "starts the HVAC system" do - expect(vehicle.auto_conditioning_start["result"]).to eq(true) + describe '#auto_conditioning_start', vcr: {cassette_name: 'vehicle-auto_conditioning_start'} do + it 'starts the HVAC system' do + expect(vehicle.auto_conditioning_start['result']).to eq(true) end end - describe "#auto_conditioning_stop", vcr: {cassette_name: "vehicle-auto_conditioning_stop"} do - it "stops the HVAC system" do - expect(vehicle.auto_conditioning_stop["result"]).to eq(true) + describe '#auto_conditioning_stop', vcr: {cassette_name: 'vehicle-auto_conditioning_stop'} do + it 'stops the HVAC system' do + expect(vehicle.auto_conditioning_stop['result']).to eq(true) end end - describe "#sun_roof_control" do - it "opens the sun roof", vcr: {cassette_name: "vehicle-sun_roof_control-open"} do - expect(vehicle.sun_roof_control("open")["result"]).to eq(true) + describe '#sun_roof_control' do + it 'opens the sun roof', vcr: {cassette_name: 'vehicle-sun_roof_control-open'} do + expect(vehicle.sun_roof_control('open')['result']).to eq(true) end - it "closes the sun roof", vcr: {cassette_name: "vehicle-sun_roof_control-close"} do - expect(vehicle.sun_roof_control("close")["result"]).to eq(true) + it 'closes the sun roof', vcr: {cassette_name: 'vehicle-sun_roof_control-close'} do + expect(vehicle.sun_roof_control('close')['result']).to eq(true) end - it "vents the sun roof", vcr: {cassette_name: "vehicle-sun_roof_control-vent"} do - expect(vehicle.sun_roof_control("vent")["result"]).to eq(true) + it 'vents the sun roof', vcr: {cassette_name: 'vehicle-sun_roof_control-vent'} do + expect(vehicle.sun_roof_control('vent')['result']).to eq(true) end - it "sets the sun roof to the comfort (80%) setting", vcr: {cassette_name: "vehicle-sun_roof_control-comfort"} do - expect(vehicle.sun_roof_control("comfort")["result"]).to eq(true) + it 'sets the sun roof to the comfort (80%) setting', vcr: {cassette_name: 'vehicle-sun_roof_control-comfort'} do + expect(vehicle.sun_roof_control('comfort')['result']).to eq(true) end end - describe "#sun_roof_move" do - it "moves the sun roof to 100% open", vcr: {cassette_name: "vehicle-sun_roof_move-100"} do - expect(vehicle.sun_roof_move(100)["result"]).to eq(true) + describe '#sun_roof_move' do + it 'moves the sun roof to 100% open', vcr: {cassette_name: 'vehicle-sun_roof_move-100'} do + expect(vehicle.sun_roof_move(100)['result']).to eq(true) end - it "moves the sun roof to closed", vcr: {cassette_name: "vehicle-sun_roof_move-0"} do - expect(vehicle.sun_roof_move(0)["result"]).to eq(true) + it 'moves the sun roof to closed', vcr: {cassette_name: 'vehicle-sun_roof_move-0'} do + expect(vehicle.sun_roof_move(0)['result']).to eq(true) end - it "moves the sun roof to 50% open", vcr: {cassette_name: "vehicle-sun_roof_move-50"} do - expect(vehicle.sun_roof_move(50)["result"]).to eq(true) + it 'moves the sun roof to 50% open', vcr: {cassette_name: 'vehicle-sun_roof_move-50'} do + expect(vehicle.sun_roof_move(50)['result']).to eq(true) end end - describe "#remote_start_drive", vcr: {cassette_name: "vehicle-remote_start_drive"} do - it "starts the vehicle's keyless driving mode" do - expect(vehicle.remote_start_drive("elon4eva")["result"]).to eq(true) + describe '#remote_start_drive', vcr: {cassette_name: 'vehicle-remote_start_drive'} do + it 'starts the vehicle\'s keyless driving mode' do + expect(vehicle.remote_start_drive('elon4eva')['result']).to eq(true) end end - describe "#open_trunk", vcr: {cassette_name: "vehicle-open_trunk"} do - it "opens the trunk" do - expect(vehicle.open_frunk["result"]).to eq(true) + describe '#open_trunk', vcr: {cassette_name: 'vehicle-open_trunk'} do + it 'opens the trunk' do + expect(vehicle.open_frunk['result']).to eq(true) end end - describe "#open_frunk", vcr: {cassette_name: "vehicle-open_frunk"} do - it "opens the frunk" do - expect(vehicle.open_frunk["result"]).to eq(true) + describe '#open_frunk', vcr: {cassette_name: 'vehicle-open_frunk'} do + it 'opens the frunk' do + expect(vehicle.open_frunk['result']).to eq(true) end end - describe '#activate_speed_limit', vcr: {cassette_name: "vehicle-activate_speed_limit"} do - it "activates the speed limit" do - expect(vehicle.activate_speed_limit("1234")["result"]).to eq(true) + describe '#activate_speed_limit', vcr: {cassette_name: 'vehicle-activate_speed_limit'} do + it 'activates the speed limit' do + expect(vehicle.activate_speed_limit('1234')['result']).to eq(true) end end - describe '#deactivate_speed_limit', vcr: {cassette_name: "vehicle-deactivate_speed_limit"} do - it "deactivates the speed limit" do - expect(vehicle.deactivate_speed_limit("1234")["result"]).to eq(true) + describe '#deactivate_speed_limit', vcr: {cassette_name: 'vehicle-deactivate_speed_limit'} do + it 'deactivates the speed limit' do + expect(vehicle.deactivate_speed_limit('1234')['result']).to eq(true) end end - describe '#set_speed_limit', vcr: {cassette_name: "vehicle-set_speed_limit"} do - it "sets the speed limit" do - expect(vehicle.set_speed_limit(65)["result"]).to eq(true) + describe '#set_speed_limit', vcr: {cassette_name: 'vehicle-set_speed_limit'} do + it 'sets the speed limit' do + expect(vehicle.set_speed_limit(65)['result']).to eq(true) end end - describe '#clear_speed_limit_pin', vcr: {cassette_name: "vehicle-clear_speed_limit_pin"} do - it "clears the speed limit pin" do - expect(vehicle.clear_speed_limit_pin("1234")["result"]).to eq(true) + describe '#clear_speed_limit_pin', vcr: {cassette_name: 'vehicle-clear_speed_limit_pin'} do + it 'clears the speed limit pin' do + expect(vehicle.clear_speed_limit_pin('1234')['result']).to eq(true) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3de2c63b..ce2a0358 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,16 +8,16 @@ Dotenv.load VCR.configure do |c| - c.cassette_library_dir = "spec/cassettes" + c.cassette_library_dir = 'spec/cassettes' c.hook_into :webmock c.default_cassette_options = {:record => :once} c.configure_rspec_metadata! - c.define_cassette_placeholder("") { CGI::escape(ENV["TESLA_EMAIL"]) } - c.define_cassette_placeholder("") { ENV["TESLA_PASS"] } - c.define_cassette_placeholder("") { ENV["TESLA_CLIENT_ID"] } - c.define_cassette_placeholder("") { ENV["TESLA_CLIENT_SECRET"] } - c.define_cassette_placeholder("") { ENV["TESLA_API_TOKEN"] } + c.define_cassette_placeholder('') { CGI::escape(ENV['TESLA_EMAIL']) } + c.define_cassette_placeholder('') { ENV['TESLA_PASS'] } + c.define_cassette_placeholder('') { ENV['TESLA_CLIENT_ID'] } + c.define_cassette_placeholder('') { ENV['TESLA_CLIENT_SECRET'] } + c.define_cassette_placeholder('') { ENV['TESLA_API_TOKEN'] } end RSpec.configure do |config|