Skip to content

Commit

Permalink
Add Tidal play_media support to Bang & Olufsen (home-assistant#119838)
Browse files Browse the repository at this point in the history
Add tidal play_media support
  • Loading branch information
mj23000 authored Jun 18, 2024
1 parent 041746a commit 3046329
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions homeassistant/components/bang_olufsen/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BangOlufsenMediaType(StrEnum):
FAVOURITE = "favourite"
DEEZER = "deezer"
RADIO = "radio"
TIDAL = "tidal"
TTS = "provider"
OVERLAY_TTS = "overlay_tts"

Expand Down Expand Up @@ -118,6 +119,7 @@ class WebsocketNotification(StrEnum):
BangOlufsenMediaType.DEEZER,
BangOlufsenMediaType.RADIO,
BangOlufsenMediaType.TTS,
BangOlufsenMediaType.TIDAL,
BangOlufsenMediaType.OVERLAY_TTS,
MediaType.MUSIC,
MediaType.URL,
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/bang_olufsen/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,39 +638,39 @@ async def async_play_media(
elif media_type == BangOlufsenMediaType.FAVOURITE:
await self._client.activate_preset(id=int(media_id))

elif media_type == BangOlufsenMediaType.DEEZER:
elif media_type in (BangOlufsenMediaType.DEEZER, BangOlufsenMediaType.TIDAL):
try:
if media_id == "flow":
# Play Deezer flow.
if media_id == "flow" and media_type == BangOlufsenMediaType.DEEZER:
deezer_id = None

if "id" in kwargs[ATTR_MEDIA_EXTRA]:
deezer_id = kwargs[ATTR_MEDIA_EXTRA]["id"]

# Play Deezer flow.
await self._client.start_deezer_flow(
user_flow=UserFlow(user_id=deezer_id)
)

# Play a Deezer playlist or album.
# Play a playlist or album.
elif any(match in media_id for match in ("playlist", "album")):
start_from = 0
if "start_from" in kwargs[ATTR_MEDIA_EXTRA]:
start_from = kwargs[ATTR_MEDIA_EXTRA]["start_from"]

await self._client.add_to_queue(
play_queue_item=PlayQueueItem(
provider=PlayQueueItemType(value="deezer"),
provider=PlayQueueItemType(value=media_type),
start_now_from_position=start_from,
type="playlist",
uri=media_id,
)
)

# Play a Deezer track.
# Play a track.
else:
await self._client.add_to_queue(
play_queue_item=PlayQueueItem(
provider=PlayQueueItemType(value="deezer"),
provider=PlayQueueItemType(value=media_type),
start_now_from_position=0,
type="track",
uri=media_id,
Expand Down

0 comments on commit 3046329

Please sign in to comment.