1 """A shopping list todo platform."""
3 from typing
import cast
16 from .
import NoMatchingShoppingListItem, ShoppingData
17 from .const
import DOMAIN
22 config_entry: ConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 """Set up the shopping_list todo platform."""
26 shopping_data = hass.data[DOMAIN]
32 """A To-do List representation of the Shopping List."""
34 _attr_has_entity_name =
True
35 _attr_translation_key =
"shopping_list"
36 _attr_should_poll =
False
37 _attr_supported_features = (
38 TodoListEntityFeature.CREATE_TODO_ITEM
39 | TodoListEntityFeature.DELETE_TODO_ITEM
40 | TodoListEntityFeature.UPDATE_TODO_ITEM
41 | TodoListEntityFeature.MOVE_TODO_ITEM
44 def __init__(self, data: ShoppingData, unique_id: str) ->
None:
45 """Initialize ShoppingTodoListEntity."""
50 """Add an item to the To-do list."""
51 await self.
_data_data.async_add(
52 item.summary, complete=(item.status == TodoItemStatus.COMPLETED)
56 """Update an item to the To-do list."""
59 "complete": item.status == TodoItemStatus.COMPLETED,
63 except NoMatchingShoppingListItem
as err:
65 f
"Shopping list item '{item.uid}' was not found"
69 """Add an item to the To-do list."""
70 await self.
_data_data.async_remove_items(set(uids))
73 self, uid: str, previous_uid: str |
None =
None
75 """Re-order an item to the To-do list."""
78 await self.
_data_data.async_move_item(uid, previous_uid)
79 except NoMatchingShoppingListItem
as err:
81 f
"Shopping list item '{uid}' could not be re-ordered"
85 """Entity has been added to hass."""
93 """Get items in the To-do list."""
95 for item
in self.
_data_data.items:
96 if cast(bool, item[
"complete"]):
97 status = TodoItemStatus.COMPLETED
99 status = TodoItemStatus.NEEDS_ACTION
102 summary=cast(str, item[
"name"]),
103 uid=cast(str, item[
"id"]),
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_add_listener(HomeAssistant hass, Callable[[], None] listener)