1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-14 23:28:42 +00:00

Add pre announce URL to Music Assistant (#161448)

This commit is contained in:
Artur Pragacz
2026-01-23 15:37:13 +01:00
committed by GitHub
parent 8983d06d05
commit 6b386bbc8f
6 changed files with 21 additions and 2 deletions

View File

@@ -51,6 +51,7 @@ ATTR_ALBUM = "album"
ATTR_URL = "url"
ATTR_USE_PRE_ANNOUNCE = "use_pre_announce"
ATTR_ANNOUNCE_VOLUME = "announce_volume"
ATTR_PRE_ANNOUNCE_URL = "pre_announce_url"
ATTR_SOURCE_PLAYER = "source_player"
ATTR_AUTO_PLAY = "auto_play"
ATTR_QUEUE_ID = "queue_id"

View File

@@ -356,6 +356,7 @@ class MusicAssistantPlayer(MusicAssistantEntity, MediaPlayerEntity):
await self._async_handle_play_announcement(
media_id,
use_pre_announce=kwargs[ATTR_MEDIA_EXTRA].get("use_pre_announce"),
pre_announce_url=kwargs[ATTR_MEDIA_EXTRA].get("pre_announce_url"),
announce_volume=kwargs[ATTR_MEDIA_EXTRA].get("announce_volume"),
)
return
@@ -464,11 +465,16 @@ class MusicAssistantPlayer(MusicAssistantEntity, MediaPlayerEntity):
self,
url: str,
use_pre_announce: bool | None = None,
pre_announce_url: str | None = None,
announce_volume: int | None = None,
) -> None:
"""Send the play_announcement command to the media player."""
await self.mass.players.play_announcement(
self.player_id, url, use_pre_announce, announce_volume
self.player_id,
url,
pre_announce=use_pre_announce,
pre_announce_url=pre_announce_url,
volume_level=announce_volume,
)
@catch_musicassistant_error

View File

@@ -42,6 +42,7 @@ from .const import (
ATTR_ORDER_BY,
ATTR_PLAYLISTS,
ATTR_PODCASTS,
ATTR_PRE_ANNOUNCE_URL,
ATTR_RADIO,
ATTR_RADIO_MODE,
ATTR_SEARCH,
@@ -150,6 +151,7 @@ def register_actions(hass: HomeAssistant) -> None:
schema={
vol.Required(ATTR_URL): cv.string,
vol.Optional(ATTR_USE_PRE_ANNOUNCE): vol.Coerce(bool),
vol.Optional(ATTR_PRE_ANNOUNCE_URL): cv.string,
vol.Optional(ATTR_ANNOUNCE_VOLUME): vol.Coerce(int),
},
func="_async_handle_play_announcement",

View File

@@ -68,6 +68,10 @@ play_announcement:
example: "true"
selector:
boolean:
pre_announce_url:
example: "http://someremotesite.com/chime.mp3"
selector:
text:
announce_volume:
example: 75
selector:

View File

@@ -169,6 +169,10 @@
"description": "Use a forced volume level for the announcement. Omit to use player default.",
"name": "Announce volume"
},
"pre_announce_url": {
"description": "URL to the pre-announcement sound.",
"name": "Pre-announce URL"
},
"url": {
"description": "URL to the notification sound.",
"name": "URL"

View File

@@ -37,6 +37,7 @@ from homeassistant.components.music_assistant.const import (
ATTR_AUTO_PLAY,
ATTR_MEDIA_ID,
ATTR_MEDIA_TYPE,
ATTR_PRE_ANNOUNCE_URL,
ATTR_RADIO_MODE,
ATTR_SOURCE_PLAYER,
ATTR_URL,
@@ -529,6 +530,7 @@ async def test_media_player_play_announcement_action(
ATTR_ENTITY_ID: entity_id,
ATTR_URL: "http://blah.com/announcement.mp3",
ATTR_USE_PRE_ANNOUNCE: True,
ATTR_PRE_ANNOUNCE_URL: "http://blah.com/chime.mp3",
ATTR_ANNOUNCE_VOLUME: 50,
},
blocking=True,
@@ -540,7 +542,7 @@ async def test_media_player_play_announcement_action(
url="http://blah.com/announcement.mp3",
pre_announce=True,
volume_level=50,
pre_announce_url=None,
pre_announce_url="http://blah.com/chime.mp3",
)