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

Commit

Permalink
Remove group_id and set infinite page size
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Jun 29, 2024
1 parent 96d71e3 commit 96d04e3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 29 deletions.
3 changes: 1 addition & 2 deletions custom_components/mealie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
MIN_HA_VERSION,
DOMAIN_CONFIG,
COORDINATOR,
CONF_GROUP_ID,
CONF_BREAKFAST_START,
CONF_BREAKFAST_END,
CONF_LUNCH_START,
Expand Down Expand Up @@ -116,7 +115,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)

hass.data[DOMAIN][COORDINATOR] = coordinator = MealieDataUpdateCoordinator(
hass=hass, api=api, group_id=entry.data[CONF_GROUP_ID]
hass=hass, api=api
)

await coordinator.async_config_entry_first_refresh()
Expand Down
20 changes: 8 additions & 12 deletions custom_components/mealie/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ async def async_get_groups(self) -> dict:
"""Get current users group."""
return await self.api_wrapper("get", "/api/groups/self")

async def async_get_shopping_lists(self, group_id: str) -> dict:
async def async_get_shopping_lists(self) -> dict:
"""Get all shopping lists for our group."""
params = {"group_id": group_id}
return await self.api_wrapper("get", "/api/groups/shopping/lists", data=params)
return await self.api_wrapper("get", "/api/groups/shopping/lists")

async def async_get_shopping_list_items(
self, group_id: str, shopping_list_id: str
self, shopping_list_id: str
) -> dict:
"""Get all shopping list items."""

params = {"orderBy": "position", "orderDirection": "asc", "perPage": "1000"}
params["group_id"] = group_id
params = {"orderBy": "position", "orderDirection": "asc", "perPage": "-1"}
params["queryFilter"] = f"shoppingListId={shopping_list_id}"

return await self.api_wrapper("get", "/api/groups/shopping/items", data=params)
Expand Down Expand Up @@ -99,19 +97,17 @@ async def async_delete_shopping_list_item(self, item_id: str) -> dict:
"delete", f"/api/groups/shopping/items/{item_id}", data=data
)

async def async_get_meal_plans(self, group_id: str, start_date: str, end_date: str) -> dict:
async def async_get_meal_plans(self, start_date: str, end_date: str) -> dict:
"""Get all meal plans for our group."""
params = {"orderBy": "date", "orderDirection": "asc", "perPage": "1000"}
params["group_id"] = group_id
params = {"orderBy": "date", "orderDirection": "asc", "perPage": "-1"}
params["start_date"] = start_date
params["end_date"] = end_date

return await self.api_wrapper("get", "/api/groups/mealplans", data=params)

async def async_get_meal_plans_today(self, group_id: str) -> dict:
async def async_get_meal_plans_today(self) -> dict:
"""Get today's meal plans for our group."""
params = {"orderBy": "date", "orderDirection": "asc", "perPage": "1000"}
params["group_id"] = group_id
params = {"orderBy": "date", "orderDirection": "asc", "perPage": "-1"}

return await self.api_wrapper("get", "/api/groups/mealplans/today", data=params)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/mealie/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def async_get_events(
mealie_end_date = f"{end_date:%Y-%m-%d}"

plans = await self.coordinator.api.async_get_meal_plans(
self.coordinator.group_id, mealie_start_date, mealie_end_date
mealie_start_date, mealie_end_date
)

events: list[CalendarEvent] = []
Expand Down
2 changes: 0 additions & 2 deletions custom_components/mealie/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .const import (
DOMAIN,
LOGGER,
CONF_GROUP_ID,
)

STEP_USER_DATA_SCHEMA = vol.Schema(
Expand Down Expand Up @@ -65,7 +64,6 @@ async def async_step_user(

# Save instance
if not errors:
user_input[CONF_GROUP_ID] = data.get("id")
if self._reauth_entry is None:
return self.async_create_entry(title="Mealie", data=user_input)
else:
Expand Down
2 changes: 0 additions & 2 deletions custom_components/mealie/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

SERVICE_ADD_SHOPPING_LIST_ITEM = "add_shopping_list_item"

CONF_GROUP_ID = "group_id"

CONF_BREAKFAST_START = "breakfast_start"
CONF_BREAKFAST_END = "breakfast_end"
CONF_LUNCH_START = "lunch_start"
Expand Down
14 changes: 4 additions & 10 deletions custom_components/mealie/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ def __init__(
self,
hass: HomeAssistant,
api: MealieApiClient,
group_id: str,
) -> None:
"""Initialize."""
self.api = api
self.group_id = group_id

self._shopping_lists: dict | None = None
self.shopping_list_items: dict = {}
Expand Down Expand Up @@ -203,16 +201,14 @@ async def async_get_shopping_lists(self) -> dict:
"""Return shopping lists fetched at most once."""
if self._shopping_lists is None:

result = await self.api.async_get_shopping_lists(self.group_id)
result = await self.api.async_get_shopping_lists()

self._shopping_lists = result.get("items")
return self._shopping_lists

async def async_get_shopping_lists_items(self, shopping_list_id) -> dict:
"""Return shopping lists fetched at most once."""
result = await self.api.async_get_shopping_list_items(
self.group_id, shopping_list_id
)
result = await self.api.async_get_shopping_list_items(shopping_list_id)

items = result.get("items")
return items
Expand All @@ -223,7 +219,7 @@ async def _async_update_data(self):
# Today's meal plan

try:
result = await self.api.async_get_meal_plans_today(self.group_id)
result = await self.api.async_get_meal_plans_today()

if self.api.error:
raise ConfigEntryAuthFailed(
Expand All @@ -243,9 +239,7 @@ async def _async_update_data(self):

for value in self._shopping_lists:
shopping_list_id = value.get("id")
result = await self.api.async_get_shopping_list_items(
self.group_id, shopping_list_id
)
result = await self.api.async_get_shopping_list_items(shopping_list_id)

if self.api.error:
raise ConfigEntryAuthFailed(
Expand Down

0 comments on commit 96d04e3

Please sign in to comment.