From c78212b0cdf96a490899749be3d832e5d2788fdc Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 3 Oct 2019 13:25:44 -0400 Subject: [PATCH] Feature/media (#157) * Add media commands * media_toggle_playback * media_next_track * media_prev_track * media_next_fav * media_prev_fav * media_volume_up * media_volume_down * Add media specs * Add vcr cassettes for media specs --- lib/tesla_api/vehicle.rb | 28 +++++ spec/cassettes/vehicle-media_next_fav.yml | 109 ++++++++++++++++++ spec/cassettes/vehicle-media_next_track.yml | 109 ++++++++++++++++++ spec/cassettes/vehicle-media_prev_fav.yml | 109 ++++++++++++++++++ spec/cassettes/vehicle-media_prev_track.yml | 109 ++++++++++++++++++ .../vehicle-media_toggle_playback.yml | 109 ++++++++++++++++++ spec/cassettes/vehicle-media_volume_down.yml | 109 ++++++++++++++++++ spec/cassettes/vehicle-media_volume_up.yml | 109 ++++++++++++++++++ spec/lib/tesla_api/vehicle_spec.rb | 44 +++++++ 9 files changed, 835 insertions(+) create mode 100644 spec/cassettes/vehicle-media_next_fav.yml create mode 100644 spec/cassettes/vehicle-media_next_track.yml create mode 100644 spec/cassettes/vehicle-media_prev_fav.yml create mode 100644 spec/cassettes/vehicle-media_prev_track.yml create mode 100644 spec/cassettes/vehicle-media_toggle_playback.yml create mode 100644 spec/cassettes/vehicle-media_volume_down.yml create mode 100644 spec/cassettes/vehicle-media_volume_up.yml diff --git a/lib/tesla_api/vehicle.rb b/lib/tesla_api/vehicle.rb index 22cd5d8d..631ce890 100644 --- a/lib/tesla_api/vehicle.rb +++ b/lib/tesla_api/vehicle.rb @@ -210,6 +210,34 @@ def trigger_homelink(lat, lon) command('trigger_homelink', body: {lat: lat, lon: lon})['response'] end + def media_toggle_playback + command('media_toggle_playback')['response'] + end + + def media_next_track + command('media_next_track')['response'] + end + + def media_prev_track + command('media_prev_track')['response'] + end + + def media_next_fav + command('media_next_fav')['response'] + end + + def media_prev_fav + command('media_prev_fav')['response'] + end + + def media_volume_up + command('media_volume_up')['response'] + end + + def media_volume_down + command('media_volume_down')['response'] + end + private def data_request(name) diff --git a/spec/cassettes/vehicle-media_next_fav.yml b/spec/cassettes/vehicle-media_next_fav.yml new file mode 100644 index 00000000..8f78b1ac --- /dev/null +++ b/spec/cassettes/vehicle-media_next_fav.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:15 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 14bff6e11faacd74f2e45e00ce3a22ca + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 1c00cd57-2b52-43f1-b179-4569cbe3cc9d + X-Runtime: + - '0.037398' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:15 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_next_fav + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:16 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: + - 8071c728da780d613a3b5af7e219c080 + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 23e04dbb-c730-4d64-949d-1f6fb5723cc8 + X-Runtime: + - '0.535570' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:16 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-media_next_track.yml b/spec/cassettes/vehicle-media_next_track.yml new file mode 100644 index 00000000..1455fe5a --- /dev/null +++ b/spec/cassettes/vehicle-media_next_track.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:10 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 53507e4ddb533acdca04c85e956d5d0b + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - e0c1920f-ebca-44d5-818e-419632e19b30 + X-Runtime: + - '0.034419' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:10 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_next_track + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:11 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: + - 3378733fc84bfc9a0d8ca8829f3e061e + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 7d4d8512-ede6-47f7-bec0-0d8827369cce + X-Runtime: + - '0.233400' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:11 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-media_prev_fav.yml b/spec/cassettes/vehicle-media_prev_fav.yml new file mode 100644 index 00000000..2d637532 --- /dev/null +++ b/spec/cassettes/vehicle-media_prev_fav.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:13 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - ebdbffdab2c2775c54baa8da990d85bf + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - c88974d9-c7d5-4082-a197-6b0106a1272b + X-Runtime: + - '0.043550' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:13 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_prev_fav + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:14 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: + - 6a65e94c22f4feabfcacfe9695305d8b + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 8e593817-2ce5-4ce7-89e2-9543421af7a3 + X-Runtime: + - '0.438129' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:14 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-media_prev_track.yml b/spec/cassettes/vehicle-media_prev_track.yml new file mode 100644 index 00000000..94944d35 --- /dev/null +++ b/spec/cassettes/vehicle-media_prev_track.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:12 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 6a2031faf6edd5db7dbd035750238f13 + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 5beba8de-97b6-4372-8db7-8cd727aafbc0 + X-Runtime: + - '0.024729' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:12 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_prev_track + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:13 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: + - dbb5802aa39b5317ccdf1c02efb3c686 + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 0f31b943-eee3-437d-a6a2-4c06a09a97c7 + X-Runtime: + - '0.411534' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:13 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-media_toggle_playback.yml b/spec/cassettes/vehicle-media_toggle_playback.yml new file mode 100644 index 00000000..5e20bd61 --- /dev/null +++ b/spec/cassettes/vehicle-media_toggle_playback.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:07 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - dfaa20808000cca42d2d5e236eaf33a9 + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - d6c767b3-4425-4ddf-91f4-b3c3823db73f + X-Runtime: + - '0.018363' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:07 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_toggle_playback + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:08 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: + - 0fb86e2b83309cbf87ad5e4aa322ee26 + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 84566bae-cfc5-4818-92db-a2b48be0bf0a + X-Runtime: + - '0.466495' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:08 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-media_volume_down.yml b/spec/cassettes/vehicle-media_volume_down.yml new file mode 100644 index 00000000..bf831196 --- /dev/null +++ b/spec/cassettes/vehicle-media_volume_down.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:05 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 796921f5a214dd0e5ffef9a7c098732e + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 6dce7691-3341-49e9-9336-f643b343ba6c + X-Runtime: + - '0.024369' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:05 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_volume_down + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:06 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: + - 7d39d164b7236420df18cd8f493f3aa9 + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 54ca8542-89ef-491a-b936-a21347a0a69e + X-Runtime: + - '0.427457' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:07 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/vehicle-media_volume_up.yml b/spec/cassettes/vehicle-media_volume_up.yml new file mode 100644 index 00000000..b5adfad1 --- /dev/null +++ b/spec/cassettes/vehicle-media_volume_up.yml @@ -0,0 +1,109 @@ +--- +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:3.0.1 + Authorization: + - Bearer + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:09 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '569' + Connection: + - keep-alive + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Txid: + - 0bdb6b5922a2eb417845f8cc734b9575 + Etag: + - W/"fee0c127f31e354aae63ac0325c6cce4" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 644429de-81cd-4254-a568-368fa64ac962 + X-Runtime: + - '0.023907' + body: + encoding: UTF-8 + string: '{"response":[{"id":1,"vehicle_id":1,"vin":"1","display_name":"tm3","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["1","1"],"state":"online","in_service":false,"id_s":"1","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:09 GMT +- request: + method: post + uri: https://owner-api.teslamotors.com/api/1/vehicles/1/command/media_volume_up + body: + encoding: UTF-8 + string: '' + headers: + User-Agent: + - github.com/timdorr/tesla-api v:3.0.1 + Authorization: + - Bearer + Content-Length: + - '0' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Thu, 03 Oct 2019 12:07:10 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: + - e755be3a3feafe691897ee6a73d76776 + Etag: + - W/"f67eec105dd6522783a1f1bacc52723a" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 1816dbf7-4dec-4914-bc70-2eed155517da + X-Runtime: + - '0.339461' + body: + encoding: UTF-8 + string: '{"response":{"reason":"","result":true}}' + http_version: + recorded_at: Thu, 03 Oct 2019 12:07:10 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 9425fab6..97864d87 100644 --- a/spec/lib/tesla_api/vehicle_spec.rb +++ b/spec/lib/tesla_api/vehicle_spec.rb @@ -331,4 +331,48 @@ expect(vehicle.set_sentry_mode(false)['result']).to eq(true) end end + + context '#media' do + describe '#media_toggle_playback', vcr: {cassette_name: 'vehicle-media_toggle_playback'} do + it 'toggles media from playing and paused' do + expect(vehicle.media_toggle_playback['result']).to eq(true) + end + end + + describe '#media_next_track', vcr: {cassette_name: 'vehicle-media_next_track'} do + it 'plays the next track in playlist' do + expect(vehicle.media_next_track['result']).to eq(true) + end + end + + describe '#media_prev_track', vcr: {cassette_name: 'vehicle-media_prev_track'} do + it 'plays the previous track in playlist' do + expect(vehicle.media_prev_track['result']).to eq(true) + end + end + + describe '#media_next_fav', vcr: {cassette_name: 'vehicle-media_next_fav'} do + it 'plays the next favourite track' do + expect(vehicle.media_next_fav['result']).to eq(true) + end + end + + describe '#media_prev_fav', vcr: {cassette_name: 'vehicle-media_prev_fav'} do + it 'plays the previous favourite track' do + expect(vehicle.media_prev_fav['result']).to eq(true) + end + end + + describe '#media_volume_up', vcr: {cassette_name: 'vehicle-media_volume_up'} do + it 'increases volume of media' do + expect(vehicle.media_volume_up['result']).to eq(true) + end + end + + describe '#media_volume_down', vcr: {cassette_name: 'vehicle-media_volume_down'} do + it 'decreases volume of media' do + expect(vehicle.media_volume_down['result']).to eq(true) + end + end + end end