Skip to content

Commit

Permalink
Add Stream title to attributes for radio streams (#1729)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Dec 30, 2023
1 parent 020b91a commit 0eaebd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions custom_components/mass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ATTR_GROUP_LEADER = "group_leader"
ATTR_MASS_PLAYER_ID = "mass_player_id"
ATTR_MASS_PLAYER_TYPE = "mass_player_type"
ATTR_STREAM_TITLE = "stream_title"

ADDON_SLUG = "d5369777_music_assistant_beta"
ADDON_HOSTNAME = "d5369777-music-assistant-beta"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/music-assistant/hass-music-assistant/issues",
"loggers": ["music_assistant"],
"requirements": ["music-assistant==2.0.0b59"],
"requirements": ["music-assistant==2.0.0b79"],
"version": "0.0.0",
"zeroconf": ["_mass._tcp.local."]
}
20 changes: 19 additions & 1 deletion custom_components/mass/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ATTR_MASS_PLAYER_TYPE,
ATTR_QUEUE_INDEX,
ATTR_QUEUE_ITEMS,
ATTR_STREAM_TITLE,
DOMAIN,
)
from .entity import MassBaseEntity
Expand Down Expand Up @@ -194,7 +195,7 @@ def extra_state_attributes(self) -> Mapping[str, Any]:
"""Return additional state attributes."""
player = self.player
queue = self.mass.players.get_player_queue(player.active_source)
return {
attrs = {
ATTR_MASS_PLAYER_ID: self.player_id,
ATTR_MASS_PLAYER_TYPE: player.type.value,
ATTR_GROUP_MEMBERS: player.group_childs,
Expand All @@ -203,6 +204,23 @@ def extra_state_attributes(self) -> Mapping[str, Any]:
ATTR_QUEUE_ITEMS: queue.items if queue else None,
ATTR_QUEUE_INDEX: queue.current_index if queue else None,
}
# add optional stream_title for radio streams
if (
queue
and queue.current_item
and queue.current_item.streamdetails
and queue.current_item.streamdetails.stream_title
):
attrs[ATTR_STREAM_TITLE] = queue.current_item.streamdetails.stream_title
elif (
queue
and queue.current_item
and queue.current_item.media_type == MediaType.RADIO
and queue.current_item.media_item
and queue.current_item.media_item.metadata
):
attrs[ATTR_STREAM_TITLE] = queue.current_item.media_item.metadata.description
return attrs

async def async_on_update(self) -> None:
"""Handle player updates."""
Expand Down
5 changes: 3 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mypy==1.7.1
pylint==3.0.3
pre-commit==3.6.0
homeassistant==2023.11.3
music-assistant==2.0.0b78
homeassistant==2023.12.4
music-assistant==2.0.0b79
async_timeout==4.0.2

0 comments on commit 0eaebd9

Please sign in to comment.