From 516c2b0cdb590f551dbd24d8a1990ced29520c57 Mon Sep 17 00:00:00 2001 From: tronikos Date: Sat, 31 Dec 2022 12:07:31 -0800 Subject: [PATCH] Google Assistant SDK: Log command and response (#84904) Log command and response --- homeassistant/components/google_assistant_sdk/helpers.py | 7 ++++++- .../components/google_assistant_sdk/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/google_assistant_sdk/test_notify.py | 9 ++++++--- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/google_assistant_sdk/helpers.py b/homeassistant/components/google_assistant_sdk/helpers.py index f91f8f4241f..15e325f10c1 100644 --- a/homeassistant/components/google_assistant_sdk/helpers.py +++ b/homeassistant/components/google_assistant_sdk/helpers.py @@ -1,6 +1,8 @@ """Helper classes for Google Assistant SDK integration.""" from __future__ import annotations +import logging + import aiohttp from gassist_text import TextAssistant from google.oauth2.credentials import Credentials @@ -12,6 +14,8 @@ from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session from .const import CONF_LANGUAGE_CODE, DOMAIN, SUPPORTED_LANGUAGE_CODES +_LOGGER = logging.getLogger(__name__) + DEFAULT_LANGUAGE_CODES = { "de": "de-DE", "en": "en-US", @@ -39,7 +43,8 @@ async def async_send_text_commands(commands: list[str], hass: HomeAssistant) -> language_code = entry.options.get(CONF_LANGUAGE_CODE, default_language_code(hass)) with TextAssistant(credentials, language_code) as assistant: for command in commands: - assistant.assist(command) + text_response = assistant.assist(command)[0] + _LOGGER.debug("command: %s\nresponse: %s", command, text_response) def default_language_code(hass: HomeAssistant): diff --git a/homeassistant/components/google_assistant_sdk/manifest.json b/homeassistant/components/google_assistant_sdk/manifest.json index 2f16d0deef3..e1b390f9496 100644 --- a/homeassistant/components/google_assistant_sdk/manifest.json +++ b/homeassistant/components/google_assistant_sdk/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "dependencies": ["application_credentials"], "documentation": "https://www.home-assistant.io/integrations/google_assistant_sdk/", - "requirements": ["gassist-text==0.0.5"], + "requirements": ["gassist-text==0.0.7"], "codeowners": ["@tronikos"], "iot_class": "cloud_polling", "integration_type": "service" diff --git a/requirements_all.txt b/requirements_all.txt index 756240346cc..f4810489bc5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -741,7 +741,7 @@ fritzconnection==1.10.3 gTTS==2.2.4 # homeassistant.components.google_assistant_sdk -gassist-text==0.0.5 +gassist-text==0.0.7 # homeassistant.components.google gcal-sync==4.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 2e1dafe0009..606a9546f3e 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -557,7 +557,7 @@ fritzconnection==1.10.3 gTTS==2.2.4 # homeassistant.components.google_assistant_sdk -gassist-text==0.0.5 +gassist-text==0.0.7 # homeassistant.components.google gcal-sync==4.1.0 diff --git a/tests/components/google_assistant_sdk/test_notify.py b/tests/components/google_assistant_sdk/test_notify.py index 5dbaa3aa79b..5a2d11b861b 100644 --- a/tests/components/google_assistant_sdk/test_notify.py +++ b/tests/components/google_assistant_sdk/test_notify.py @@ -41,7 +41,8 @@ async def test_broadcast_one_target( target = "basement" expected_command = "broadcast to basement time for dinner" with patch( - "homeassistant.components.google_assistant_sdk.helpers.TextAssistant.assist" + "homeassistant.components.google_assistant_sdk.helpers.TextAssistant.assist", + return_value=["text_response", None], ) as mock_assist_call: await hass.services.async_call( notify.DOMAIN, @@ -64,7 +65,8 @@ async def test_broadcast_two_targets( expected_command1 = "broadcast to basement time for dinner" expected_command2 = "broadcast to master bedroom time for dinner" with patch( - "homeassistant.components.google_assistant_sdk.helpers.TextAssistant.assist" + "homeassistant.components.google_assistant_sdk.helpers.TextAssistant.assist", + return_value=["text_response", None], ) as mock_assist_call: await hass.services.async_call( notify.DOMAIN, @@ -84,7 +86,8 @@ async def test_broadcast_empty_message( await setup_integration() with patch( - "homeassistant.components.google_assistant_sdk.helpers.TextAssistant.assist" + "homeassistant.components.google_assistant_sdk.helpers.TextAssistant.assist", + return_value=["text_response", None], ) as mock_assist_call: await hass.services.async_call( notify.DOMAIN,