Tweak conversation/intent/shopping list (#8636)

This commit is contained in:
Paulus Schoutsen 2017-07-25 00:42:59 -07:00 committed by GitHub
parent ad7370e1c2
commit c2828bac2c
4 changed files with 18 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 = {}

View File

@ -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