From 5731f528d235aa708a6d412bc88644d272dde07d Mon Sep 17 00:00:00 2001 From: Paul Romkes <paul@newbreedmedia.nl> Date: Mon, 18 Nov 2019 09:13:22 +0100 Subject: [PATCH] Make intents end Snips session without speech (#28820) * intents should also end session without speech * Move endSession message to try block * Minor improvement on endSession response --- homeassistant/components/snips/__init__.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/snips/__init__.py b/homeassistant/components/snips/__init__.py index 441104211cf..93e445e8ced 100644 --- a/homeassistant/components/snips/__init__.py +++ b/homeassistant/components/snips/__init__.py @@ -135,7 +135,6 @@ async def async_setup(hass, config): intent_type = request["intent"]["intentName"].split("__")[-1] else: intent_type = request["intent"]["intentName"].split(":")[-1] - snips_response = None slots = {} for slot in request.get("slots", []): slots[slot["slotName"]] = {"value": resolve_slot_values(slot)} @@ -148,8 +147,15 @@ async def async_setup(hass, config): intent_response = await intent.async_handle( hass, DOMAIN, intent_type, slots, request["input"] ) + notification = {"sessionId": request.get("sessionId", "default")} + if "plain" in intent_response.speech: - snips_response = intent_response.speech["plain"]["speech"] + notification["text"] = intent_response.speech["plain"]["speech"] + + _LOGGER.debug("send_response %s", json.dumps(notification)) + mqtt.async_publish( + hass, "hermes/dialogueManager/endSession", json.dumps(notification) + ) except intent.UnknownIntent: _LOGGER.warning( "Received unknown intent %s", request["intent"]["intentName"] @@ -157,17 +163,6 @@ async def async_setup(hass, config): except intent.IntentError: _LOGGER.exception("Error while handling intent: %s.", intent_type) - if snips_response: - notification = { - "sessionId": request.get("sessionId", "default"), - "text": snips_response, - } - - _LOGGER.debug("send_response %s", json.dumps(notification)) - mqtt.async_publish( - hass, "hermes/dialogueManager/endSession", json.dumps(notification) - ) - await hass.components.mqtt.async_subscribe(INTENT_TOPIC, message_received) async def snips_say(call): -- GitLab