Skip to content
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
14 changes: 14 additions & 0 deletions homeassistant/components/bang_olufsen/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
class BangOlufsenSource:
"""Class used for associating device source ids with friendly names. May not include all sources."""

DEEZER: Final[Source] = Source(name="Deezer", id="deezer")
LINE_IN: Final[Source] = Source(name="Line-In", id="lineIn")
NET_RADIO: Final[Source] = Source(name="B&O Radio", id="netRadio")
SPDIF: Final[Source] = Source(name="Optical", id="spdif")
TIDAL: Final[Source] = Source(name="Tidal", id="tidal")
UNKNOWN: Final[Source] = Source(name="Unknown Source", id="unknown")
URI_STREAMER: Final[Source] = Source(name="Audio Streamer", id="uriStreamer")


Expand Down Expand Up @@ -75,6 +79,16 @@ class BangOlufsenModel(StrEnum):
BEOSOUND_THEATRE = "Beosound Theatre"


class BangOlufsenAttribute(StrEnum):
"""Enum for extra_state_attribute keys."""

BEOLINK = "beolink"
BEOLINK_PEERS = "peers"
BEOLINK_SELF = "self"
BEOLINK_LEADER = "leader"
BEOLINK_LISTENERS = "listeners"


# Physical "buttons" on devices
class BangOlufsenButtons(StrEnum):
"""Enum for device buttons."""
Expand Down
55 changes: 40 additions & 15 deletions homeassistant/components/bang_olufsen/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
DOMAIN,
FALLBACK_SOURCES,
VALID_MEDIA_TYPES,
BangOlufsenAttribute,
BangOlufsenMediaType,
BangOlufsenSource,
WebsocketNotification,
Expand Down Expand Up @@ -223,7 +224,8 @@ def __init__(self, entry: ConfigEntry, client: MozartClient) -> None:
# Beolink compatible sources
self._beolink_sources: dict[str, bool] = {}
self._remote_leader: BeolinkLeader | None = None
# Extra state attributes for showing Beolink: peer(s), listener(s), leader and self
# Extra state attributes:
# Beolink: peer(s), listener(s), leader and self
self._beolink_attributes: dict[str, dict[str, dict[str, str]]] = {}

async def async_added_to_hass(self) -> None:
Expand Down Expand Up @@ -435,7 +437,10 @@ async def _async_update_name_and_beolink(self) -> None:
await self._async_update_beolink()

async def _async_update_beolink(self) -> None:
"""Update the current Beolink leader, listeners, peers and self."""
"""Update the current Beolink leader, listeners, peers and self.

Updates Home Assistant state.
"""

self._beolink_attributes = {}

Expand All @@ -444,18 +449,24 @@ async def _async_update_beolink(self) -> None:

# Add Beolink self
self._beolink_attributes = {
"beolink": {"self": {self.device_entry.name: self._beolink_jid}}
BangOlufsenAttribute.BEOLINK: {
BangOlufsenAttribute.BEOLINK_SELF: {
self.device_entry.name: self._beolink_jid
}
}
}

# Add Beolink peers
peers = await self._client.get_beolink_peers()

if len(peers) > 0:
self._beolink_attributes["beolink"]["peers"] = {}
self._beolink_attributes[BangOlufsenAttribute.BEOLINK][
BangOlufsenAttribute.BEOLINK_PEERS
] = {}
for peer in peers:
self._beolink_attributes["beolink"]["peers"][peer.friendly_name] = (
peer.jid
)
self._beolink_attributes[BangOlufsenAttribute.BEOLINK][
BangOlufsenAttribute.BEOLINK_PEERS
][peer.friendly_name] = peer.jid

# Add Beolink listeners / leader
self._remote_leader = self._playback_metadata.remote_leader
Expand All @@ -476,7 +487,9 @@ async def _async_update_beolink(self) -> None:
# Add self
group_members.append(self.entity_id)

self._beolink_attributes["beolink"]["leader"] = {
self._beolink_attributes[BangOlufsenAttribute.BEOLINK][
BangOlufsenAttribute.BEOLINK_LEADER
] = {
self._remote_leader.friendly_name: self._remote_leader.jid,
}

Expand Down Expand Up @@ -513,9 +526,9 @@ async def _async_update_beolink(self) -> None:
beolink_listener.jid
)
break
self._beolink_attributes["beolink"]["listeners"] = (
beolink_listeners_attribute
)
self._beolink_attributes[BangOlufsenAttribute.BEOLINK][
BangOlufsenAttribute.BEOLINK_LISTENERS
] = beolink_listeners_attribute

self._attr_group_members = group_members

Expand Down Expand Up @@ -614,11 +627,18 @@ def is_volume_muted(self) -> bool | None:
return None

@property
def media_content_type(self) -> str:
def media_content_type(self) -> MediaType | str | None:
"""Return the current media type."""
# Hard to determine content type
if self._source_change.id == BangOlufsenSource.URI_STREAMER.id:
return MediaType.URL
content_type = {
BangOlufsenSource.URI_STREAMER.id: MediaType.URL,
BangOlufsenSource.DEEZER.id: BangOlufsenMediaType.DEEZER,
BangOlufsenSource.TIDAL.id: BangOlufsenMediaType.TIDAL,
BangOlufsenSource.NET_RADIO.id: BangOlufsenMediaType.RADIO,
}
# Hard to determine content type.
if self._source_change.id in content_type:
return content_type[self._source_change.id]

return MediaType.MUSIC

@property
Expand All @@ -631,6 +651,11 @@ def media_position(self) -> int | None:
"""Return the current playback progress."""
return self._playback_progress.progress

@property
def media_content_id(self) -> str | None:
"""Return internal ID of Deezer, Tidal and radio stations."""
return self._playback_metadata.source_internal_id

@property
def media_image_url(self) -> str | None:
"""Return URL of the currently playing music."""
Expand Down
1 change: 1 addition & 0 deletions tests/components/bang_olufsen/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
title="Test title",
total_duration_seconds=123,
track=1,
source_internal_id="123",
)
TEST_PLAYBACK_ERROR = PlaybackError(error="Test error")
TEST_PLAYBACK_PROGRESS = PlaybackProgress(progress=123)
Expand Down
Loading
Loading