mirror of
https://github.com/home-assistant/core.git
synced 2025-11-15 05:50:13 +00:00
* Add AI Task integration * Remove GenTextTaskType * Add AI Task prefs * Add action to LLM task * Remove WS command * Rename result to text for GenTextTaskResult * Apply suggestions from code review Co-authored-by: Allen Porter <allen.porter@gmail.com> * Add supported feature for generate text * Update const.py Co-authored-by: HarvsG <11440490+HarvsG@users.noreply.github.com> * Update homeassistant/components/ai_task/services.yaml Co-authored-by: HarvsG <11440490+HarvsG@users.noreply.github.com> * Use WS API to set preferences * Simplify pref storage * Simplify pref test * Update homeassistant/components/ai_task/services.yaml Co-authored-by: Allen Porter <allen.porter@gmail.com> --------- Co-authored-by: Allen Porter <allen.porter@gmail.com> Co-authored-by: HarvsG <11440490+HarvsG@users.noreply.github.com>
85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
"""Test the HTTP API for AI Task integration."""
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.typing import WebSocketGenerator
|
|
|
|
|
|
async def test_ws_preferences(
|
|
hass: HomeAssistant,
|
|
hass_ws_client: WebSocketGenerator,
|
|
init_components: None,
|
|
) -> None:
|
|
"""Test preferences via the WebSocket API."""
|
|
client = await hass_ws_client(hass)
|
|
|
|
# Get initial preferences
|
|
await client.send_json_auto_id({"type": "ai_task/preferences/get"})
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": None,
|
|
}
|
|
|
|
# Set preferences
|
|
await client.send_json_auto_id(
|
|
{
|
|
"type": "ai_task/preferences/set",
|
|
"gen_text_entity_id": "ai_task.summary_1",
|
|
}
|
|
)
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": "ai_task.summary_1",
|
|
}
|
|
|
|
# Get updated preferences
|
|
await client.send_json_auto_id({"type": "ai_task/preferences/get"})
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": "ai_task.summary_1",
|
|
}
|
|
|
|
# Update an existing preference
|
|
await client.send_json_auto_id(
|
|
{
|
|
"type": "ai_task/preferences/set",
|
|
"gen_text_entity_id": "ai_task.summary_2",
|
|
}
|
|
)
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": "ai_task.summary_2",
|
|
}
|
|
|
|
# Get updated preferences
|
|
await client.send_json_auto_id({"type": "ai_task/preferences/get"})
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": "ai_task.summary_2",
|
|
}
|
|
|
|
# No preferences set will preserve existing preferences
|
|
await client.send_json_auto_id(
|
|
{
|
|
"type": "ai_task/preferences/set",
|
|
}
|
|
)
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": "ai_task.summary_2",
|
|
}
|
|
|
|
# Get updated preferences
|
|
await client.send_json_auto_id({"type": "ai_task/preferences/get"})
|
|
msg = await client.receive_json()
|
|
assert msg["success"]
|
|
assert msg["result"] == {
|
|
"gen_text_entity_id": "ai_task.summary_2",
|
|
}
|