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

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Louis Christ 2024-11-06 13:10:23 +01:00 committed by GitHub
parent a7ba4bd086
commit 2c1db10986
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View File

@ -364,12 +364,13 @@ class BluesoundPlayer(MediaPlayerEntity):
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:

View File

@ -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,