diff --git a/homeassistant/components/conversation/__init__.py b/homeassistant/components/conversation/__init__.py index 5009530dc31..46a060f99bf 100644 --- a/homeassistant/components/conversation/__init__.py +++ b/homeassistant/components/conversation/__init__.py @@ -18,10 +18,12 @@ from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from .agent import AbstractConversationAgent, ConversationInput, ConversationResult +from .const import HOME_ASSISTANT_AGENT from .default_agent import DefaultAgent __all__ = [ "DOMAIN", + "HOME_ASSISTANT_AGENT", "async_converse", "async_get_agent_info", "async_set_agent", @@ -333,8 +335,6 @@ async def async_converse( class AgentManager: """Class to manage conversation agents.""" - HOME_ASSISTANT_AGENT = "homeassistant" - default_agent: str = HOME_ASSISTANT_AGENT _builtin_agent: AbstractConversationAgent | None = None @@ -351,7 +351,7 @@ class AgentManager: if agent_id is None: agent_id = self.default_agent - if agent_id == AgentManager.HOME_ASSISTANT_AGENT: + if agent_id == HOME_ASSISTANT_AGENT: if self._builtin_agent is not None: return self._builtin_agent @@ -376,7 +376,7 @@ class AgentManager: """List all agents.""" agents: list[AgentInfo] = [ { - "id": AgentManager.HOME_ASSISTANT_AGENT, + "id": HOME_ASSISTANT_AGENT, "name": "Home Assistant", } ] @@ -401,18 +401,18 @@ class AgentManager: @core.callback def async_is_valid_agent_id(self, agent_id: str) -> bool: """Check if the agent id is valid.""" - return agent_id in self._agents or agent_id == AgentManager.HOME_ASSISTANT_AGENT + return agent_id in self._agents or agent_id == HOME_ASSISTANT_AGENT @core.callback def async_set_agent(self, agent_id: str, agent: AbstractConversationAgent) -> None: """Set the agent.""" self._agents[agent_id] = agent - if self.default_agent == AgentManager.HOME_ASSISTANT_AGENT: + if self.default_agent == HOME_ASSISTANT_AGENT: self.default_agent = agent_id @core.callback def async_unset_agent(self, agent_id: str) -> None: """Unset the agent.""" if self.default_agent == agent_id: - self.default_agent = AgentManager.HOME_ASSISTANT_AGENT + self.default_agent = HOME_ASSISTANT_AGENT self._agents.pop(agent_id, None) diff --git a/homeassistant/components/conversation/const.py b/homeassistant/components/conversation/const.py index 04bfa373061..7ba12ec830d 100644 --- a/homeassistant/components/conversation/const.py +++ b/homeassistant/components/conversation/const.py @@ -1,3 +1,4 @@ """Const for conversation integration.""" DOMAIN = "conversation" +HOME_ASSISTANT_AGENT = "homeassistant" diff --git a/homeassistant/components/voice_assistant/pipeline.py b/homeassistant/components/voice_assistant/pipeline.py index b30e3b07474..c2eff90530b 100644 --- a/homeassistant/components/voice_assistant/pipeline.py +++ b/homeassistant/components/voice_assistant/pipeline.py @@ -289,7 +289,10 @@ class PipelineRun: async def prepare_recognize_intent(self) -> None: """Prepare recognizing an intent.""" agent_info = conversation.async_get_agent_info( - self.hass, self.pipeline.conversation_engine + self.hass, + # If no conversation engine is set, use the Home Assistant agent + # (the conversation integration default is currently the last one set) + self.pipeline.conversation_engine or conversation.HOME_ASSISTANT_AGENT, ) if agent_info is None: diff --git a/tests/components/conversation/test_init.py b/tests/components/conversation/test_init.py index 03f581b9aff..a4d6ea6c915 100644 --- a/tests/components/conversation/test_init.py +++ b/tests/components/conversation/test_init.py @@ -25,7 +25,7 @@ from . import expose_entity, expose_new from tests.common import MockConfigEntry, MockUser, async_mock_service from tests.typing import ClientSessionGenerator, WebSocketGenerator -AGENT_ID_OPTIONS = [None, conversation.AgentManager.HOME_ASSISTANT_AGENT] +AGENT_ID_OPTIONS = [None, conversation.HOME_ASSISTANT_AGENT] class OrderBeerIntentHandler(intent.IntentHandler): @@ -1569,7 +1569,7 @@ async def test_agent_id_validator_invalid_agent(hass: HomeAssistant) -> None: with pytest.raises(vol.Invalid): conversation.agent_id_validator("invalid_agent") - conversation.agent_id_validator(conversation.AgentManager.HOME_ASSISTANT_AGENT) + conversation.agent_id_validator(conversation.HOME_ASSISTANT_AGENT) async def test_get_agent_list(