Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Handle food items
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Jun 4, 2024
1 parent de04f93 commit 801c164
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
15 changes: 6 additions & 9 deletions custom_components/mealie/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,12 @@ async def async_add_shopping_list_item(
return await self.api_wrapper("post", "/api/groups/shopping/items", data=data)

async def async_update_shopping_list_item(
self, shopping_list_id: str, item_id: str, summary: str, checked: bool
self, shopping_list_id: str, item_id: str, item: dict
) -> dict:
"""Update a shopping list item."""

data = {"isFood": "False", "checked": checked}
data["note"] = summary
data["shoppingListId"] = shopping_list_id

return await self.api_wrapper(
"put", f"/api/groups/shopping/items/{item_id}", data=data
"put", f"/api/groups/shopping/items/{item_id}", data=item
)

async def async_reorder_shopping_list_item(
Expand All @@ -80,12 +76,13 @@ async def async_reorder_shopping_list_item(
data["item_id"] = item["id"]
data["position"] = position
data["isFood"] = item["isFood"]
data["quantity"] = item["quantity"]
data["labelId"] = item["labelId"]
data["note"] = item["note"]

if item["isFood"]:
data["foodId"] = item["foodId"]
data["quantity"] = item["quantity"]
else:
data["note"] = item["note"]
data["unitId"] = item["unitId"]

return await self.api_wrapper(
"put", f"/api/groups/shopping/items/{item["id"]}", data=data
Expand Down
30 changes: 18 additions & 12 deletions custom_components/mealie/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, COORDINATOR, ATTR_SHOPPING_LIST_ID
from .const import DOMAIN, LOGGER, COORDINATOR, ATTR_SHOPPING_LIST_ID
from .entity import MealieEntity
from .coordinator import MealieDataUpdateCoordinator

Expand Down Expand Up @@ -139,18 +139,24 @@ async def async_create_todo_item(self, item: TodoItem) -> None:
async def async_update_todo_item(self, item: TodoItem) -> None:
"""Update an item on the list."""

# try:
await self.coordinator.api.async_update_shopping_list_item(
self._shopping_list_id,
item.uid,
item.summary,
item.status == TodoItemStatus.COMPLETED,
list_items = self.coordinator.shopping_list_items[self._shopping_list_id]
for list_item in list_items:
if list_item["id"] == item.uid:
list_item["note"] = item.summary
list_item["isFood"] = "False"
list_item["foodId"] = None
list_item["quantity"] = "0.0"
list_item["checked"] = item.status == TodoItemStatus.COMPLETED

await self.coordinator.api.async_update_shopping_list_item(
self._shopping_list_id, item.uid, list_item
)
await self.coordinator.async_refresh()
return

LOGGER.error(
"Item %s not found in shopping list %s", item.uid, self._shopping_list_id
)
await self.coordinator.async_refresh()
# except NoMatchingShoppingListItem as err:
# raise HomeAssistantError(
# f"Shopping list item '{item.uid}' was not found"
# ) from err

async def async_delete_todo_items(self, uids: list[str]) -> None:
"""Delete items from the list."""
Expand Down

0 comments on commit 801c164

Please sign in to comment.