Skip to content

Commit 80fb2c1

Browse files
committed
Added service "add-missing-products-to-shopping-list" to add all items below min stock amount to given shopping list, addressing #275
1 parent 9b09562 commit 80fb2c1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Executes the given chore with an optional timestamp and executor.
7777

7878
Consumes the given recipe.
7979

80+
- **Grocy: Add Missing Products to Shopping List** (_grocy.add_missing_products_to_shopping_list_)
81+
82+
Adds currently missing products to a given shopping list.
83+
8084

8185
# Translations
8286

custom_components/grocy/services.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
SERVICE_RECIPE_ID = "recipe_id"
2525
SERVICE_BATTERY_ID = "battery_id"
2626
SERVICE_OBJECT_ID = "object_id"
27+
SERVICE_LIST_ID = "list_id"
2728

2829
SERVICE_ADD_PRODUCT = "add_product_to_stock"
2930
SERVICE_OPEN_PRODUCT = "open_product"
@@ -35,6 +36,7 @@
3536
SERVICE_DELETE_GENERIC = "delete_generic"
3637
SERVICE_CONSUME_RECIPE = "consume_recipe"
3738
SERVICE_TRACK_BATTERY = "track_battery"
39+
SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST = "add_missing_products_to_shopping_list"
3840

3941
SERVICE_ADD_PRODUCT_SCHEMA = vol.All(
4042
vol.Schema(
@@ -130,6 +132,14 @@
130132
)
131133
)
132134

135+
SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST_SCHEMA: vol.All(
136+
vol.Schema(
137+
{
138+
vol.Optional(SERVICE_LIST_ID): vol.Coerce(int),
139+
}
140+
)
141+
)
142+
133143
SERVICES_WITH_ACCOMPANYING_SCHEMA: list[tuple[str, vol.Schema]] = [
134144
(SERVICE_ADD_PRODUCT, SERVICE_ADD_PRODUCT_SCHEMA),
135145
(SERVICE_OPEN_PRODUCT, SERVICE_OPEN_PRODUCT_SCHEMA),
@@ -141,6 +151,7 @@
141151
(SERVICE_DELETE_GENERIC, SERVICE_DELETE_GENERIC_SCHEMA),
142152
(SERVICE_CONSUME_RECIPE, SERVICE_CONSUME_RECIPE_SCHEMA),
143153
(SERVICE_TRACK_BATTERY, SERVICE_TRACK_BATTERY_SCHEMA),
154+
(SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST, SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST_SCHEMA),
144155
]
145156

146157

@@ -351,6 +362,14 @@ def wrapper():
351362

352363
await hass.async_add_executor_job(wrapper)
353364

365+
async def async_add_missing_products_to_shopping_list(hass, coordinator, data):
366+
'''Adds currently missing proudcts (below defined min. stock amount) to the given shopping list.'''
367+
list_id = data.get(SERVICE_LIST_ID, None)
368+
369+
def wrapper():
370+
coordinator.grocy_api.add_missing_product_to_shopping_list(list_id)
371+
372+
await hass.async_add_executor_job(wrapper)
354373

355374
async def _async_force_update_entity(
356375
coordinator: GrocyDataUpdateCoordinator, entity_key: str

custom_components/grocy/services.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,15 @@ track_battery:
304304
description: The id of the battery
305305
selector:
306306
text:
307+
308+
add_missing_products_to_shopping_list:
309+
name: Add Missing Products to Shopping List
310+
description: Adds currently missing products to the given shopping list.
311+
fields:
312+
list_id:
313+
name: List Id
314+
example: '1'
315+
required: false
316+
description: The id of the shopping list to be added to.
317+
selector:
318+
text:

0 commit comments

Comments
 (0)