|
24 | 24 | SERVICE_RECIPE_ID = "recipe_id"
|
25 | 25 | SERVICE_BATTERY_ID = "battery_id"
|
26 | 26 | SERVICE_OBJECT_ID = "object_id"
|
| 27 | +SERVICE_LIST_ID = "list_id" |
27 | 28 |
|
28 | 29 | SERVICE_ADD_PRODUCT = "add_product_to_stock"
|
29 | 30 | SERVICE_OPEN_PRODUCT = "open_product"
|
|
35 | 36 | SERVICE_DELETE_GENERIC = "delete_generic"
|
36 | 37 | SERVICE_CONSUME_RECIPE = "consume_recipe"
|
37 | 38 | SERVICE_TRACK_BATTERY = "track_battery"
|
| 39 | +SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST = "add_missing_products_to_shopping_list" |
38 | 40 |
|
39 | 41 | SERVICE_ADD_PRODUCT_SCHEMA = vol.All(
|
40 | 42 | vol.Schema(
|
|
130 | 132 | )
|
131 | 133 | )
|
132 | 134 |
|
| 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 | + |
133 | 143 | SERVICES_WITH_ACCOMPANYING_SCHEMA: list[tuple[str, vol.Schema]] = [
|
134 | 144 | (SERVICE_ADD_PRODUCT, SERVICE_ADD_PRODUCT_SCHEMA),
|
135 | 145 | (SERVICE_OPEN_PRODUCT, SERVICE_OPEN_PRODUCT_SCHEMA),
|
|
141 | 151 | (SERVICE_DELETE_GENERIC, SERVICE_DELETE_GENERIC_SCHEMA),
|
142 | 152 | (SERVICE_CONSUME_RECIPE, SERVICE_CONSUME_RECIPE_SCHEMA),
|
143 | 153 | (SERVICE_TRACK_BATTERY, SERVICE_TRACK_BATTERY_SCHEMA),
|
| 154 | + (SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST, SERVICE_ADD_MISSING_PRODUCTS_TO_SHOPPING_LIST_SCHEMA), |
144 | 155 | ]
|
145 | 156 |
|
146 | 157 |
|
@@ -351,6 +362,14 @@ def wrapper():
|
351 | 362 |
|
352 | 363 | await hass.async_add_executor_job(wrapper)
|
353 | 364 |
|
| 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) |
354 | 373 |
|
355 | 374 | async def _async_force_update_entity(
|
356 | 375 | coordinator: GrocyDataUpdateCoordinator, entity_key: str
|
|
0 commit comments