Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map "stop" to MediaPlayerState.IDLE in bluesound integration #129904

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,13 @@ def state(self) -> MediaPlayerState:
if self.is_grouped and not self.is_master:
return MediaPlayerState.IDLE

status = self._status.state
if status in ("pause", "stop"):
return MediaPlayerState.PAUSED
if status in ("stream", "play"):
return MediaPlayerState.PLAYING
return MediaPlayerState.IDLE
match self._status.state:
case "pause":
return MediaPlayerState.PAUSED
case "stream" | "play":
return MediaPlayerState.PLAYING
case _:
return MediaPlayerState.IDLE

@property
def media_title(self) -> str | None:
Expand Down
20 changes: 20 additions & 0 deletions tests/components/bluesound/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ async def test_attributes_set(
assert state == snapshot(exclude=props("media_position_updated_at"))


async def test_stop_maps_to_idle(
hass: HomeAssistant,
setup_config_entry: None,
player_mocks: PlayerMocks,
) -> None:
"""Test the media player stop maps to idle."""
player_mocks.player_data.status_long_polling_mock.set(
dataclasses.replace(
player_mocks.player_data.status_long_polling_mock.get(), state="stop"
)
)

# give the long polling loop a chance to update the state; this could be any async call
await hass.async_block_till_done()

assert (
hass.states.get("media_player.player_name1111").state == MediaPlayerState.IDLE
)


async def test_status_updated(
hass: HomeAssistant,
setup_config_entry: None,
Expand Down