mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Tweak conversation/intent/shopping list (#8636)
This commit is contained in:
parent
ad7370e1c2
commit
c2828bac2c
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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 = {}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user