mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Show internet radio station if no artist is available in Cambridge Audio (#140716)
* Add media_channel property to cambridge audio * Return channel instead of artist when playing internet radio to mimick behaviour of CXN100 and StreamMagic app * Add test for media_artist attribute * Add test that media_artist is not set in certain cases * Update homeassistant/components/cambridge_audio/media_player.py Co-authored-by: Noah Husby <32528627+noahhusby@users.noreply.github.com> --------- Co-authored-by: Noah Husby <32528627+noahhusby@users.noreply.github.com>
This commit is contained in:
parent
078be3b8df
commit
267a80e70c
@ -142,6 +142,12 @@ class CambridgeAudioDevice(CambridgeAudioEntity, MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def media_artist(self) -> str | None:
|
def media_artist(self) -> str | None:
|
||||||
"""Artist of current playing media, music track only."""
|
"""Artist of current playing media, music track only."""
|
||||||
|
if (
|
||||||
|
not self.client.play_state.metadata.artist
|
||||||
|
and self.client.state.source == "IR"
|
||||||
|
):
|
||||||
|
# Return channel instead of artist when playing internet radio
|
||||||
|
return self.client.play_state.metadata.station
|
||||||
return self.client.play_state.metadata.artist
|
return self.client.play_state.metadata.artist
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -169,6 +175,11 @@ class CambridgeAudioDevice(CambridgeAudioEntity, MediaPlayerEntity):
|
|||||||
"""Last time the media position was updated."""
|
"""Last time the media position was updated."""
|
||||||
return self.client.position_last_updated
|
return self.client.position_last_updated
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_channel(self) -> str | None:
|
||||||
|
"""Channel currently playing."""
|
||||||
|
return self.client.play_state.metadata.station
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_volume_muted(self) -> bool | None:
|
def is_volume_muted(self) -> bool | None:
|
||||||
"""Volume mute status."""
|
"""Volume mute status."""
|
||||||
|
@ -10,6 +10,7 @@ from aiostreammagic import (
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
|
ATTR_MEDIA_ARTIST,
|
||||||
ATTR_MEDIA_CONTENT_ID,
|
ATTR_MEDIA_CONTENT_ID,
|
||||||
ATTR_MEDIA_CONTENT_TYPE,
|
ATTR_MEDIA_CONTENT_TYPE,
|
||||||
ATTR_MEDIA_REPEAT,
|
ATTR_MEDIA_REPEAT,
|
||||||
@ -489,3 +490,41 @@ async def test_play_media_unknown_type(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("source_id", "artist", "station", "display"),
|
||||||
|
[
|
||||||
|
("MEDIA_PLAYER", "Metallica", None, "Metallica"),
|
||||||
|
("USB_AUDIO", "Iron Maiden", "Radio BOB!", "Iron Maiden"),
|
||||||
|
("IR", "In Flames", "Radio BOB!", "In Flames"),
|
||||||
|
("IR", None, "Radio BOB!", "Radio BOB!"),
|
||||||
|
("IR", None, None, None),
|
||||||
|
("MEDIA_PLAYER", None, "Radio BOB!", None),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_media_artist(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_stream_magic_client: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
source_id: str,
|
||||||
|
artist: str,
|
||||||
|
station: str,
|
||||||
|
display: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test media player state."""
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
mock_stream_magic_client.play_state.metadata.artist = artist
|
||||||
|
mock_stream_magic_client.play_state.metadata.station = station
|
||||||
|
mock_stream_magic_client.state.source = source_id
|
||||||
|
|
||||||
|
await mock_state_update(mock_stream_magic_client)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get(ENTITY_ID)
|
||||||
|
if (artist is None and source_id != "IR") or (
|
||||||
|
source_id == "IR" and station is None
|
||||||
|
):
|
||||||
|
assert ATTR_MEDIA_ARTIST not in state.attributes
|
||||||
|
else:
|
||||||
|
assert state.attributes[ATTR_MEDIA_ARTIST] == display
|
||||||
|
Loading…
x
Reference in New Issue
Block a user