diff --git a/custom_components/mass/intent.py b/custom_components/mass/intent.py index a04be091..31c9c1aa 100644 --- a/custom_components/mass/intent.py +++ b/custom_components/mass/intent.py @@ -32,6 +32,7 @@ from . import DOMAIN from .const import ( + ATTR_MASS_PLAYER_TYPE, CONF_OPENAI_AGENT_ID, ATTR_MEDIA_ID, ATTR_MEDIA_TYPE, @@ -145,16 +146,19 @@ async def _get_media_items( async def _get_matched_state( self, intent_obj: intent.Intent, match_constraints: MatchTargetsConstraints ) -> State: - match_result = intent.async_match_targets( - intent_obj.hass, - match_constraints, - ) + match_result = intent.async_match_targets(intent_obj.hass, match_constraints) if not match_result.is_match: - raise MatchFailedError( - result=match_result, - constraints=match_constraints, - ) - return match_result.states[0] + raise MatchFailedError(result=match_result, constraints=match_constraints) + + potential_states = [ + state + for state in match_result.states + if state.attributes.get(ATTR_MASS_PLAYER_TYPE) + ] + + if not potential_states: + raise MatchFailedError(result=match_result, constraints=match_constraints) + return potential_states[0] slot_schema = { vol.Optional(NAME_SLOT): cv.string,