1 """Intents for the Shopping List integration."""
3 from __future__
import annotations
9 from .
import DOMAIN, EVENT_SHOPPING_LIST_UPDATED
11 INTENT_ADD_ITEM =
"HassShoppingListAddItem"
12 INTENT_LAST_ITEMS =
"HassShoppingListLastItems"
16 """Set up the Shopping List intents."""
22 """Handle AddItem intents."""
24 intent_type = INTENT_ADD_ITEM
25 description =
"Adds an item to the shopping list"
26 slot_schema = {
"item": cv.string}
29 async
def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
30 """Handle the intent."""
31 slots = self.async_validate_slots(intent_obj.slots)
32 item = slots[
"item"][
"value"].strip()
33 await intent_obj.hass.data[DOMAIN].async_add(item)
35 response = intent_obj.create_response()
36 intent_obj.hass.bus.async_fire(EVENT_SHOPPING_LIST_UPDATED)
41 """Handle AddItem intents."""
43 intent_type = INTENT_LAST_ITEMS
44 description =
"List the top five items on the shopping list"
45 slot_schema = {
"item": cv.string}
48 async
def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
49 """Handle the intent."""
50 items = intent_obj.hass.data[DOMAIN].items[-5:]
51 response = intent_obj.create_response()
54 response.async_set_speech(
"There are no items on your shopping list")
56 items_list =
", ".join(itm[
"name"]
for itm
in reversed(items))
57 response.async_set_speech(
58 f
"These are the top {min(len(items), 5)} items on your shopping list: {items_list}"