diff --git a/homeassistant/components/conversation.py b/homeassistant/components/conversation.py index b682b318c7b..303e83e7e0e 100644 --- a/homeassistant/components/conversation.py +++ b/homeassistant/components/conversation.py @@ -151,7 +151,7 @@ def _process(hass, text): if not entity_ids: _LOGGER.error( "Could not find entity id %s from text %s", name, text) - return + return None if command == 'on': yield from hass.services.async_call( @@ -169,6 +169,8 @@ def _process(hass, text): _LOGGER.error('Got unsupported command %s from text %s', command, text) + return None + class ConversationProcessView(http.HomeAssistantView): """View to retrieve shopping list content.""" @@ -194,4 +196,8 @@ class ConversationProcessView(http.HomeAssistantView): intent_result = yield from _process(hass, text) + if intent_result is None: + intent_result = intent.IntentResponse() + intent_result.async_set_speech("Sorry, I didn't understand that") + return self.json(intent_result) diff --git a/homeassistant/components/shopping_list.py b/homeassistant/components/shopping_list.py index 7247579fa39..ac59c15572a 100644 --- a/homeassistant/components/shopping_list.py +++ b/homeassistant/components/shopping_list.py @@ -70,11 +70,16 @@ class ListTopItemsIntent(intent.IntentHandler): @asyncio.coroutine def async_handle(self, intent_obj): """Handle the intent.""" + items = intent_obj.hass.data[DOMAIN][-5:] response = intent_obj.create_response() - response.async_set_speech( - "These are the top 5 items in your shopping list: {}".format( - ', '.join(reversed(intent_obj.hass.data[DOMAIN][-5:])))) - intent_obj.hass.bus.async_fire(EVENT) + + if len(items) == 0: + response.async_set_speech( + "There are no items on your shopping list") + else: + response.async_set_speech( + "These are the top {} items on your shopping list: {}".format( + min(len(items), 5), ', '.join(reversed(items)))) return response diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index 459d89a83ce..8843bf53df9 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -134,7 +134,7 @@ class Intent: class IntentResponse: """Response to an intent.""" - def __init__(self, intent): + def __init__(self, intent=None): """Initialize an IntentResponse.""" self.intent = intent self.speech = {} diff --git a/tests/components/test_shopping_list.py b/tests/components/test_shopping_list.py index 867e695e2d5..c25ce593c54 100644 --- a/tests/components/test_shopping_list.py +++ b/tests/components/test_shopping_list.py @@ -38,7 +38,7 @@ def test_recent_items_intent(hass): ) assert response.speech['plain']['speech'] == \ - "These are the top 5 items in your shopping list: soda, wine, beer" + "These are the top 3 items on your shopping list: soda, wine, beer" @asyncio.coroutine