Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix intent after recent refactor #3136

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions custom_components/mass/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,36 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
return response
media_id = json_payload.get(ATTR_MEDIA_ID)
media_type = json_payload.get(ATTR_MEDIA_TYPE)
media_item = mass.music.get_item_by_name(
media_id, media_type=MediaType(media_type)
)
media_items = []
if isinstance(media_id, list):
media_items = [
(
await mass.music.get_item_by_name(
item, media_type=MediaType(media_type)
)
).to_dict()
for item in media_id
]
media_item = media_items
else:
media_item = await mass.music.get_item_by_name(
media_id, media_type=MediaType(media_type)
)
radio_mode = json_payload.get(ATTR_RADIO_MODE, False)
else:
artist = slots.get(ARTIST_SLOT, {}).get(SLOT_VALUE, "")
track = slots.get(TRACK_SLOT, {}).get(SLOT_VALUE, "")
album = slots.get(ALBUM_SLOT, {}).get(SLOT_VALUE, "")
if track:
media_item = mass.music.get_item_by_name(
media_item = await mass.music.get_item_by_name(
track, artist=artist, album=album, media_type=MediaType.TRACK
)
elif album:
media_item = mass.music.get_item_by_name(
media_item = await mass.music.get_item_by_name(
album, artist=artist, media_type=MediaType.ALBUM
)
elif artist:
media_item = mass.music.get_item_by_name(
media_item = await mass.music.get_item_by_name(
artist, artist=artist, album=album, media_type=MediaType.ARTIST
)
else:
Expand All @@ -120,7 +132,9 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
try:
await mass.player_queues.play_media(
queue_id=mass_player_id,
media=media_item,
media=(
media_item if isinstance(media_item, list) else media_item.to_dict()
),
radio_mode=radio_mode,
)
except MusicAssistantError as err:
Expand Down