diff --git a/tests/components/conversation/__init__.py b/tests/components/conversation/__init__.py index db233be04cf..7fb4468277b 100644 --- a/tests/components/conversation/__init__.py +++ b/tests/components/conversation/__init__.py @@ -18,6 +18,11 @@ class MockAgent(conversation.AbstractConversationAgent): self.calls = [] self.response = "Test response" + @property + def attribution(self) -> conversation.Attribution | None: + """Return the attribution.""" + return {"name": "Mock assistant", "url": "https://assist.me"} + @property def supported_languages(self) -> list[str]: """Return a list of supported languages.""" diff --git a/tests/components/conversation/snapshots/test_init.ambr b/tests/components/conversation/snapshots/test_init.ambr index 12e70058ea6..116e7da203e 100644 --- a/tests/components/conversation/snapshots/test_init.ambr +++ b/tests/components/conversation/snapshots/test_init.ambr @@ -79,3 +79,30 @@ ]), }) # --- +# name: test_ws_get_agent_info + dict({ + 'attribution': dict({ + 'name': 'Mock assistant', + 'url': 'https://assist.me', + }), + }) +# --- +# name: test_ws_get_agent_info.1 + dict({ + 'attribution': None, + }) +# --- +# name: test_ws_get_agent_info.2 + dict({ + 'attribution': dict({ + 'name': 'Mock assistant', + 'url': 'https://assist.me', + }), + }) +# --- +# name: test_ws_get_agent_info.3 + dict({ + 'code': 'invalid_format', + 'message': "invalid agent ID for dictionary value @ data['agent_id']. Got 'not_exist'", + }) +# --- diff --git a/tests/components/conversation/test_init.py b/tests/components/conversation/test_init.py index 82dcd66231c..88a7c53786b 100644 --- a/tests/components/conversation/test_init.py +++ b/tests/components/conversation/test_init.py @@ -1624,3 +1624,40 @@ async def test_get_agent_info( assert conversation.async_get_agent_info(hass, "homeassistant") == snapshot assert conversation.async_get_agent_info(hass, mock_agent.agent_id) == snapshot assert conversation.async_get_agent_info(hass, "not exist") is None + + +async def test_ws_get_agent_info( + hass: HomeAssistant, + init_components, + mock_agent, + hass_ws_client: WebSocketGenerator, + snapshot: SnapshotAssertion, +) -> None: + """Test get agent info.""" + client = await hass_ws_client(hass) + + await client.send_json_auto_id({"type": "conversation/agent/info"}) + msg = await client.receive_json() + assert msg["success"] + assert msg["result"] == snapshot + + await client.send_json_auto_id( + {"type": "conversation/agent/info", "agent_id": "homeassistant"} + ) + msg = await client.receive_json() + assert msg["success"] + assert msg["result"] == snapshot + + await client.send_json_auto_id( + {"type": "conversation/agent/info", "agent_id": mock_agent.agent_id} + ) + msg = await client.receive_json() + assert msg["success"] + assert msg["result"] == snapshot + + await client.send_json_auto_id( + {"type": "conversation/agent/info", "agent_id": "not_exist"} + ) + msg = await client.receive_json() + assert not msg["success"] + assert msg["error"] == snapshot