mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
39 lines
1021 B
Python
39 lines
1021 B
Python
"""Test the HTTP API for AI Task integration."""
|
|
|
|
from homeassistant.const import STATE_UNKNOWN
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .conftest import TEST_ENTITY_ID
|
|
|
|
from tests.typing import WebSocketGenerator
|
|
|
|
|
|
async def test_ws_generate_text(
|
|
hass: HomeAssistant,
|
|
hass_ws_client: WebSocketGenerator,
|
|
init_components: None,
|
|
) -> None:
|
|
"""Test running a generate text task via the WebSocket API."""
|
|
entity = hass.states.get(TEST_ENTITY_ID)
|
|
assert entity is not None
|
|
assert entity.state == STATE_UNKNOWN
|
|
|
|
client = await hass_ws_client(hass)
|
|
|
|
await client.send_json_auto_id(
|
|
{
|
|
"type": "ai_task/generate_text",
|
|
"task_name": "Test Task",
|
|
"entity_id": TEST_ENTITY_ID,
|
|
"instructions": "Test prompt",
|
|
}
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert msg["success"]
|
|
assert msg["result"]["result"] == "Mock result"
|
|
|
|
entity = hass.states.get(TEST_ENTITY_ID)
|
|
assert entity.state != STATE_UNKNOWN
|