diff --git a/custom_components/mass/config_flow.py b/custom_components/mass/config_flow.py index d6217974..dbd2f5d8 100644 --- a/custom_components/mass/config_flow.py +++ b/custom_components/mass/config_flow.py @@ -30,6 +30,7 @@ CONF_ASSIST_AUTO_EXPOSE_PLAYERS, CONF_INTEGRATION_CREATED_ADDON, CONF_OPENAI_AGENT_ID, + CONF_PRE_ANNOUNCE_TTS, CONF_USE_ADDON, DOMAIN, LOGGER, @@ -264,6 +265,9 @@ async def async_step_zeroconf( This flow is triggered by the Zeroconf component. It will check if the host is already configured and delegate to the import step if not. """ + # abort if discovery info is not what we expect + if "server_id" not in discovery_info.properties: + return None # abort if we already have exactly this server_id # reload the integration if the host got updated server_id = discovery_info.properties["server_id"] @@ -435,6 +439,10 @@ def mass_config_option_schema( else False ), ): bool, + vol.Optional( + CONF_PRE_ANNOUNCE_TTS, + default=True, + ): bool, } diff --git a/custom_components/mass/const.py b/custom_components/mass/const.py index 20f3d0e5..1372e6dc 100644 --- a/custom_components/mass/const.py +++ b/custom_components/mass/const.py @@ -26,5 +26,6 @@ CONF_USE_ADDON = "use_addon" CONF_OPENAI_AGENT_ID = "openai_agent_id" CONF_ASSIST_AUTO_EXPOSE_PLAYERS = "expose_players_assist" +CONF_PRE_ANNOUNCE_TTS = "pre_announce_tts" LOGGER = logging.getLogger(__package__) diff --git a/custom_components/mass/manifest.json b/custom_components/mass/manifest.json index 3dd7dc90..0b12e078 100644 --- a/custom_components/mass/manifest.json +++ b/custom_components/mass/manifest.json @@ -16,7 +16,7 @@ "music_assistant" ], "requirements": [ - "music-assistant==2.0.0b110" + "music-assistant==2.0.0b112" ], "version": "0.0.0", "zeroconf": [ diff --git a/custom_components/mass/media_player.py b/custom_components/mass/media_player.py index a451beaf..a8ab16d4 100644 --- a/custom_components/mass/media_player.py +++ b/custom_components/mass/media_player.py @@ -55,6 +55,7 @@ ATTR_QUEUE_INDEX, ATTR_QUEUE_ITEMS, ATTR_STREAM_TITLE, + CONF_PRE_ANNOUNCE_TTS, DOMAIN, ) from .entity import MassBaseEntity @@ -471,6 +472,16 @@ async def _async_play_media_advanced( ) -> None: """Send the play_media command to the media player.""" # pylint: disable=too-many-arguments + # announce/alert support + if announce: + conf_entry = self.hass.config_entries.async_get_entry( + self.registry_entry.config_entry_id + ) + use_pre_announce = conf_entry.options.get(CONF_PRE_ANNOUNCE_TTS, True) + await self.mass.players.play_announcement( + self.player_id, media_id[0], use_pre_announce + ) + return media_uris: list[str] = [] # work out (all) uri(s) to play for media_id_str in media_id: @@ -503,16 +514,6 @@ async def _async_play_media_advanced( else: queue_id = self.player_id - # announce/alert support (WIP) - if announce and radio_mode: - radio_mode = None - if announce is None and "/api/tts_proxy" in media_id: - announce = True - if announce: - raise NotImplementedError( - "Music Assistant does not yet support announcements" - ) - await self.mass.players.play_media( queue_id, media=media_uris, option=enqueue, radio_mode=radio_mode ) diff --git a/custom_components/mass/strings.json b/custom_components/mass/strings.json index 0a197ad1..beed0467 100644 --- a/custom_components/mass/strings.json +++ b/custom_components/mass/strings.json @@ -53,7 +53,7 @@ "error": { "cannot_connect": "Failed to connect", "unknown": "Unexpected error" - }, + }, "abort": { "addon_get_discovery_info_failed": "Failed to get Music Assistant Server add-on discovery info.", "addon_info_failed": "Failed to get Music Assistant Server add-on info.", @@ -64,7 +64,7 @@ "not_matter_addon": "Discovered add-on is not the official Music Assistant Server add-on.", "reconfiguration_successful": "Successfully reconfigured the Music Assistant integration.", "cannot_connect": "Failed to connect" - }, + }, "progress": { "install_addon": "Please wait while the Music Assistant Server add-on installation finishes. This can take several minutes.", "start_addon": "Please wait while the Music Assistant Server add-on starts. This add-on is what powers Music Assistant in Home Assistant. This may take some seconds." @@ -150,7 +150,8 @@ "data": { "url": "URL of the Music Assistant server", "use_addon": "Use the official Music Assistant Server add-on", - "expose_players_assist": "Expose players to Assist" + "expose_players_assist": "Expose players to Assist", + "pre_announce_tts": "Prepend notification sound to TTS announcements" } } } diff --git a/custom_components/mass/translations/en.json b/custom_components/mass/translations/en.json index 685a7c0e..8a0228aa 100644 --- a/custom_components/mass/translations/en.json +++ b/custom_components/mass/translations/en.json @@ -53,7 +53,7 @@ "error": { "cannot_connect": "Failed to connect", "unknown": "Unexpected error" - }, + }, "abort": { "addon_get_discovery_info_failed": "Failed to get Music Assistant Server add-on discovery info.", "addon_info_failed": "Failed to get Music Assistant Server add-on info.", @@ -64,7 +64,7 @@ "not_matter_addon": "Discovered add-on is not the official Music Assistant Server add-on.", "reconfiguration_successful": "Successfully reconfigured the Music Assistant integration.", "cannot_connect": "Failed to connect" - }, + }, "progress": { "install_addon": "Please wait while the Music Assistant Server add-on installation finishes. This can take several minutes.", "start_addon": "Please wait while the Music Assistant Server add-on starts. This add-on is what powers Music Assistant in Home Assistant. This may take some seconds." @@ -150,7 +150,8 @@ "data": { "url": "URL of the Music Assistant server", "use_addon": "Use the official Music Assistant Server add-on", - "expose_players_assist": "Expose players to Assist" + "expose_players_assist": "Expose players to Assist", + "pre_announce_tts": "Prepend notification sound to TTS announcements" } } } diff --git a/pyproject.toml b/pyproject.toml index 58295534..d479b8bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ classifiers = [ dependencies = [ "async_timeout~=4.0.3", "homeassistant~=2024.3.1", - "music-assistant~=2.0.0b93", + "music-assistant~=2.0.0b112", ] description = "Music Assistant (BETA) Home Assistant Integration" license = {text = "Apache-2.0"} @@ -31,7 +31,7 @@ test = [ "safety==3.0.1", "tomli==2.0.1", "pytest-homeassistant-custom-component==0.13.108", - "zeroconf" + "zeroconf", ] [tool.codespell]