Skip to content

Commit

Permalink
Replace strings with constants in Bang & Olufsen testing (#125423)
Browse files Browse the repository at this point in the history
Replace strings with constants in service calls
  • Loading branch information
mj23000 authored Sep 6, 2024
1 parent ee59303 commit 741add0
Showing 1 changed file with 58 additions and 46 deletions.
104 changes: 58 additions & 46 deletions tests/components/bang_olufsen/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
ATTR_MEDIA_TRACK,
ATTR_MEDIA_VOLUME_LEVEL,
ATTR_MEDIA_VOLUME_MUTED,
DOMAIN as MEDIA_PLAYER_DOMAIN,
SERVICE_CLEAR_PLAYLIST,
SERVICE_MEDIA_NEXT_TRACK,
SERVICE_MEDIA_PLAY_PAUSE,
SERVICE_MEDIA_PREVIOUS_TRACK,
SERVICE_MEDIA_SEEK,
SERVICE_MEDIA_STOP,
SERVICE_PLAY_MEDIA,
SERVICE_SELECT_SOURCE,
SERVICE_TURN_OFF,
SERVICE_VOLUME_MUTE,
SERVICE_VOLUME_SET,
MediaPlayerState,
MediaType,
)
Expand Down Expand Up @@ -385,8 +397,8 @@ async def test_async_turn_off(
)

await hass.services.async_call(
"media_player",
"turn_off",
MEDIA_PLAYER_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID},
blocking=True,
)
Expand Down Expand Up @@ -416,8 +428,8 @@ async def test_async_set_volume_level(
assert ATTR_MEDIA_VOLUME_LEVEL not in states.attributes

await hass.services.async_call(
"media_player",
"volume_set",
MEDIA_PLAYER_DOMAIN,
SERVICE_VOLUME_SET,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_VOLUME_LEVEL: TEST_VOLUME_HOME_ASSISTANT_FORMAT,
Expand Down Expand Up @@ -454,8 +466,8 @@ async def test_async_mute_volume(
assert ATTR_MEDIA_VOLUME_MUTED not in states.attributes

await hass.services.async_call(
"media_player",
"volume_mute",
MEDIA_PLAYER_DOMAIN,
SERVICE_VOLUME_MUTE,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_VOLUME_MUTED: TEST_VOLUME_HOME_ASSISTANT_FORMAT,
Expand Down Expand Up @@ -509,8 +521,8 @@ async def test_async_media_play_pause(
assert states.state == BANG_OLUFSEN_STATES[initial_state.value]

await hass.services.async_call(
"media_player",
"media_play_pause",
MEDIA_PLAYER_DOMAIN,
SERVICE_MEDIA_PLAY_PAUSE,
{ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID},
blocking=True,
)
Expand Down Expand Up @@ -539,8 +551,8 @@ async def test_async_media_stop(
assert states.state == BANG_OLUFSEN_STATES[TEST_PLAYBACK_STATE_PLAYING.value]

await hass.services.async_call(
"media_player",
"media_stop",
MEDIA_PLAYER_DOMAIN,
SERVICE_MEDIA_STOP,
{ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID},
blocking=True,
)
Expand All @@ -560,8 +572,8 @@ async def test_async_media_next_track(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"media_next_track",
MEDIA_PLAYER_DOMAIN,
SERVICE_MEDIA_NEXT_TRACK,
{ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID},
blocking=True,
)
Expand Down Expand Up @@ -601,8 +613,8 @@ async def test_async_media_seek(
# Check results
with expected_result:
await hass.services.async_call(
"media_player",
"media_seek",
MEDIA_PLAYER_DOMAIN,
SERVICE_MEDIA_SEEK,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_SEEK_POSITION: TEST_SEEK_POSITION_HOME_ASSISTANT_FORMAT,
Expand All @@ -624,8 +636,8 @@ async def test_async_media_previous_track(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"media_previous_track",
MEDIA_PLAYER_DOMAIN,
SERVICE_MEDIA_PREVIOUS_TRACK,
{ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID},
blocking=True,
)
Expand All @@ -644,8 +656,8 @@ async def test_async_clear_playlist(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"clear_playlist",
MEDIA_PLAYER_DOMAIN,
SERVICE_CLEAR_PLAYLIST,
{ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID},
blocking=True,
)
Expand Down Expand Up @@ -680,8 +692,8 @@ async def test_async_select_source(

with expected_result:
await hass.services.async_call(
"media_player",
"select_source",
MEDIA_PLAYER_DOMAIN,
SERVICE_SELECT_SOURCE,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_INPUT_SOURCE: source,
Expand All @@ -705,8 +717,8 @@ async def test_async_play_media_invalid_type(

with pytest.raises(ServiceValidationError) as exc_info:
await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "test",
Expand Down Expand Up @@ -734,8 +746,8 @@ async def test_async_play_media_url(
await async_setup_component(hass, "media_source", {"media_source": {}})

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "media-source://media_source/local/doorbell.mp3",
Expand All @@ -760,8 +772,8 @@ async def test_async_play_media_overlay_absolute_volume_uri(
await async_setup_component(hass, "media_source", {"media_source": {}})

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "media-source://media_source/local/doorbell.mp3",
Expand Down Expand Up @@ -792,8 +804,8 @@ async def test_async_play_media_overlay_invalid_offset_volume_tts(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "Dette er en test",
Expand Down Expand Up @@ -829,8 +841,8 @@ async def test_async_play_media_overlay_offset_volume_tts(
volume_callback(TEST_VOLUME)

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "This is a test",
Expand Down Expand Up @@ -859,8 +871,8 @@ async def test_async_play_media_tts(
await async_setup_component(hass, "media_source", {"media_source": {}})

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "media-source://media_source/local/doorbell.mp3",
Expand All @@ -883,8 +895,8 @@ async def test_async_play_media_radio(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "1234567890123456",
Expand All @@ -909,8 +921,8 @@ async def test_async_play_media_favourite(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "1",
Expand All @@ -934,8 +946,8 @@ async def test_async_play_media_deezer_flow(

# Send a service call
await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "flow",
Expand All @@ -961,8 +973,8 @@ async def test_async_play_media_deezer_playlist(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "playlist:1234567890",
Expand All @@ -988,8 +1000,8 @@ async def test_async_play_media_deezer_track(
await hass.config_entries.async_setup(mock_config_entry.entry_id)

await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "1234567890",
Expand Down Expand Up @@ -1017,8 +1029,8 @@ async def test_async_play_media_invalid_deezer(

with pytest.raises(HomeAssistantError) as exc_info:
await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "flow",
Expand Down Expand Up @@ -1054,8 +1066,8 @@ async def test_async_play_media_url_m3u(
),
):
await hass.services.async_call(
"media_player",
"play_media",
MEDIA_PLAYER_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: TEST_MEDIA_PLAYER_ENTITY_ID,
ATTR_MEDIA_CONTENT_ID: "media-source://media_source/local/doorbell.mp3",
Expand Down

0 comments on commit 741add0

Please sign in to comment.