mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +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:
|
if not entity_ids:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Could not find entity id %s from text %s", name, text)
|
"Could not find entity id %s from text %s", name, text)
|
||||||
return
|
return None
|
||||||
|
|
||||||
if command == 'on':
|
if command == 'on':
|
||||||
yield from hass.services.async_call(
|
yield from hass.services.async_call(
|
||||||
@ -169,6 +169,8 @@ def _process(hass, text):
|
|||||||
_LOGGER.error('Got unsupported command %s from text %s',
|
_LOGGER.error('Got unsupported command %s from text %s',
|
||||||
command, text)
|
command, text)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ConversationProcessView(http.HomeAssistantView):
|
class ConversationProcessView(http.HomeAssistantView):
|
||||||
"""View to retrieve shopping list content."""
|
"""View to retrieve shopping list content."""
|
||||||
@ -194,4 +196,8 @@ class ConversationProcessView(http.HomeAssistantView):
|
|||||||
|
|
||||||
intent_result = yield from _process(hass, text)
|
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)
|
return self.json(intent_result)
|
||||||
|
@ -70,11 +70,16 @@ class ListTopItemsIntent(intent.IntentHandler):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_handle(self, intent_obj):
|
def async_handle(self, intent_obj):
|
||||||
"""Handle the intent."""
|
"""Handle the intent."""
|
||||||
|
items = intent_obj.hass.data[DOMAIN][-5:]
|
||||||
response = intent_obj.create_response()
|
response = intent_obj.create_response()
|
||||||
|
|
||||||
|
if len(items) == 0:
|
||||||
response.async_set_speech(
|
response.async_set_speech(
|
||||||
"These are the top 5 items in your shopping list: {}".format(
|
"There are no items on your shopping list")
|
||||||
', '.join(reversed(intent_obj.hass.data[DOMAIN][-5:]))))
|
else:
|
||||||
intent_obj.hass.bus.async_fire(EVENT)
|
response.async_set_speech(
|
||||||
|
"These are the top {} items on your shopping list: {}".format(
|
||||||
|
min(len(items), 5), ', '.join(reversed(items))))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class Intent:
|
|||||||
class IntentResponse:
|
class IntentResponse:
|
||||||
"""Response to an intent."""
|
"""Response to an intent."""
|
||||||
|
|
||||||
def __init__(self, intent):
|
def __init__(self, intent=None):
|
||||||
"""Initialize an IntentResponse."""
|
"""Initialize an IntentResponse."""
|
||||||
self.intent = intent
|
self.intent = intent
|
||||||
self.speech = {}
|
self.speech = {}
|
||||||
|
@ -38,7 +38,7 @@ def test_recent_items_intent(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert response.speech['plain']['speech'] == \
|
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
|
@asyncio.coroutine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user