Skip to content

Commit

Permalink
Adopt changes to server for announcements (#2070)
Browse files Browse the repository at this point in the history
adopt changes to server for announcements
  • Loading branch information
marcelveldt committed Mar 26, 2024
1 parent 158e16e commit f7327c6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
6 changes: 0 additions & 6 deletions custom_components/mass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
CONF_ASSIST_AUTO_EXPOSE_PLAYERS,
CONF_INTEGRATION_CREATED_ADDON,
CONF_OPENAI_AGENT_ID,
CONF_PRE_ANNOUNCE_TTS,
CONF_USE_ADDON,
DOMAIN,
LOGGER,
Expand Down Expand Up @@ -400,7 +399,6 @@ async def async_step_init(self, user_input=None) -> FlowResult:
CONF_ASSIST_AUTO_EXPOSE_PLAYERS: user_input[
CONF_ASSIST_AUTO_EXPOSE_PLAYERS
],
CONF_PRE_ANNOUNCE_TTS: user_input[CONF_PRE_ANNOUNCE_TTS],
},
)
await self.hass.config_entries.async_reload(self.config_entry.entry_id)
Expand Down Expand Up @@ -436,10 +434,6 @@ def mass_config_option_schema(
else False
),
): bool,
vol.Optional(
CONF_PRE_ANNOUNCE_TTS,
default=config_entry.data.get(CONF_PRE_ANNOUNCE_TTS, False),
): bool,
}


Expand Down
2 changes: 1 addition & 1 deletion custom_components/mass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"music_assistant"
],
"requirements": [
"music-assistant==2.0.0b112"
"music-assistant==2.0.0b125"
],
"version": "0.0.0",
"zeroconf": [
Expand Down
15 changes: 9 additions & 6 deletions custom_components/mass/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
ATTR_QUEUE_INDEX,
ATTR_QUEUE_ITEMS,
ATTR_STREAM_TITLE,
CONF_PRE_ANNOUNCE_TTS,
DOMAIN,
)
from .entity import MassBaseEntity
Expand Down Expand Up @@ -108,6 +107,8 @@
ATTR_MEDIA_TYPE = "media_type"
ATTR_ARTIST = "artist"
ATTR_ALBUM = "album"
ATTR_USE_PRE_ANNOUNCE = "use_pre_announce"
ATTR_ANNOUNCE_VOLUME = "announce_volume"

# pylint: disable=too-many-public-methods

Expand Down Expand Up @@ -151,6 +152,8 @@ async def handle_player_added(event: MassEvent) -> None:
vol.Optional(ATTR_ARTIST): cv.string,
vol.Optional(ATTR_ALBUM): cv.string,
vol.Optional(ATTR_RADIO_MODE): vol.Coerce(bool),
vol.Optional(ATTR_USE_PRE_ANNOUNCE): vol.Coerce(bool),
vol.Optional(ATTR_ANNOUNCE_VOLUME): vol.Coerce(int),
},
"_async_play_media_advanced",
)
Expand Down Expand Up @@ -437,6 +440,8 @@ async def async_play_media(
announce=announce,
media_type=media_type,
radio_mode=kwargs[ATTR_MEDIA_EXTRA].get(ATTR_RADIO_MODE),
use_pre_announce=kwargs[ATTR_MEDIA_EXTRA].get("use_pre_announce"),
announce_volume=kwargs[ATTR_MEDIA_EXTRA].get("announce_volume"),
)

async def async_join_players(self, group_members: list[str]) -> None:
Expand Down Expand Up @@ -469,17 +474,15 @@ async def _async_play_media_advanced(
announce: bool | None = None,
radio_mode: bool | None = None,
media_type: str | None = None,
use_pre_announce: bool | None = None,
announce_volume: int | None = None,
) -> 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.data.get(CONF_PRE_ANNOUNCE_TTS) is True
await self.mass.players.play_announcement(
self.player_id, media_id[0], use_pre_announce
self.player_id, media_id[0], use_pre_announce, announce_volume
)
return
media_uris: list[str] = []
Expand Down
20 changes: 19 additions & 1 deletion custom_components/mass/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ play_media:
example: "true"
selector:
boolean:
use_pre_announce:
filter:
supported_features:
- media_player.MediaPlayerEntityFeature.MEDIA_ANNOUNCE
required: false
example: "true"
selector:
boolean:
announce_volume:
filter:
supported_features:
- media_player.MediaPlayerEntityFeature.MEDIA_ANNOUNCE
required: false
example: 75
selector:
number:
min: 1
max: 100
step: 1
artist:
required: false
example: "Queen"
Expand All @@ -62,7 +81,6 @@ play_media:
selector:
boolean:


search:
fields:
name:
Expand Down
11 changes: 9 additions & 2 deletions custom_components/mass/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
"name": "Announce",
"description": "If the media should be played as an announcement."
},
"use_pre_announce": {
"name": "Use pre-announce",
"description": "Use pre-announcement sound for the announcement. Used with the announce option, omit to use player default."
},
"announce_volume": {
"name": "Announce volume",
"description": "Use a forced volume level for the announcement. Used with the announce option, omit to use player default."
},
"artist": {
"name": "Artist name",
"description": "When specifying a track or album by name in the Media ID field, you can optionally restrict results by this artist name."
Expand Down Expand Up @@ -150,8 +158,7 @@
"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",
"pre_announce_tts": "Prepend notification sound to TTS announcements"
"expose_players_assist": "Expose players to Assist"
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions custom_components/mass/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
"name": "Announce",
"description": "If the media should be played as an announcement."
},
"use_pre_announce": {
"name": "Use pre-announce",
"description": "Use pre-announcement sound for the announcement. Used with the announce option, omit to use player default."
},
"announce_volume": {
"name": "Announce volume",
"description": "Use a forced volume level for the announcement. Used with the announce option, omit to use player default."
},
"artist": {
"name": "Artist name",
"description": "When specifying a track or album by name in the Media ID field, you can optionally restrict results by this artist name."
Expand Down Expand Up @@ -150,8 +158,7 @@
"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",
"pre_announce_tts": "Prepend notification sound to TTS announcements"
"expose_players_assist": "Expose players to Assist"
}
}
}
Expand Down

0 comments on commit f7327c6

Please sign in to comment.