Add conversation_id parameter to conversation.process service (#106078)

* Add conversation_id parameter to conversation.process service

* fix test

* fix tests
This commit is contained in:
Denis Shulyaka 2024-01-04 23:46:06 +03:00 committed by GitHub
parent 34e6fa3328
commit 99bcc38284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 139 additions and 6 deletions

View File

@ -42,6 +42,7 @@ _LOGGER = logging.getLogger(__name__)
ATTR_TEXT = "text"
ATTR_LANGUAGE = "language"
ATTR_AGENT_ID = "agent_id"
ATTR_CONVERSATION_ID = "conversation_id"
DOMAIN = "conversation"
@ -66,6 +67,7 @@ SERVICE_PROCESS_SCHEMA = vol.Schema(
vol.Required(ATTR_TEXT): cv.string,
vol.Optional(ATTR_LANGUAGE): cv.string,
vol.Optional(ATTR_AGENT_ID): agent_id_validator,
vol.Optional(ATTR_CONVERSATION_ID): cv.string,
}
)
@ -164,7 +166,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
result = await async_converse(
hass=hass,
text=text,
conversation_id=None,
conversation_id=service.data.get(ATTR_CONVERSATION_ID),
context=service.context,
language=service.data.get(ATTR_LANGUAGE),
agent_id=service.data.get(ATTR_AGENT_ID),

View File

@ -14,6 +14,10 @@ process:
example: homeassistant
selector:
conversation_agent:
conversation_id:
example: my_conversation_1
selector:
text:
reload:
fields:

View File

@ -16,6 +16,10 @@
"agent_id": {
"name": "Agent",
"description": "Conversation agent to process your request. The conversation agent is the brains of your assistant. It processes the incoming text commands."
},
"conversation_id": {
"name": "Conversation ID",
"description": "ID of the conversation, to be able to continue a previous conversation"
}
}
},

View File

@ -225,7 +225,7 @@
]),
})
# ---
# name: test_turn_on_intent[turn kitchen on-None]
# name: test_turn_on_intent[None-turn kitchen on-None]
dict({
'conversation_id': None,
'response': dict({
@ -255,7 +255,7 @@
}),
})
# ---
# name: test_turn_on_intent[turn kitchen on-homeassistant]
# name: test_turn_on_intent[None-turn kitchen on-homeassistant]
dict({
'conversation_id': None,
'response': dict({
@ -285,7 +285,7 @@
}),
})
# ---
# name: test_turn_on_intent[turn on kitchen-None]
# name: test_turn_on_intent[None-turn on kitchen-None]
dict({
'conversation_id': None,
'response': dict({
@ -315,7 +315,127 @@
}),
})
# ---
# name: test_turn_on_intent[turn on kitchen-homeassistant]
# name: test_turn_on_intent[None-turn on kitchen-homeassistant]
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'failed': list([
]),
'success': list([
dict({
'id': 'light.kitchen',
'name': 'kitchen',
'type': <IntentResponseTargetType.ENTITY: 'entity'>,
}),
]),
'targets': list([
]),
}),
'language': 'en',
'response_type': 'action_done',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Turned on light',
}),
}),
}),
})
# ---
# name: test_turn_on_intent[my_new_conversation-turn kitchen on-None]
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'failed': list([
]),
'success': list([
dict({
'id': 'light.kitchen',
'name': 'kitchen',
'type': <IntentResponseTargetType.ENTITY: 'entity'>,
}),
]),
'targets': list([
]),
}),
'language': 'en',
'response_type': 'action_done',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Turned on light',
}),
}),
}),
})
# ---
# name: test_turn_on_intent[my_new_conversation-turn kitchen on-homeassistant]
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'failed': list([
]),
'success': list([
dict({
'id': 'light.kitchen',
'name': 'kitchen',
'type': <IntentResponseTargetType.ENTITY: 'entity'>,
}),
]),
'targets': list([
]),
}),
'language': 'en',
'response_type': 'action_done',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Turned on light',
}),
}),
}),
})
# ---
# name: test_turn_on_intent[my_new_conversation-turn on kitchen-None]
dict({
'conversation_id': None,
'response': dict({
'card': dict({
}),
'data': dict({
'failed': list([
]),
'success': list([
dict({
'id': 'light.kitchen',
'name': 'kitchen',
'type': <IntentResponseTargetType.ENTITY: 'entity'>,
}),
]),
'targets': list([
]),
}),
'language': 'en',
'response_type': 'action_done',
'speech': dict({
'plain': dict({
'extra_data': None,
'speech': 'Turned on light',
}),
}),
}),
})
# ---
# name: test_turn_on_intent[my_new_conversation-turn on kitchen-homeassistant]
dict({
'conversation_id': None,
'response': dict({

View File

@ -873,8 +873,9 @@ async def test_http_processing_intent_conversion_not_expose_new(
@pytest.mark.parametrize("agent_id", AGENT_ID_OPTIONS)
@pytest.mark.parametrize("sentence", ("turn on kitchen", "turn kitchen on"))
@pytest.mark.parametrize("conversation_id", ("my_new_conversation", None))
async def test_turn_on_intent(
hass: HomeAssistant, init_components, sentence, agent_id, snapshot
hass: HomeAssistant, init_components, conversation_id, sentence, agent_id, snapshot
) -> None:
"""Test calling the turn on intent."""
hass.states.async_set("light.kitchen", "off")
@ -883,6 +884,8 @@ async def test_turn_on_intent(
data = {conversation.ATTR_TEXT: sentence}
if agent_id is not None:
data[conversation.ATTR_AGENT_ID] = agent_id
if conversation_id is not None:
data[conversation.ATTR_CONVERSATION_ID] = conversation_id
result = await hass.services.async_call(
"conversation",
"process",