From 855b9991796943b1ba0f087e6d0305c8f2f1bd7f Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 20 Dec 2024 20:59:27 +0100 Subject: [PATCH] Fix: only send the bypass_proxy data to esphome players --- .../providers/hass_players/__init__.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/music_assistant/providers/hass_players/__init__.py b/music_assistant/providers/hass_players/__init__.py index eef68e2cc..2be6beeb2 100644 --- a/music_assistant/providers/hass_players/__init__.py +++ b/music_assistant/providers/hass_players/__init__.py @@ -255,6 +255,26 @@ async def play_media(self, player_id: str, media: PlayerMedia) -> None: """Handle PLAY MEDIA on given player.""" if self.mass.config.get_raw_player_config_value(player_id, CONF_ENFORCE_MP3, True): media.uri = media.uri.replace(".flac", ".mp3") + player = self.mass.players.get(player_id, True) + assert player + extra_data = { + # passing metadata to the player + # so far only supported by google cast, but maybe others can follow + "metadata": { + "title": media.title, + "artist": media.artist, + "metadataType": 3, + "album": media.album, + "albumName": media.album, + "images": [{"url": media.image_url}] if media.image_url else None, + "imageUrl": media.image_url, + }, + } + if player.extra_data.get("hass_domain") == "esphome": + # tell esphome mediaproxy to bypass the proxy, + # as MA already delivers an optimized stream + extra_data["bypass_proxy"] = True + await self.hass_prov.hass.call_service( domain="media_player", service="play_media", @@ -262,22 +282,7 @@ async def play_media(self, player_id: str, media: PlayerMedia) -> None: "media_content_id": media.uri, "media_content_type": "music", "enqueue": "replace", - "extra": { - # passing metadata to the player - # so far only supported by google cast, but maybe others can follow - "metadata": { - "title": media.title, - "artist": media.artist, - "metadataType": 3, - "album": media.album, - "albumName": media.album, - "images": [{"url": media.image_url}] if media.image_url else None, - "imageUrl": media.image_url, - }, - # tell esphome mediaproxy to bypass the proxy, - # as MA already delivers an optimized stream - "bypass_proxy": True, - }, + "extra": extra_data, }, target={"entity_id": player_id}, )