Skip to content

Commit

Permalink
Merge pull request #329 from rapala-b/master
Browse files Browse the repository at this point in the history
Feature: Service for Add Missing Products to Shopping List
  • Loading branch information
isabellaalstrom authored Feb 3, 2025
2 parents 6a3b19e + e6ff660 commit e34c64f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Executes the given chore with an optional timestamp and executor.

Consumes the given recipe.

- **Grocy: Add Missing Products to Shopping List** (_grocy.add_missing_products_to_shopping_list_)

Adds currently missing products to a given shopping list.


# Translations

Expand Down
19 changes: 19 additions & 0 deletions custom_components/grocy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SERVICE_RECIPE_ID = "recipe_id"
SERVICE_BATTERY_ID = "battery_id"
SERVICE_OBJECT_ID = "object_id"
SERVICE_LIST_ID = "list_id"

SERVICE_ADD_PRODUCT = "add_product_to_stock"
SERVICE_OPEN_PRODUCT = "open_product"
Expand All @@ -37,6 +38,7 @@
SERVICE_DELETE_GENERIC = "delete_generic"
SERVICE_CONSUME_RECIPE = "consume_recipe"
SERVICE_TRACK_BATTERY = "track_battery"
SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST = "add_missing_products_to_shopping_list"

SERVICE_ADD_PRODUCT_SCHEMA = vol.All(
vol.Schema(
Expand Down Expand Up @@ -133,6 +135,14 @@
)
)

SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST_SCHEMA: vol.All(
vol.Schema(
{
vol.Optional(SERVICE_LIST_ID): vol.Coerce(int),
}
)
)

SERVICES_WITH_ACCOMPANYING_SCHEMA: list[tuple[str, vol.Schema]] = [
(SERVICE_ADD_PRODUCT, SERVICE_ADD_PRODUCT_SCHEMA),
(SERVICE_OPEN_PRODUCT, SERVICE_OPEN_PRODUCT_SCHEMA),
Expand All @@ -144,6 +154,7 @@
(SERVICE_DELETE_GENERIC, SERVICE_DELETE_GENERIC_SCHEMA),
(SERVICE_CONSUME_RECIPE, SERVICE_CONSUME_RECIPE_SCHEMA),
(SERVICE_TRACK_BATTERY, SERVICE_TRACK_BATTERY_SCHEMA),
(SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST, SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST_SCHEMA),
]


Expand Down Expand Up @@ -357,6 +368,14 @@ def wrapper():

await hass.async_add_executor_job(wrapper)

async def async_add_missing_products_to_shopping_list(hass, coordinator, data):
'''Adds currently missing proudcts (below defined min. stock amount) to the given shopping list.'''
list_id = data.get(SERVICE_LIST_ID, 1)

def wrapper():
coordinator.grocy_api.add_missing_product_to_shopping_list(list_id)

await hass.async_add_executor_job(wrapper)

async def _async_force_update_entity(
coordinator: GrocyDataUpdateCoordinator, entity_key: str
Expand Down
12 changes: 12 additions & 0 deletions custom_components/grocy/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,15 @@ track_battery:
description: The id of the battery
selector:
text:

add_missing_products_to_shopping_list:
name: Add Missing Products to Shopping List
description: Adds currently missing products to the given shopping list.
fields:
list_id:
name: List Id
example: '1'
required: false
description: The id of the shopping list to be added to.
selector:
text:

0 comments on commit e34c64f

Please sign in to comment.