From 6626e5c4a4ac8684329298ef28a83a2175f9aafa Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 25 Feb 2019 10:35:03 -0800 Subject: [PATCH] Handle GA Disconnect intent (#21387) * Handle GA Disconnect intent * Fixed lint error --- .../components/google_assistant/smart_home.py | 16 ++++++++++++++-- .../google_assistant/test_smart_home.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index bab63bdb7ae..8ea7a8aa7bc 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -187,7 +187,7 @@ async def async_handle_message(hass, config, message): """Handle incoming API messages.""" response = await _process(hass, config, message) - if 'errorCode' in response['payload']: + if response and 'errorCode' in response['payload']: _LOGGER.error('Error handling message %s: %s', message, response['payload']) @@ -215,7 +215,6 @@ async def _process(hass, config, message): try: result = await handler(hass, config, inputs[0].get('payload')) - return {'requestId': request_id, 'payload': result} except SmartHomeError as err: return { 'requestId': request_id, @@ -228,6 +227,10 @@ async def _process(hass, config, message): 'payload': {'errorCode': ERR_UNKNOWN_ERROR} } + if result is None: + return None + return {'requestId': request_id, 'payload': result} + @HANDLERS.register('action.devices.SYNC') async def async_devices_sync(hass, config, payload): @@ -337,6 +340,15 @@ async def handle_devices_execute(hass, config, payload): return {'commands': final_results} +@HANDLERS.register('action.devices.DISCONNECT') +async def async_devices_disconnect(hass, config, payload): + """Handle action.devices.DISCONNECT request. + + https://developers.google.com/actions/smarthome/create#actiondevicesdisconnect + """ + return None + + def turned_off_response(message): """Return a device turned off response.""" return { diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index d7c6094bebb..05ae0809527 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -316,3 +316,15 @@ async def test_empty_name_doesnt_sync(hass): 'devices': [] } } + + +async def test_query_disconnect(hass): + """Test a disconnect message.""" + result = await sh.async_handle_message(hass, BASIC_CONFIG, { + 'inputs': [ + {'intent': 'action.devices.DISCONNECT'} + ], + 'requestId': REQ_ID + }) + + assert result is None