diff --git a/tests/components/spotify/conftest.py b/tests/components/spotify/conftest.py index 581d54fe0db..757a4b57250 100644 --- a/tests/components/spotify/conftest.py +++ b/tests/components/spotify/conftest.py @@ -79,6 +79,7 @@ def mock_spotify() -> Generator[MagicMock]: client.current_user.return_value = current_user client.me.return_value = current_user for fixture, method in ( + ("devices.json", "devices"), ("current_user_playlist.json", "current_user_playlists"), ("playback.json", "current_playback"), ("followed_artists.json", "current_user_followed_artists"), diff --git a/tests/components/spotify/fixtures/devices.json b/tests/components/spotify/fixtures/devices.json new file mode 100644 index 00000000000..2dd8dfd7c3b --- /dev/null +++ b/tests/components/spotify/fixtures/devices.json @@ -0,0 +1,14 @@ +{ + "devices": [ + { + "id": "21dac6b0e0a1f181870fdc9749b2656466557666", + "is_active": false, + "is_private_session": false, + "is_restricted": false, + "name": "DESKTOP-BKC5SIK", + "supports_volume": true, + "type": "Computer", + "volume_percent": 69 + } + ] +} diff --git a/tests/components/spotify/snapshots/test_media_player.ambr b/tests/components/spotify/snapshots/test_media_player.ambr index c7861788d9c..1688df66ed9 100644 --- a/tests/components/spotify/snapshots/test_media_player.ambr +++ b/tests/components/spotify/snapshots/test_media_player.ambr @@ -5,6 +5,9 @@ }), 'area_id': None, 'capabilities': dict({ + 'source_list': list([ + 'DESKTOP-BKC5SIK', + ]), }), 'config_entry_id': , 'device_class': None, @@ -51,6 +54,9 @@ 'repeat': , 'shuffle': False, 'source': 'Master Bathroom Speaker', + 'source_list': list([ + 'DESKTOP-BKC5SIK', + ]), 'supported_features': , 'volume_level': 0.25, }), @@ -68,6 +74,9 @@ }), 'area_id': None, 'capabilities': dict({ + 'source_list': list([ + 'DESKTOP-BKC5SIK', + ]), }), 'config_entry_id': , 'device_class': None, @@ -112,6 +121,9 @@ 'repeat': , 'shuffle': False, 'source': 'Sonos Roam SL', + 'source_list': list([ + 'DESKTOP-BKC5SIK', + ]), 'supported_features': , 'volume_level': 0.46, }), diff --git a/tests/components/spotify/test_media_player.py b/tests/components/spotify/test_media_player.py index 6f45263f260..03b46b88a5f 100644 --- a/tests/components/spotify/test_media_player.py +++ b/tests/components/spotify/test_media_player.py @@ -7,6 +7,7 @@ from spotipy import SpotifyException from syrupy import SnapshotAssertion from homeassistant.components.media_player import ( + ATTR_INPUT_SOURCE, ATTR_MEDIA_CONTENT_ID, ATTR_MEDIA_CONTENT_TYPE, ATTR_MEDIA_ENQUEUE, @@ -16,6 +17,7 @@ from homeassistant.components.media_player import ( ATTR_MEDIA_VOLUME_LEVEL, DOMAIN as MEDIA_PLAYER_DOMAIN, SERVICE_PLAY_MEDIA, + SERVICE_SELECT_SOURCE, MediaPlayerEnqueue, MediaPlayerEntityFeature, MediaPlayerState, @@ -391,3 +393,25 @@ async def test_play_unsupported_media( ) assert mock_spotify.return_value.start_playback.call_count == 0 assert mock_spotify.return_value.add_to_queue.call_count == 0 + + +@pytest.mark.usefixtures("setup_credentials") +async def test_select_source( + hass: HomeAssistant, + mock_spotify: MagicMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test the Spotify media player source select.""" + await setup_integration(hass, mock_config_entry) + await hass.services.async_call( + MEDIA_PLAYER_DOMAIN, + SERVICE_SELECT_SOURCE, + { + ATTR_ENTITY_ID: "media_player.spotify_spotify_1", + ATTR_INPUT_SOURCE: "DESKTOP-BKC5SIK", + }, + blocking=True, + ) + mock_spotify.return_value.transfer_playback.assert_called_with( + "21dac6b0e0a1f181870fdc9749b2656466557666", True + )