From 22088d192aa115f83029d56ab8455aae2bcf550f Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 29 Jul 2017 21:52:26 -0700 Subject: [PATCH] Fix alexa cards (#8708) --- homeassistant/components/alexa.py | 9 +++------ tests/components/test_alexa.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/alexa.py b/homeassistant/components/alexa.py index c121268f93d..3547e86dad1 100644 --- a/homeassistant/components/alexa.py +++ b/homeassistant/components/alexa.py @@ -171,7 +171,7 @@ class AlexaIntentsView(http.HomeAssistantView): if 'simple' in intent_response.card: alexa_response.add_card( - 'simple', intent_response.card['simple']['title'], + CardType.simple, intent_response.card['simple']['title'], intent_response.card['simple']['content']) return self.json(alexa_response) @@ -208,8 +208,8 @@ class AlexaResponse(object): self.card = card return - card["title"] = title.async_render(self.variables) - card["content"] = content.async_render(self.variables) + card["title"] = title + card["content"] = content self.card = card def add_speech(self, speech_type, text): @@ -218,9 +218,6 @@ class AlexaResponse(object): key = 'ssml' if speech_type == SpeechType.ssml else 'text' - if isinstance(text, template.Template): - text = text.async_render(self.variables) - self.speech = { 'type': speech_type.value, key: text diff --git a/tests/components/test_alexa.py b/tests/components/test_alexa.py index eb8391c3e0d..4e082441064 100644 --- a/tests/components/test_alexa.py +++ b/tests/components/test_alexa.py @@ -86,7 +86,12 @@ def alexa_client(loop, hass, test_client): "CallServiceIntent": { "speech": { "type": "plain", - "text": "Service called", + "text": "Service called for {{ ZodiacSign }}", + }, + "card": { + "type": "simple", + "title": "Card title for {{ ZodiacSign }}", + "content": "Card content: {{ ZodiacSign }}", }, "action": { "service": "test.alexa", @@ -319,6 +324,13 @@ def test_intent_request_calling_service(alexa_client): assert call.data.get("entity_id") == ["switch.test"] assert call.data.get("hello") == "virgo" + data = yield from req.json() + assert data['response']['card']['title'] == 'Card title for virgo' + assert data['response']['card']['content'] == 'Card content: virgo' + assert data['response']['outputSpeech']['type'] == 'PlainText' + assert data['response']['outputSpeech']['text'] == \ + 'Service called for virgo' + @asyncio.coroutine def test_intent_session_ended_request(alexa_client):