diff --git a/homeassistant/components/conversation/services.yaml b/homeassistant/components/conversation/services.yaml index 6b031ff7142f6f..8ac929e13b6d69 100644 --- a/homeassistant/components/conversation/services.yaml +++ b/homeassistant/components/conversation/services.yaml @@ -20,4 +20,4 @@ process: description: Assist engine to process your request example: homeassistant selector: - text: + conversation_agent: diff --git a/homeassistant/helpers/selector.py b/homeassistant/helpers/selector.py index afd38bf763695f..84c0f769c7cec8 100644 --- a/homeassistant/helpers/selector.py +++ b/homeassistant/helpers/selector.py @@ -500,6 +500,34 @@ def __call__(self, data: Any) -> Any: return self.config["value"] +class ConversationAgentSelectorConfig(TypedDict, total=False): + """Class to represent a conversation agent selector config.""" + + language: str + + +@SELECTORS.register("conversation_agent") +class COnversationAgentSelector(Selector[ConversationAgentSelectorConfig]): + """Selector for a conversation agent.""" + + selector_type = "conversation_agent" + + CONFIG_SCHEMA = vol.Schema( + { + vol.Optional("language"): str, + } + ) + + def __init__(self, config: ConversationAgentSelectorConfig) -> None: + """Instantiate a selector.""" + super().__init__(config) + + def __call__(self, data: Any) -> str: + """Validate the passed selection.""" + agent: str = vol.Schema(str)(data) + return agent + + class DateSelectorConfig(TypedDict): """Class to represent a date selector config.""" diff --git a/tests/helpers/test_selector.py b/tests/helpers/test_selector.py index f95da5c6e66e84..c518ad227a76f9 100644 --- a/tests/helpers/test_selector.py +++ b/tests/helpers/test_selector.py @@ -979,3 +979,25 @@ def test_constant_selector_schema_error(schema) -> None: """Test constant selector.""" with pytest.raises(vol.Invalid): selector.validate_selector({"constant": schema}) + + +@pytest.mark.parametrize( + ("schema", "valid_selections", "invalid_selections"), + ( + ( + {}, + ("home_assistant", "2j4hp3uy4p87wyrpiuhk34"), + (None, True, 1), + ), + ( + {"language": "nl"}, + ("home_assistant", "2j4hp3uy4p87wyrpiuhk34"), + (None, True, 1), + ), + ), +) +def test_conversation_agent_selector_schema( + schema, valid_selections, invalid_selections +) -> None: + """Test conversation agent selector.""" + _test_selector("conversation_agent", schema, valid_selections, invalid_selections)