mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Google Assistant SDK: Allow multiple commands in the same conversation context (#85423)
* Allow multiple commands in the same conversation * fix test * Apply suggestions from code review Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Add missing cv import * Update service description * Fix test after merging dev Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
0d3bf0e911
commit
949c88930f
@ -38,7 +38,7 @@ SERVICE_SEND_TEXT_COMMAND_FIELD_MEDIA_PLAYER = "media_player"
|
|||||||
SERVICE_SEND_TEXT_COMMAND_SCHEMA = vol.All(
|
SERVICE_SEND_TEXT_COMMAND_SCHEMA = vol.All(
|
||||||
{
|
{
|
||||||
vol.Required(SERVICE_SEND_TEXT_COMMAND_FIELD_COMMAND): vol.All(
|
vol.Required(SERVICE_SEND_TEXT_COMMAND_FIELD_COMMAND): vol.All(
|
||||||
str, vol.Length(min=1)
|
cv.ensure_list, [vol.All(str, vol.Length(min=1))]
|
||||||
),
|
),
|
||||||
vol.Optional(SERVICE_SEND_TEXT_COMMAND_FIELD_MEDIA_PLAYER): cv.comp_entity_ids,
|
vol.Optional(SERVICE_SEND_TEXT_COMMAND_FIELD_MEDIA_PLAYER): cv.comp_entity_ids,
|
||||||
},
|
},
|
||||||
@ -106,11 +106,11 @@ async def async_setup_service(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def send_text_command(call: ServiceCall) -> None:
|
async def send_text_command(call: ServiceCall) -> None:
|
||||||
"""Send a text command to Google Assistant SDK."""
|
"""Send a text command to Google Assistant SDK."""
|
||||||
command: str = call.data[SERVICE_SEND_TEXT_COMMAND_FIELD_COMMAND]
|
commands: list[str] = call.data[SERVICE_SEND_TEXT_COMMAND_FIELD_COMMAND]
|
||||||
media_players: list[str] | None = call.data.get(
|
media_players: list[str] | None = call.data.get(
|
||||||
SERVICE_SEND_TEXT_COMMAND_FIELD_MEDIA_PLAYER
|
SERVICE_SEND_TEXT_COMMAND_FIELD_MEDIA_PLAYER
|
||||||
)
|
)
|
||||||
await async_send_text_commands(hass, [command], media_players)
|
await async_send_text_commands(hass, commands, media_players)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -4,7 +4,7 @@ send_text_command:
|
|||||||
fields:
|
fields:
|
||||||
command:
|
command:
|
||||||
name: Command
|
name: Command
|
||||||
description: Command to send to Google Assistant.
|
description: Command(s) to send to Google Assistant.
|
||||||
example: turn off kitchen TV
|
example: turn off kitchen TV
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
@ -145,6 +145,35 @@ async def test_send_text_command(
|
|||||||
mock_text_assistant.assert_has_calls([call().__enter__().assist(command)])
|
mock_text_assistant.assert_has_calls([call().__enter__().assist(command)])
|
||||||
|
|
||||||
|
|
||||||
|
async def test_send_text_commands(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
setup_integration: ComponentSetup,
|
||||||
|
) -> None:
|
||||||
|
"""Test service call send_text_command calls TextAssistant."""
|
||||||
|
await setup_integration()
|
||||||
|
|
||||||
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
|
assert len(entries) == 1
|
||||||
|
assert entries[0].state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
command1 = "open the garage door"
|
||||||
|
command2 = "1234"
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.google_assistant_sdk.helpers.TextAssistant"
|
||||||
|
) as mock_text_assistant:
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
"send_text_command",
|
||||||
|
{"command": [command1, command2]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
mock_text_assistant.assert_called_once_with(
|
||||||
|
ExpectedCredentials(), "en-US", audio_out=False
|
||||||
|
)
|
||||||
|
mock_text_assistant.assert_has_calls([call().__enter__().assist(command1)])
|
||||||
|
mock_text_assistant.assert_has_calls([call().__enter__().assist(command2)])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"status,requires_reauth",
|
"status,requires_reauth",
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user