From 7efd8089c88466a6c24c83f8eff2f3cbf431fabc Mon Sep 17 00:00:00 2001 From: Pete Sage <76050312+PeteRager@users.noreply.github.com> Date: Sat, 17 Aug 2024 07:47:27 -0400 Subject: [PATCH] Add Sonos test for media_player play, pause, stop, previous, next (#122978) * initial commit * update to use constant * retrigger checks --- tests/components/sonos/test_media_player.py | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/components/sonos/test_media_player.py b/tests/components/sonos/test_media_player.py index ddf84efd7da..b7b879dc368 100644 --- a/tests/components/sonos/test_media_player.py +++ b/tests/components/sonos/test_media_player.py @@ -15,6 +15,7 @@ from homeassistant.components.media_player import ( ATTR_MEDIA_SHUFFLE, ATTR_MEDIA_VOLUME_LEVEL, DOMAIN as MP_DOMAIN, + SERVICE_CLEAR_PLAYLIST, SERVICE_PLAY_MEDIA, SERVICE_SELECT_SOURCE, MediaPlayerEnqueue, @@ -33,6 +34,11 @@ from homeassistant.components.sonos.media_player import ( ) from homeassistant.const import ( ATTR_ENTITY_ID, + SERVICE_MEDIA_NEXT_TRACK, + SERVICE_MEDIA_PAUSE, + SERVICE_MEDIA_PLAY, + SERVICE_MEDIA_PREVIOUS_TRACK, + SERVICE_MEDIA_STOP, SERVICE_REPEAT_SET, SERVICE_SHUFFLE_SET, SERVICE_VOLUME_DOWN, @@ -963,3 +969,33 @@ async def test_volume( ) # SoCo uses 0..100 for its range. assert soco.volume == 30 + + +@pytest.mark.parametrize( + ("service", "client_call"), + [ + (SERVICE_MEDIA_PLAY, "play"), + (SERVICE_MEDIA_PAUSE, "pause"), + (SERVICE_MEDIA_STOP, "stop"), + (SERVICE_MEDIA_NEXT_TRACK, "next"), + (SERVICE_MEDIA_PREVIOUS_TRACK, "previous"), + (SERVICE_CLEAR_PLAYLIST, "clear_queue"), + ], +) +async def test_media_transport( + hass: HomeAssistant, + soco: MockSoCo, + async_autosetup_sonos, + service: str, + client_call: str, +) -> None: + """Test the media player transport services.""" + await hass.services.async_call( + MP_DOMAIN, + service, + { + ATTR_ENTITY_ID: "media_player.zone_a", + }, + blocking=True, + ) + assert getattr(soco, client_call).call_count == 1