Skip to content

Commit

Permalink
Add radio mode to sentences
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefKruszynski committed Nov 9, 2024
1 parent f38d344 commit c30fd47
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
14 changes: 9 additions & 5 deletions custom_components/mass/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
ALBUM_SLOT = "album"
RADIO_SLOT = "radio"
PLAYLIST_SLOT = "playlist"
DONT_STOP_SLOT = "dont_stop"
RADIO_MODE_SLOT = "radio_mode"
SLOT_VALUE = "value"


Expand Down Expand Up @@ -140,8 +140,7 @@ def __init__(self, hass: HomeAssistant) -> None:
vol.Optional(ALBUM_SLOT): cv.string,
vol.Optional(RADIO_SLOT): cv.string,
vol.Optional(PLAYLIST_SLOT): cv.string,
# TODO: Implement dont_stopß
# vol.Optional(DONT_STOP_SLOT): cv.boolean,
vol.Optional(RADIO_MODE_SLOT): cv.string,
}

async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
Expand All @@ -159,9 +158,10 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
album = slots.get(ALBUM_SLOT, {}).get(SLOT_VALUE, "")
radio = slots.get(RADIO_SLOT, {}).get(SLOT_VALUE, "")
playlist = slots.get(PLAYLIST_SLOT, {}).get(SLOT_VALUE, "")
# TODO: Implement dont_stop
# dont_stop = slots.get(DONT_STOP_SLOT, {}).get(SLOT_VALUE, False)
radio_mode_text = slots.get(RADIO_MODE_SLOT, {}).get(SLOT_VALUE, "")
radio_mode = False
if radio_mode_text:
radio_mode = True
if track:
media_item = await mass.music.get_item_by_name(
track, artist=artist, album=album, media_type=MediaType.TRACK
Expand Down Expand Up @@ -214,6 +214,7 @@ def __init__(self, hass: HomeAssistant) -> None:
slot_schema = {
vol.Any(NAME_SLOT, AREA_SLOT): cv.string,
vol.Optional(QUERY_SLOT): cv.string,
vol.Optional(RADIO_MODE_SLOT): cv.string,
}

async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
Expand All @@ -227,7 +228,10 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
mass = config_entry.runtime_data.mass
mass_player_id = await self._async_get_matched_mass_player(intent_obj, slots)
query = slots.get(QUERY_SLOT, {}).get(SLOT_VALUE)
radio_mode_text = slots.get(RADIO_MODE_SLOT, {}).get(SLOT_VALUE, "")
radio_mode = False
if radio_mode_text:
radio_mode = True
if query:
if not config_entry.data.get(CONF_OPENAI_AGENT_ID):
raise intent.IntentHandleError(
Expand Down
27 changes: 15 additions & 12 deletions custom_sentences/en/music_assistant_PlayMediaAssist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ intents:

# TARGET AN AREA
- sentences:
- "<play> <artist> {artist} in [the ]<area>"
- "<play> <album> {album} [by <artist> {artist}] in [the ]<area>"
- "<play> <track> {track} [by <artist> {artist}] in [the ]<area>"
- "<play> <playlist> {playlist} in [the ]<area>"
- "<play> <artist> {artist} in [the ]<area> [((with)|(using)) {radio_mode}]"
- "<play> <album> {album} [by <artist> {artist}] in [the ]<area> [((with)|(using)) {radio_mode}]"
- "<play> <track> {track} [by <artist> {artist}] in [the ]<area> [((with)|(using)) {radio_mode}]"
- "<play> <playlist> {playlist} in [the ]<area> [((with)|(using)) {radio_mode}]"
- "<play> <radio_station> {radio} in [the ]<area>"
expansion_rules:
play: "((play)|(listen to))"
Expand All @@ -20,10 +20,10 @@ intents:

# TARGET A NAME
- sentences:
- "<play> <artist> {artist} <on> [the ]{name} [<player_devices>]"
- "<play> <album> {album} [by <artist> {artist}] <on> [the ]{name} [<player_devices>]"
- "<play> <track> {track} [by <artist> {artist}] <on> [the ]{name} [<player_devices>]"
- "<play> <playlist> {playlist} <on> [the ]{name} [<player_devices>]"
- "<play> <artist> {artist} <on> [the ]{name} [<player_devices>] [((with)|(using)) {radio_mode}]"
- "<play> <album> {album} [by <artist> {artist}] <on> [the ]{name} [<player_devices>] [((with)|(using)) {radio_mode}]"
- "<play> <track> {track} [by <artist> {artist}] <on> [the ]{name} [<player_devices>] [((with)|(using)) {radio_mode}]"
- "<play> <playlist> {playlist} <on> [the ]{name} [<player_devices>] [((with)|(using)) {radio_mode}]"
- "<play> <radio_station> {radio} <on> [the ]{name} [<player_devices>]"
expansion_rules:
play: "((play)|(listen to))"
Expand All @@ -39,10 +39,10 @@ intents:

# CONTEXT AWARNESS
- sentences:
- "<play> <artist> {artist}"
- "<play> <album> {album} [by <artist> {artist}]"
- "<play> <track> {track} [by <artist> {artist}]"
- "<play> <playlist> {playlist}"
- "<play> <artist> {artist} [((with)|(using)) {radio_mode}]"
- "<play> <album> {album} [by <artist> {artist}] [((with)|(using)) {radio_mode}]"
- "<play> <track> {track} [by <artist> {artist}] [((with)|(using)) {radio_mode}]"
- "<play> <playlist> {playlist} [((with)|(using)) {radio_mode}]"
- "<play> <radio_station> {radio}"
expansion_rules:
play: "((play)|(listen to))"
Expand All @@ -65,3 +65,6 @@ lists:
wildcard: true
radio:
wildcard: true
radio_mode:
values:
- "radio mode"
7 changes: 5 additions & 2 deletions custom_sentences/en/play_media_on_media_player.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ intents:
MassPlayMediaOnMediaPlayer:
data:
- sentences:
- "<play> {query};in [the ]<area>"
- "<play> {query};in [the ]<area> [((with)|(using)) {radio_mode}]"
expansion_rules:
play: "((play)|(listen to))"
player_devices: "((speaker)|([media] player))"
"on": "(on|using)"
- sentences:
- "<play> {query};<on> [the ]{name} [<player_devices>]"
- "<play> {query};<on> [the ]{name} [<player_devices>] [((with)|(using)) {radio_mode}]"
expansion_rules:
play: "((play)|(listen to))"
player_devices: "((speaker)|([media] player))"
Expand All @@ -19,3 +19,6 @@ intents:
lists:
query:
wildcard: true
radio_mode:
values:
- "radio mode"

0 comments on commit c30fd47

Please sign in to comment.