From 9c42c881574f7c67c3c81fc3d4f14977220a745c Mon Sep 17 00:00:00 2001 From: Jordan <15076623+jor-dan@users.noreply.github.com> Date: Sun, 24 Feb 2019 12:32:08 -0800 Subject: [PATCH] Support for seat/steering wheel heater requests (#116) * Add set_seat_heater and set_steering_wheel_heater * Add tests for seat and steering wheel heaters --- lib/tesla_api/vehicle.rb | 8 ++ .../cassettes/vehicle-seat_heater_request.yml | 100 ++++++++++++++++++ .../vehicle-steering_wheel_heater_request.yml | 100 ++++++++++++++++++ spec/lib/tesla_api/vehicle_spec.rb | 12 +++ 4 files changed, 220 insertions(+) create mode 100644 spec/cassettes/vehicle-seat_heater_request.yml create mode 100644 spec/cassettes/vehicle-steering_wheel_heater_request.yml diff --git a/lib/tesla_api/vehicle.rb b/lib/tesla_api/vehicle.rb index 7017893a..31287001 100644 --- a/lib/tesla_api/vehicle.rb +++ b/lib/tesla_api/vehicle.rb @@ -182,6 +182,14 @@ def cancel_software_update command('cancel_software_update')['response'] end + def set_seat_heater(heater, level) + command('remote_seat_heater_request', body: {heater: heater, level: level})['response'] + end + + def set_steering_wheel_heater(on) + command('remote_steering_wheel_heater_request', body: {on: on})['response'] + end + private def data_request(name) diff --git a/spec/cassettes/vehicle-seat_heater_request.yml b/spec/cassettes/vehicle-seat_heater_request.yml new file mode 100644 index 00000000..3635207f --- /dev/null +++ b/spec/cassettes/vehicle-seat_heater_request.yml @@ -0,0 +1,100 @@ +--- +http_interactions: +- request: + method: get + uri: https://owner-api.teslamotors.com/api/1/vehicles + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:1.4.1 + Authorization: + - Bearer + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Sun, 24 Feb 2019 01:43:45 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '560' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - c4c935f820bb983ab39c3cb55cff40b9 + Etag: + - W/"ab623a35dcb4358cb8efa907f4c48acb" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 3937089b-c69c-51a9-b30b-3c5cc32bab5a + X-Runtime: + - '0.031140' + body: + encoding: UTF-8 + string: '{"response":[{"id":19298251174317440,"vehicle_id":1817902171,"vin":"5YJSA1E41GF167745","display_name":"Nikola + 2.0","option_codes":"MDLS,RENA,AF02,APF1,APH2,APPB,AU01,BC0R,BP00,BR00,BS00,CDM0,CH05,PBCW,CW00,DCF0,DRLH,DSH7,DV4W,FG02,FR04,HP00,IDBA,IX01,LP01,ME02,MI01,PF01,PI01,PK00,PS01,PX00,PX4D,QTVB,RFP2,SC01,SP00,SR01,SU01,TM00,TP03,TR00,UTAB,WTAS,X001,X003,X007,X011,X013,X021,X024,X027,X028,X031,X037,X040,X044,YFFC,COUS","color":null,"tokens":["921c1c9a2f2b479a","08f5098517a10231"],"state":"online","in_service":false,"id_s":"19298251174317440","calendar_enabled":true,"api_version":4,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Sun, 24 Feb 2019 01:43:45 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/19298251174317440/command/remote_seat_heater_request + body: + encoding: UTF-8 + string: heater=1&level=0 + headers: + User-Agent: + - github.com/timdorr/tesla-api v:1.4.1 + Authorization: + - Bearer + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Sun, 24 Feb 2019 01:43:46 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '40' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 285c2b1b42411a224af014a336d5a3c2 + Etag: + - W/"17f1bc21c0a8289b664a341515a4815a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 532f50af-01aa-34ca-81cf-441a43c1c4c1 + X-Runtime: + - '0.296134' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Sun, 24 Feb 2019 01:43:46 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-steering_wheel_heater_request.yml b/spec/cassettes/vehicle-steering_wheel_heater_request.yml new file mode 100644 index 00000000..e56828c9 --- /dev/null +++ b/spec/cassettes/vehicle-steering_wheel_heater_request.yml @@ -0,0 +1,100 @@ +--- +http_interactions: +- request: + method: get + uri: https://owner-api.teslamotors.com/api/1/vehicles + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:1.4.1 + Authorization: + - Bearer + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Sun, 24 Feb 2019 01:45:31 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '560' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 6f71bbfe2f7d615dd53dd27a7d561083 + Etag: + - W/"ac52d151f70236be8a2fd76cc3a7e215" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - beacbab2-72a5-7a1b-ecba-c73c1cd249af + X-Runtime: + - '0.013103' + body: + encoding: UTF-8 + string: '{"response":[{"id":19298251174317440,"vehicle_id":1817902171,"vin":"5YJSA1E41GF167745","display_name":"Nikola + 2.0","option_codes":"MDLS,RENA,AF02,APF1,APH2,APPB,AU01,BC0R,BP00,BR00,BS00,CDM0,CH05,PBCW,CW00,DCF0,DRLH,DSH7,DV4W,FG02,FR04,HP00,IDBA,IX01,LP01,ME02,MI01,PF01,PI01,PK00,PS01,PX00,PX4D,QTVB,RFP2,SC01,SP00,SR01,SU01,TM00,TP03,TR00,UTAB,WTAS,X001,X003,X007,X011,X013,X021,X024,X027,X028,X031,X037,X040,X044,YFFC,COUS","color":null,"tokens":["08f5098517a10231","8d219a2e09242e02"],"state":"online","in_service":false,"id_s":"19298251174317440","calendar_enabled":true,"api_version":4,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Sun, 24 Feb 2019 01:45:31 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/19298251174317440/command/remote_steering_wheel_heater_request + body: + encoding: UTF-8 + string: on=false + headers: + User-Agent: + - github.com/timdorr/tesla-api v:1.4.1 + Authorization: + - Bearer + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Sun, 24 Feb 2019 01:45:32 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '40' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - b0b529831abb830179558ade3f3b4622 + Etag: + - W/"b834d18aa9a08081d6e257c5dc7af1f0" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 3f6c3479-8549-b5f3-32cc-39745e4b75aa + X-Runtime: + - '0.320113' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Sun, 24 Feb 2019 01:45:32 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/lib/tesla_api/vehicle_spec.rb b/spec/lib/tesla_api/vehicle_spec.rb index 3732df25..8a2470d7 100644 --- a/spec/lib/tesla_api/vehicle_spec.rb +++ b/spec/lib/tesla_api/vehicle_spec.rb @@ -317,4 +317,16 @@ expect(vehicle.cancel_software_update['result']).to eq(true) end end + + describe '#seat_heater_request', vcr: {cassette_name: 'vehicle-seat_heater_request'} do + it 'turns off the driver seat heater' do + expect(vehicle.set_seat_heater(1, 0)['result']).to eq(true) + end + end + + describe '#steering_wheel_heater_request', vcr: {cassette_name: 'vehicle-steering_wheel_heater_request'} do + it 'turns off the steering wheel heater' do + expect(vehicle.set_steering_wheel_heater(false)['result']).to eq(true) + end + end end