Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Paulus Schoutsen
0f784f93d9 Mobile app to use Assist Pipeline 2023-06-25 22:57:02 -04:00
3 changed files with 47 additions and 17 deletions

View file

@ -4,7 +4,14 @@
"after_dependencies": ["cloud", "camera", "conversation", "notify"],
"codeowners": ["@home-assistant/core"],
"config_flow": true,
"dependencies": ["http", "webhook", "person", "tag", "websocket_api"],
"dependencies": [
"assist_pipeline",
"http",
"person",
"tag",
"webhook",
"websocket_api"
],
"documentation": "https://www.home-assistant.io/integrations/mobile_app",
"iot_class": "local_push",
"loggers": ["nacl"],

View file

@ -16,9 +16,9 @@ from nacl.secret import SecretBox
import voluptuous as vol
from homeassistant.components import (
assist_pipeline,
camera,
cloud,
conversation,
notify as hass_notify,
tag,
)
@ -317,7 +317,7 @@ async def webhook_fire_event(
@validate_schema(
{
vol.Required("text"): cv.string,
vol.Optional("language"): cv.string,
vol.Optional("pipeline_id"): cv.string,
vol.Optional("conversation_id"): cv.string,
}
)
@ -325,14 +325,33 @@ async def webhook_conversation_process(
hass: HomeAssistant, config_entry: ConfigEntry, data: dict[str, Any]
) -> Response:
"""Handle a conversation process webhook."""
result = await conversation.async_converse(
hass,
text=data["text"],
language=data.get("language"),
conversation_id=data.get("conversation_id"),
result: dict | None = None
def event_callback(event: assist_pipeline.PipelineEvent) -> None:
"""Handle assist event."""
nonlocal result
if event.type == assist_pipeline.PipelineEventType.INTENT_END:
assert event.data is not None
result = event.data["intent_output"]
await assist_pipeline.async_pipeline_from_text(
hass=hass,
context=registration_context(config_entry.data),
event_callback=event_callback,
intent_input=data["text"],
conversation_id=data.get("conversation_id"),
device_id=config_entry.data[ATTR_DEVICE_ID],
pipeline_id=data.get("pipeline_id"),
)
return webhook_response(result.as_dict(), registration=config_entry.data)
if result is None:
return webhook_response(
{"success": False},
registration=config_entry.data,
status=HTTPStatus.INTERNAL_SERVER_ERROR,
)
return webhook_response(result, registration=config_entry.data)
@WEBHOOK_COMMANDS.register("stream_camera")

View file

@ -1026,6 +1026,10 @@ async def test_webhook_handle_conversation_process(
"""Test that we can converse."""
webhook_client.server.app.router._frozen = False
with patch(
"homeassistant.components.conversation.AgentManager.async_get_agent",
return_value=mock_agent,
):
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
json={