From 1b2e9ea6f5bcbf6198d6eb79536de545601abb57 Mon Sep 17 00:00:00 2001 From: Jozef Kruszynski Date: Wed, 27 Nov 2024 22:04:40 +0100 Subject: [PATCH] Fix issue with matching on none mass players --- custom_components/mass/intent.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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,