From e98e364767cc766941cd7c282c85da6251d3d351 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Tue, 20 Oct 2026 13:38:29 +0100 Subject: [PATCH] Migrate to use Mealie Service constants (#187490) --- homeassistant/components/mealie/const.py | 13 - homeassistant/components/mealie/services.py | 204 ++++++----- tests/components/mealie/test_services.py | 383 ++++++++++---------- 3 files changed, 311 insertions(+), 289 deletions(-) diff --git a/homeassistant/components/mealie/const.py b/homeassistant/components/mealie/const.py index 1f5644c3ac63..8629ff545fdf 100644 --- a/homeassistant/components/mealie/const.py +++ b/homeassistant/components/mealie/const.py @@ -8,19 +8,6 @@ DOMAIN = "mealie" LOGGER = logging.getLogger(__package__) -ATTR_START_DATE = "start_date" -ATTR_END_DATE = "end_date" -ATTR_MEALPLAN_ID = "mealplan_id" -ATTR_RECIPE_ID = "recipe_id" -ATTR_URL = "url" -ATTR_INCLUDE_TAGS = "include_tags" -ATTR_ENTRY_TYPE = "entry_type" -ATTR_NOTE_TITLE = "note_title" -ATTR_NOTE_TEXT = "note_text" -ATTR_SEARCH_TERMS = "search_terms" -ATTR_RESULT_LIMIT = "result_limit" -ATTR_INGREDIENT = "ingredient" - CONF_PARSE_TODO_NEW = "parse_todo_new" CONF_PARSE_TODO_EDIT = "parse_todo_edit" CONF_PARSER = "parser" diff --git a/homeassistant/components/mealie/services.py b/homeassistant/components/mealie/services.py index 867e5259f67b..a1b924428cab 100644 --- a/homeassistant/components/mealie/services.py +++ b/homeassistant/components/mealie/services.py @@ -1,6 +1,7 @@ """Define services for the Mealie integration.""" from dataclasses import asdict +from enum import StrEnum from aiomealie import ( MealieConnectionError, @@ -13,7 +14,7 @@ from awesomeversion import AwesomeVersion import probatio from homeassistant.components.todo import DOMAIN as TODO_DOMAIN -from homeassistant.const import ATTR_CONFIG_ENTRY_ID, ATTR_DATE +from homeassistant.const import ATTR_CONFIG_ENTRY_ID from homeassistant.core import ( HomeAssistant, ServiceCall, @@ -26,144 +27,159 @@ from homeassistant.helpers import config_validation as cv, service from homeassistant.helpers.typing import VolDictType from homeassistant.util import dt as dt_util -from .const import ( - ATTR_END_DATE, - ATTR_ENTRY_TYPE, - ATTR_INCLUDE_TAGS, - ATTR_INGREDIENT, - ATTR_MEALPLAN_ID, - ATTR_NOTE_TEXT, - ATTR_NOTE_TITLE, - ATTR_RECIPE_ID, - ATTR_RESULT_LIMIT, - ATTR_SEARCH_TERMS, - ATTR_START_DATE, - ATTR_URL, - CONF_PARSER, - DEFAULT_PARSER, - DOMAIN, - MINIMUM_PARSER_CONFIDENCE, -) +from .const import CONF_PARSER, DEFAULT_PARSER, DOMAIN, MINIMUM_PARSER_CONFIDENCE from .coordinator import MealieConfigEntry -SERVICE_ADD_INGREDIENT = "add_ingredient" + +class MealieService(StrEnum): + """Service names for Mealie.""" + + ADD_INGREDIENT = "add_ingredient" + DELETE_MEALPLAN = "delete_mealplan" + GET_MEALPLAN = "get_mealplan" + GET_RECIPE = "get_recipe" + GET_RECIPES = "get_recipes" + GET_SHOPPING_LIST_ITEMS = "get_shopping_list_items" + IMPORT_RECIPE = "import_recipe" + PARSE_INGREDIENT = "parse_ingredient" + SET_MEALPLAN = "set_mealplan" + SET_RANDOM_MEALPLAN = "set_random_mealplan" + UPDATE_MEALPLAN = "update_mealplan" + + +class MealieServiceArgument(StrEnum): + """Service argument names for Mealie.""" + + DATE = "date" + END_DATE = "end_date" + ENTRY_TYPE = "entry_type" + FOOD_ID = "food_id" + INCLUDE_TAGS = "include_tags" + INGREDIENT = "ingredient" + MEALPLAN_ID = "mealplan_id" + NOTE = "note" + NOTE_TEXT = "note_text" + NOTE_TITLE = "note_title" + QUANTITY = "quantity" + RECIPE_ID = "recipe_id" + RESULT_LIMIT = "result_limit" + SEARCH_TERMS = "search_terms" + START_DATE = "start_date" + UNIT_ID = "unit_id" + URL = "url" + + SERVICE_ADD_INGREDIENT_SCHEMA: VolDictType = { - probatio.Optional("food_id"): str, - probatio.Optional("note"): str, - probatio.Optional("unit_id"): str, - probatio.Optional("quantity"): cv.positive_float, + probatio.Optional(MealieServiceArgument.FOOD_ID): str, + probatio.Optional(MealieServiceArgument.NOTE): str, + probatio.Optional(MealieServiceArgument.UNIT_ID): str, + probatio.Optional(MealieServiceArgument.QUANTITY): cv.positive_float, } -SERVICE_GET_MEALPLAN = "get_mealplan" SERVICE_GET_MEALPLAN_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Optional(ATTR_START_DATE): cv.date, - probatio.Optional(ATTR_END_DATE): cv.date, + probatio.Optional(MealieServiceArgument.START_DATE): cv.date, + probatio.Optional(MealieServiceArgument.END_DATE): cv.date, } ) -SERVICE_GET_RECIPE = "get_recipe" SERVICE_GET_RECIPE_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_RECIPE_ID): str, + probatio.Required(MealieServiceArgument.RECIPE_ID): str, } ) -SERVICE_GET_RECIPES = "get_recipes" SERVICE_GET_RECIPES_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Optional(ATTR_SEARCH_TERMS): str, - probatio.Optional(ATTR_RESULT_LIMIT): int, + probatio.Optional(MealieServiceArgument.SEARCH_TERMS): str, + probatio.Optional(MealieServiceArgument.RESULT_LIMIT): int, } ) -SERVICE_GET_SHOPPING_LIST_ITEMS = "get_shopping_list_items" -SERVICE_IMPORT_RECIPE = "import_recipe" SERVICE_IMPORT_RECIPE_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_URL): str, - probatio.Optional(ATTR_INCLUDE_TAGS): bool, + probatio.Required(MealieServiceArgument.URL): str, + probatio.Optional(MealieServiceArgument.INCLUDE_TAGS): bool, } ) -SERVICE_SET_RANDOM_MEALPLAN = "set_random_mealplan" SERVICE_SET_RANDOM_MEALPLAN_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_DATE): cv.date, - probatio.Required(ATTR_ENTRY_TYPE): probatio.In( + probatio.Required(MealieServiceArgument.DATE): cv.date, + probatio.Required(MealieServiceArgument.ENTRY_TYPE): probatio.In( [x.lower() for x in MealplanEntryType] ), } ) -SERVICE_SET_MEALPLAN = "set_mealplan" SERVICE_SET_MEALPLAN_SCHEMA = probatio.Any( probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_DATE): cv.date, - probatio.Required(ATTR_ENTRY_TYPE): probatio.In( + probatio.Required(MealieServiceArgument.DATE): cv.date, + probatio.Required(MealieServiceArgument.ENTRY_TYPE): probatio.In( [x.lower() for x in MealplanEntryType] ), - probatio.Required(ATTR_RECIPE_ID): str, + probatio.Required(MealieServiceArgument.RECIPE_ID): str, } ), probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_DATE): cv.date, - probatio.Required(ATTR_ENTRY_TYPE): probatio.In( + probatio.Required(MealieServiceArgument.DATE): cv.date, + probatio.Required(MealieServiceArgument.ENTRY_TYPE): probatio.In( [x.lower() for x in MealplanEntryType] ), - probatio.Required(ATTR_NOTE_TITLE): str, - probatio.Optional(ATTR_NOTE_TEXT): str, + probatio.Required(MealieServiceArgument.NOTE_TITLE): str, + probatio.Optional(MealieServiceArgument.NOTE_TEXT): str, } ), ) -SERVICE_DELETE_MEALPLAN = "delete_mealplan" SERVICE_DELETE_MEALPLAN_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_MEALPLAN_ID): probatio.Any(str, int), + probatio.Required(MealieServiceArgument.MEALPLAN_ID): probatio.Any(str, int), } ) -SERVICE_UPDATE_MEALPLAN = "update_mealplan" SERVICE_UPDATE_MEALPLAN_SCHEMA = probatio.Any( probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_MEALPLAN_ID): probatio.Any(str, int), - probatio.Required(ATTR_DATE): cv.date, - probatio.Required(ATTR_ENTRY_TYPE): probatio.In( + probatio.Required(MealieServiceArgument.MEALPLAN_ID): probatio.Any( + str, int + ), + probatio.Required(MealieServiceArgument.DATE): cv.date, + probatio.Required(MealieServiceArgument.ENTRY_TYPE): probatio.In( [x.lower() for x in MealplanEntryType] ), - probatio.Required(ATTR_RECIPE_ID): str, + probatio.Required(MealieServiceArgument.RECIPE_ID): str, } ), probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_MEALPLAN_ID): probatio.Any(str, int), - probatio.Required(ATTR_DATE): cv.date, - probatio.Required(ATTR_ENTRY_TYPE): probatio.In( + probatio.Required(MealieServiceArgument.MEALPLAN_ID): probatio.Any( + str, int + ), + probatio.Required(MealieServiceArgument.DATE): cv.date, + probatio.Required(MealieServiceArgument.ENTRY_TYPE): probatio.In( [x.lower() for x in MealplanEntryType] ), - probatio.Required(ATTR_NOTE_TITLE): str, - probatio.Optional(ATTR_NOTE_TEXT): str, + probatio.Required(MealieServiceArgument.NOTE_TITLE): str, + probatio.Optional(MealieServiceArgument.NOTE_TEXT): str, } ), ) -SERVICE_PARSE_INGREDIENT = "parse_ingredient" SERVICE_PARSE_INGREDIENT_SCHEMA = probatio.Schema( { probatio.Required(ATTR_CONFIG_ENTRY_ID): str, - probatio.Required(ATTR_INGREDIENT): str, + probatio.Required(MealieServiceArgument.INGREDIENT): str, } ) @@ -194,8 +210,8 @@ async def _async_get_mealplan(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - start_date = call.data.get(ATTR_START_DATE, dt_util.now().date()) - end_date = call.data.get(ATTR_END_DATE, dt_util.now().date()) + start_date = call.data.get(MealieServiceArgument.START_DATE, dt_util.now().date()) + end_date = call.data.get(MealieServiceArgument.END_DATE, dt_util.now().date()) if end_date < start_date: raise ServiceValidationError( translation_domain=DOMAIN, @@ -217,7 +233,7 @@ async def _async_get_recipe(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - recipe_id = call.data[ATTR_RECIPE_ID] + recipe_id = call.data[MealieServiceArgument.RECIPE_ID] client = entry.runtime_data.client try: recipe = await client.get_recipe(recipe_id) @@ -240,8 +256,8 @@ async def _async_get_recipes(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - search_terms = call.data.get(ATTR_SEARCH_TERMS) - result_limit = call.data.get(ATTR_RESULT_LIMIT, 10) + search_terms = call.data.get(MealieServiceArgument.SEARCH_TERMS) + result_limit = call.data.get(MealieServiceArgument.RESULT_LIMIT, 10) client = entry.runtime_data.client try: recipes = await client.get_recipes(search=search_terms, per_page=result_limit) @@ -263,8 +279,8 @@ async def _async_import_recipe(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - url = call.data[ATTR_URL] - include_tags = call.data.get(ATTR_INCLUDE_TAGS, False) + url = call.data[MealieServiceArgument.URL] + include_tags = call.data.get(MealieServiceArgument.INCLUDE_TAGS, False) client = entry.runtime_data.client try: recipe = await client.import_recipe(url, include_tags) @@ -288,8 +304,8 @@ async def _async_set_random_mealplan(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - mealplan_date = call.data[ATTR_DATE] - entry_type = MealplanEntryType(call.data[ATTR_ENTRY_TYPE]) + mealplan_date = call.data[MealieServiceArgument.DATE] + entry_type = MealplanEntryType(call.data[MealieServiceArgument.ENTRY_TYPE]) client = entry.runtime_data.client _validate_mealplan_type(entry.runtime_data.version, entry_type.value) @@ -311,8 +327,8 @@ async def _async_set_mealplan(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - mealplan_date = call.data[ATTR_DATE] - entry_type = MealplanEntryType(call.data[ATTR_ENTRY_TYPE]) + mealplan_date = call.data[MealieServiceArgument.DATE] + entry_type = MealplanEntryType(call.data[MealieServiceArgument.ENTRY_TYPE]) client = entry.runtime_data.client _validate_mealplan_type(entry.runtime_data.version, entry_type.value) @@ -321,9 +337,9 @@ async def _async_set_mealplan(call: ServiceCall) -> ServiceResponse: mealplan = await client.set_mealplan( mealplan_date, entry_type, - recipe_id=call.data.get(ATTR_RECIPE_ID), - note_title=call.data.get(ATTR_NOTE_TITLE), - note_text=call.data.get(ATTR_NOTE_TEXT), + recipe_id=call.data.get(MealieServiceArgument.RECIPE_ID), + note_title=call.data.get(MealieServiceArgument.NOTE_TITLE), + note_text=call.data.get(MealieServiceArgument.NOTE_TEXT), ) except MealieConnectionError as err: raise HomeAssistantError( @@ -340,7 +356,7 @@ async def _async_delete_mealplan(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - mealplan_id = int(call.data[ATTR_MEALPLAN_ID]) + mealplan_id = int(call.data[MealieServiceArgument.MEALPLAN_ID]) client = entry.runtime_data.client try: @@ -366,9 +382,9 @@ async def _async_update_mealplan(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - mealplan_id = int(call.data[ATTR_MEALPLAN_ID]) - mealplan_date = call.data[ATTR_DATE] - entry_type = MealplanEntryType(call.data[ATTR_ENTRY_TYPE]) + mealplan_id = int(call.data[MealieServiceArgument.MEALPLAN_ID]) + mealplan_date = call.data[MealieServiceArgument.DATE] + entry_type = MealplanEntryType(call.data[MealieServiceArgument.ENTRY_TYPE]) client = entry.runtime_data.client _validate_mealplan_type(entry.runtime_data.version, entry_type.value) @@ -378,9 +394,9 @@ async def _async_update_mealplan(call: ServiceCall) -> ServiceResponse: mealplan_id, mealplan_date, entry_type, - recipe_id=call.data.get(ATTR_RECIPE_ID), - note_title=call.data.get(ATTR_NOTE_TITLE), - note_text=call.data.get(ATTR_NOTE_TEXT), + recipe_id=call.data.get(MealieServiceArgument.RECIPE_ID), + note_title=call.data.get(MealieServiceArgument.NOTE_TITLE), + note_text=call.data.get(MealieServiceArgument.NOTE_TEXT), ) except MealieConnectionError as err: raise HomeAssistantError( @@ -403,7 +419,7 @@ async def _async_parse_ingredient(call: ServiceCall) -> ServiceResponse: entry: MealieConfigEntry = service.async_get_config_entry( call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] ) - ingredient = call.data[ATTR_INGREDIENT] + ingredient = call.data[MealieServiceArgument.INGREDIENT] client = entry.runtime_data.client parser = RegisteredParser(entry.options.get(CONF_PARSER, DEFAULT_PARSER)) @@ -435,62 +451,62 @@ def async_setup_services(hass: HomeAssistant) -> None: hass.services.async_register( DOMAIN, - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, _async_get_mealplan, schema=SERVICE_GET_MEALPLAN_SCHEMA, supports_response=SupportsResponse.ONLY, ) hass.services.async_register( DOMAIN, - SERVICE_GET_RECIPE, + MealieService.GET_RECIPE, _async_get_recipe, schema=SERVICE_GET_RECIPE_SCHEMA, supports_response=SupportsResponse.ONLY, ) hass.services.async_register( DOMAIN, - SERVICE_GET_RECIPES, + MealieService.GET_RECIPES, _async_get_recipes, schema=SERVICE_GET_RECIPES_SCHEMA, supports_response=SupportsResponse.ONLY, ) hass.services.async_register( DOMAIN, - SERVICE_IMPORT_RECIPE, + MealieService.IMPORT_RECIPE, _async_import_recipe, schema=SERVICE_IMPORT_RECIPE_SCHEMA, supports_response=SupportsResponse.OPTIONAL, ) hass.services.async_register( DOMAIN, - SERVICE_SET_RANDOM_MEALPLAN, + MealieService.SET_RANDOM_MEALPLAN, _async_set_random_mealplan, schema=SERVICE_SET_RANDOM_MEALPLAN_SCHEMA, supports_response=SupportsResponse.OPTIONAL, ) hass.services.async_register( DOMAIN, - SERVICE_SET_MEALPLAN, + MealieService.SET_MEALPLAN, _async_set_mealplan, schema=SERVICE_SET_MEALPLAN_SCHEMA, supports_response=SupportsResponse.OPTIONAL, ) hass.services.async_register( DOMAIN, - SERVICE_DELETE_MEALPLAN, + MealieService.DELETE_MEALPLAN, _async_delete_mealplan, schema=SERVICE_DELETE_MEALPLAN_SCHEMA, ) hass.services.async_register( DOMAIN, - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, _async_update_mealplan, schema=SERVICE_UPDATE_MEALPLAN_SCHEMA, supports_response=SupportsResponse.OPTIONAL, ) hass.services.async_register( DOMAIN, - SERVICE_PARSE_INGREDIENT, + MealieService.PARSE_INGREDIENT, _async_parse_ingredient, schema=SERVICE_PARSE_INGREDIENT_SCHEMA, supports_response=SupportsResponse.ONLY, @@ -498,7 +514,7 @@ def async_setup_services(hass: HomeAssistant) -> None: service.async_register_platform_entity_service( hass, DOMAIN, - SERVICE_ADD_INGREDIENT, + MealieService.ADD_INGREDIENT, entity_domain=TODO_DOMAIN, schema=SERVICE_ADD_INGREDIENT_SCHEMA, func="async_add_ingredient", @@ -506,7 +522,7 @@ def async_setup_services(hass: HomeAssistant) -> None: service.async_register_platform_entity_service( hass, DOMAIN, - SERVICE_GET_SHOPPING_LIST_ITEMS, + MealieService.GET_SHOPPING_LIST_ITEMS, entity_domain=TODO_DOMAIN, schema=None, func="async_get_shopping_list_items", diff --git a/tests/components/mealie/test_services.py b/tests/components/mealie/test_services.py index 1be008aa0624..1ecee8112598 100644 --- a/tests/components/mealie/test_services.py +++ b/tests/components/mealie/test_services.py @@ -21,35 +21,12 @@ import pytest from pytest_homeassistant.common import MockConfigEntry, load_fixture from syrupy.assertion import SnapshotAssertion -from homeassistant.components.mealie.const import ( - ATTR_END_DATE, - ATTR_ENTRY_TYPE, - ATTR_INCLUDE_TAGS, - ATTR_INGREDIENT, - ATTR_MEALPLAN_ID, - ATTR_NOTE_TEXT, - ATTR_NOTE_TITLE, - ATTR_RECIPE_ID, - ATTR_RESULT_LIMIT, - ATTR_SEARCH_TERMS, - ATTR_START_DATE, - ATTR_URL, - DOMAIN, -) +from homeassistant.components.mealie.const import DOMAIN from homeassistant.components.mealie.services import ( - SERVICE_ADD_INGREDIENT, - SERVICE_DELETE_MEALPLAN, - SERVICE_GET_MEALPLAN, - SERVICE_GET_RECIPE, - SERVICE_GET_RECIPES, - SERVICE_GET_SHOPPING_LIST_ITEMS, - SERVICE_IMPORT_RECIPE, - SERVICE_PARSE_INGREDIENT, - SERVICE_SET_MEALPLAN, - SERVICE_SET_RANDOM_MEALPLAN, - SERVICE_UPDATE_MEALPLAN, + MealieService, + MealieServiceArgument, ) -from homeassistant.const import ATTR_CONFIG_ENTRY_ID, ATTR_DATE, ATTR_ENTITY_ID +from homeassistant.const import ATTR_CONFIG_ENTRY_ID, ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError, ServiceValidationError @@ -60,7 +37,7 @@ from . import setup_integration ("data", "item"), [ pytest.param( - {"food_id": "09322430-d24c-4b1a-abb6-22b6ed3a88f5"}, + {MealieServiceArgument.FOOD_ID: "09322430-d24c-4b1a-abb6-22b6ed3a88f5"}, MutateShoppingItem( food_id="09322430-d24c-4b1a-abb6-22b6ed3a88f5", quantity=0.0, @@ -69,21 +46,24 @@ from . import setup_integration id="food-only", ), pytest.param( - {"note": "Kitchen roll"}, + {MealieServiceArgument.NOTE: "Kitchen roll"}, MutateShoppingItem(note="Kitchen roll", quantity=0.0, is_food=False), id="note-only", ), pytest.param( - {"food_id": "", "note": "Kitchen roll"}, + { + MealieServiceArgument.FOOD_ID: "", + MealieServiceArgument.NOTE: "Kitchen roll", + }, MutateShoppingItem(note="Kitchen roll", quantity=0.0, is_food=False), id="empty-food-id", ), pytest.param( { - "food_id": "09322430-d24c-4b1a-abb6-22b6ed3a88f5", - "note": "Diced", - "unit_id": "7bf539d4-fc78-48bc-b48e-c35ccccec34a", - "quantity": 1.5, + MealieServiceArgument.FOOD_ID: "09322430-d24c-4b1a-abb6-22b6ed3a88f5", + MealieServiceArgument.NOTE: "Diced", + MealieServiceArgument.UNIT_ID: "7bf539d4-fc78-48bc-b48e-c35ccccec34a", + MealieServiceArgument.QUANTITY: 1.5, }, MutateShoppingItem( food_id="09322430-d24c-4b1a-abb6-22b6ed3a88f5", @@ -95,7 +75,7 @@ from . import setup_integration id="all-fields", ), pytest.param( - {"note": "Apples", "quantity": 0}, + {MealieServiceArgument.NOTE: "Apples", MealieServiceArgument.QUANTITY: 0}, MutateShoppingItem(note="Apples", quantity=0.0, is_food=False), id="zero-quantity", ), @@ -126,7 +106,7 @@ async def test_service_add_ingredient( await hass.services.async_call( DOMAIN, - SERVICE_ADD_INGREDIENT, + MealieService.ADD_INGREDIENT, data, target={ATTR_ENTITY_ID: "todo.mealie_special_groceries"}, blocking=True, @@ -146,14 +126,26 @@ async def test_service_add_ingredient( @pytest.mark.parametrize( "data", [ - pytest.param({"food_id": 1}, id="invalid-food-id"), - pytest.param({"note": None}, id="invalid-note"), - pytest.param({"note": "Apples", "quantity": -1}, id="negative-quantity"), - pytest.param({"note": "Apples", "quantity": "many"}, id="invalid-quantity"), - pytest.param({"note": "Apples", "unit_id": 1}, id="invalid-unit-id"), + pytest.param({MealieServiceArgument.FOOD_ID: 1}, id="invalid-food-id"), + pytest.param({MealieServiceArgument.NOTE: None}, id="invalid-note"), + pytest.param( + {MealieServiceArgument.NOTE: "Apples", MealieServiceArgument.QUANTITY: -1}, + id="negative-quantity", + ), pytest.param( { - "note": "Apples", + MealieServiceArgument.NOTE: "Apples", + MealieServiceArgument.QUANTITY: "many", + }, + id="invalid-quantity", + ), + pytest.param( + {MealieServiceArgument.NOTE: "Apples", MealieServiceArgument.UNIT_ID: 1}, + id="invalid-unit-id", + ), + pytest.param( + { + MealieServiceArgument.NOTE: "Apples", "ingredient_label_id": "1a1b8adf-277b-4db1-bdcc-12dbec75fd8a", }, id="unsupported-ingredient-label-id", @@ -172,7 +164,7 @@ async def test_service_add_ingredient_invalid( with pytest.raises(probatio.Invalid): await hass.services.async_call( DOMAIN, - SERVICE_ADD_INGREDIENT, + MealieService.ADD_INGREDIENT, data, target={ATTR_ENTITY_ID: "todo.mealie_supermarket"}, blocking=True, @@ -185,10 +177,13 @@ async def test_service_add_ingredient_invalid( "data", [ pytest.param({}, id="missing-food-and-note"), - pytest.param({"quantity": 0}, id="quantity-only"), - pytest.param({"note": ""}, id="empty-note"), - pytest.param({"food_id": ""}, id="empty-food-id"), - pytest.param({"food_id": "", "note": ""}, id="empty-food-and-note"), + pytest.param({MealieServiceArgument.QUANTITY: 0}, id="quantity-only"), + pytest.param({MealieServiceArgument.NOTE: ""}, id="empty-note"), + pytest.param({MealieServiceArgument.FOOD_ID: ""}, id="empty-food-id"), + pytest.param( + {MealieServiceArgument.FOOD_ID: "", MealieServiceArgument.NOTE: ""}, + id="empty-food-and-note", + ), ], ) async def test_service_add_ingredient_requires_food_or_note( @@ -206,7 +201,7 @@ async def test_service_add_ingredient_requires_food_or_note( ): await hass.services.async_call( DOMAIN, - SERVICE_ADD_INGREDIENT, + MealieService.ADD_INGREDIENT, data, target={ATTR_ENTITY_ID: "todo.mealie_supermarket"}, blocking=True, @@ -230,8 +225,8 @@ async def test_service_add_ingredient_error( ): await hass.services.async_call( DOMAIN, - SERVICE_ADD_INGREDIENT, - {"note": "Apples"}, + MealieService.ADD_INGREDIENT, + {MealieServiceArgument.NOTE: "Apples"}, target={ATTR_ENTITY_ID: "todo.mealie_supermarket"}, blocking=True, ) @@ -254,7 +249,7 @@ async def test_service_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, {ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id}, blocking=True, return_response=True, @@ -267,11 +262,11 @@ async def test_service_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_START_DATE: "2023-10-22", - ATTR_END_DATE: "2023-10-25", + MealieServiceArgument.START_DATE: "2023-10-22", + MealieServiceArgument.END_DATE: "2023-10-25", }, blocking=True, return_response=True, @@ -284,10 +279,10 @@ async def test_service_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_START_DATE: "2023-10-19", + MealieServiceArgument.START_DATE: "2023-10-19", }, blocking=True, return_response=True, @@ -300,10 +295,10 @@ async def test_service_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_END_DATE: "2023-10-22", + MealieServiceArgument.END_DATE: "2023-10-22", }, blocking=True, return_response=True, @@ -317,11 +312,11 @@ async def test_service_mealplan( with pytest.raises(ServiceValidationError): await hass.services.async_call( DOMAIN, - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_START_DATE: "2023-10-22", - ATTR_END_DATE: "2023-10-19", + MealieServiceArgument.START_DATE: "2023-10-22", + MealieServiceArgument.END_DATE: "2023-10-19", }, blocking=True, return_response=True, @@ -340,8 +335,11 @@ async def test_service_recipe( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_RECIPE, - {ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, ATTR_RECIPE_ID: "recipe_id"}, + MealieService.GET_RECIPE, + { + ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, + MealieServiceArgument.RECIPE_ID: "recipe_id", + }, blocking=True, return_response=True, ) @@ -356,8 +354,8 @@ async def test_service_recipe( # With search terms and result limit { ATTR_CONFIG_ENTRY_ID: "mock_entry_id", - ATTR_SEARCH_TERMS: "pasta", - ATTR_RESULT_LIMIT: 5, + MealieServiceArgument.SEARCH_TERMS: "pasta", + MealieServiceArgument.RESULT_LIMIT: 5, }, ], ) @@ -376,7 +374,7 @@ async def test_service_get_recipes( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_RECIPES, + MealieService.GET_RECIPES, service_data, blocking=True, return_response=True, @@ -396,10 +394,10 @@ async def test_service_import_recipe( response = await hass.services.async_call( DOMAIN, - SERVICE_IMPORT_RECIPE, + MealieService.IMPORT_RECIPE, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_URL: "http://example.com", + MealieServiceArgument.URL: "http://example.com", }, blocking=True, return_response=True, @@ -411,11 +409,11 @@ async def test_service_import_recipe( await hass.services.async_call( DOMAIN, - SERVICE_IMPORT_RECIPE, + MealieService.IMPORT_RECIPE, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_URL: "http://example.com", - ATTR_INCLUDE_TAGS: True, + MealieServiceArgument.URL: "http://example.com", + MealieServiceArgument.INCLUDE_TAGS: True, }, blocking=True, return_response=False, @@ -437,11 +435,11 @@ async def test_service_set_random_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_SET_RANDOM_MEALPLAN, + MealieService.SET_RANDOM_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", }, blocking=True, return_response=True, @@ -454,11 +452,11 @@ async def test_service_set_random_mealplan( mock_mealie_client.random_mealplan.reset_mock() await hass.services.async_call( DOMAIN, - SERVICE_SET_RANDOM_MEALPLAN, + MealieService.SET_RANDOM_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", }, blocking=True, return_response=False, @@ -481,11 +479,11 @@ async def test_service_set_random_mealplan_invalid_entry_type( with pytest.raises(ServiceValidationError): await hass.services.async_call( DOMAIN, - SERVICE_SET_RANDOM_MEALPLAN, + MealieService.SET_RANDOM_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "dessert", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "dessert", }, blocking=True, return_response=True, @@ -498,20 +496,20 @@ async def test_service_set_random_mealplan_invalid_entry_type( [ ( { - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.RECIPE_ID: "recipe_id", }, {"recipe_id": "recipe_id", "note_title": None, "note_text": None}, ), ( { - ATTR_NOTE_TITLE: "Note Title", - ATTR_NOTE_TEXT: "Note Text", + MealieServiceArgument.NOTE_TITLE: "Note Title", + MealieServiceArgument.NOTE_TEXT: "Note Text", }, {"recipe_id": None, "note_title": "Note Title", "note_text": "Note Text"}, ), ( { - ATTR_NOTE_TITLE: "Note Title", + MealieServiceArgument.NOTE_TITLE: "Note Title", }, {"recipe_id": None, "note_title": "Note Title", "note_text": None}, ), @@ -531,11 +529,11 @@ async def test_service_set_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_SET_MEALPLAN, + MealieService.SET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", } | payload, blocking=True, @@ -549,11 +547,11 @@ async def test_service_set_mealplan( mock_mealie_client.random_mealplan.reset_mock() await hass.services.async_call( DOMAIN, - SERVICE_SET_MEALPLAN, + MealieService.SET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", } | payload, blocking=True, @@ -577,12 +575,12 @@ async def test_service_set_mealplan_invalid_entry_type( with pytest.raises(ServiceValidationError): await hass.services.async_call( DOMAIN, - SERVICE_SET_MEALPLAN, + MealieService.SET_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "dessert", - ATTR_NOTE_TITLE: "Note Title", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "dessert", + MealieServiceArgument.NOTE_TITLE: "Note Title", }, blocking=True, return_response=True, @@ -601,10 +599,10 @@ async def test_service_delete_mealplan( await hass.services.async_call( DOMAIN, - SERVICE_DELETE_MEALPLAN, + MealieService.DELETE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: "16", + MealieServiceArgument.MEALPLAN_ID: "16", }, blocking=True, ) @@ -612,10 +610,10 @@ async def test_service_delete_mealplan( await hass.services.async_call( DOMAIN, - SERVICE_DELETE_MEALPLAN, + MealieService.DELETE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: 16, + MealieServiceArgument.MEALPLAN_ID: 16, }, blocking=True, ) @@ -635,10 +633,10 @@ async def test_service_delete_mealplan_not_found( with pytest.raises(ServiceValidationError, match="Mealplan with ID"): await hass.services.async_call( DOMAIN, - SERVICE_DELETE_MEALPLAN, + MealieService.DELETE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: "16", + MealieServiceArgument.MEALPLAN_ID: "16", }, blocking=True, ) @@ -650,20 +648,20 @@ async def test_service_delete_mealplan_not_found( [ ( { - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.RECIPE_ID: "recipe_id", }, {"recipe_id": "recipe_id", "note_title": None, "note_text": None}, ), ( { - ATTR_NOTE_TITLE: "Note Title", - ATTR_NOTE_TEXT: "Note Text", + MealieServiceArgument.NOTE_TITLE: "Note Title", + MealieServiceArgument.NOTE_TEXT: "Note Text", }, {"recipe_id": None, "note_title": "Note Title", "note_text": "Note Text"}, ), ( { - ATTR_NOTE_TITLE: "Note Title", + MealieServiceArgument.NOTE_TITLE: "Note Title", }, {"recipe_id": None, "note_title": "Note Title", "note_text": None}, ), @@ -683,12 +681,12 @@ async def test_service_update_mealplan( response = await hass.services.async_call( DOMAIN, - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: "16", - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.MEALPLAN_ID: "16", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", } | payload, blocking=True, @@ -702,12 +700,12 @@ async def test_service_update_mealplan( mock_mealie_client.update_mealplan.reset_mock() await hass.services.async_call( DOMAIN, - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: "16", - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.MEALPLAN_ID: "16", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", } | payload, blocking=True, @@ -720,12 +718,12 @@ async def test_service_update_mealplan( mock_mealie_client.update_mealplan.reset_mock() await hass.services.async_call( DOMAIN, - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: 16, - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", + MealieServiceArgument.MEALPLAN_ID: 16, + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", } | payload, blocking=True, @@ -749,13 +747,13 @@ async def test_service_update_mealplan_invalid_entry_type( with pytest.raises(ServiceValidationError): await hass.services.async_call( DOMAIN, - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: "16", - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "dessert", - ATTR_NOTE_TITLE: "Note Title", + MealieServiceArgument.MEALPLAN_ID: "16", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "dessert", + MealieServiceArgument.NOTE_TITLE: "Note Title", }, blocking=True, return_response=True, @@ -776,13 +774,13 @@ async def test_service_update_mealplan_not_found( with pytest.raises(ServiceValidationError, match="Mealplan with ID"): await hass.services.async_call( DOMAIN, - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_MEALPLAN_ID: "16", - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.MEALPLAN_ID: "16", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + MealieServiceArgument.RECIPE_ID: "recipe_id", }, blocking=True, return_response=True, @@ -802,7 +800,7 @@ async def test_service_get_shopping_list_items( response = await hass.services.async_call( DOMAIN, - SERVICE_GET_SHOPPING_LIST_ITEMS, + MealieService.GET_SHOPPING_LIST_ITEMS, target={"entity_id": "todo.mealie_supermarket"}, blocking=True, return_response=True, @@ -824,7 +822,7 @@ async def test_service_get_shopping_list_items_connection_error( with pytest.raises(HomeAssistantError, match="Error connecting to Mealie instance"): await hass.services.async_call( DOMAIN, - SERVICE_GET_SHOPPING_LIST_ITEMS, + MealieService.GET_SHOPPING_LIST_ITEMS, target={"entity_id": "todo.mealie_supermarket"}, blocking=True, return_response=True, @@ -854,10 +852,10 @@ async def test_service_parse_ingredient( response = await hass.services.async_call( DOMAIN, - SERVICE_PARSE_INGREDIENT, + MealieService.PARSE_INGREDIENT, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_INGREDIENT: "1 can acorn squash", + MealieServiceArgument.INGREDIENT: "1 can acorn squash", }, blocking=True, return_response=True, @@ -900,10 +898,10 @@ async def test_service_get_ingredient_parse_failure( ) as exc_info: await hass.services.async_call( DOMAIN, - SERVICE_PARSE_INGREDIENT, + MealieService.PARSE_INGREDIENT, { ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, - ATTR_INGREDIENT: "1 can acorn squash", + MealieServiceArgument.INGREDIENT: "1 can acorn squash", }, blocking=True, return_response=True, @@ -928,8 +926,8 @@ async def test_service_get_ingredient_parse_failure( ), [ pytest.param( - SERVICE_PARSE_INGREDIENT, - {ATTR_INGREDIENT: "1 can acorn squash"}, + MealieService.PARSE_INGREDIENT, + {MealieServiceArgument.INGREDIENT: "1 can acorn squash"}, "parse_ingredient", MealieConnectionError, HomeAssistantError, @@ -938,7 +936,7 @@ async def test_service_get_ingredient_parse_failure( id="parse-ingredient-connection-error", ), ( - SERVICE_GET_MEALPLAN, + MealieService.GET_MEALPLAN, {}, "get_mealplans", MealieConnectionError, @@ -947,8 +945,8 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_GET_RECIPE, - {ATTR_RECIPE_ID: "recipe_id"}, + MealieService.GET_RECIPE, + {MealieServiceArgument.RECIPE_ID: "recipe_id"}, "get_recipe", MealieConnectionError, HomeAssistantError, @@ -956,8 +954,8 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_GET_RECIPE, - {ATTR_RECIPE_ID: "recipe_id"}, + MealieService.GET_RECIPE, + {MealieServiceArgument.RECIPE_ID: "recipe_id"}, "get_recipe", MealieNotFoundError, ServiceValidationError, @@ -965,7 +963,7 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_GET_RECIPES, + MealieService.GET_RECIPES, {}, "get_recipes", MealieConnectionError, @@ -974,8 +972,8 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_GET_RECIPES, - {ATTR_SEARCH_TERMS: "pasta"}, + MealieService.GET_RECIPES, + {MealieServiceArgument.SEARCH_TERMS: "pasta"}, "get_recipes", MealieNotFoundError, ServiceValidationError, @@ -983,8 +981,8 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_IMPORT_RECIPE, - {ATTR_URL: "http://example.com"}, + MealieService.IMPORT_RECIPE, + {MealieServiceArgument.URL: "http://example.com"}, "import_recipe", MealieConnectionError, HomeAssistantError, @@ -992,8 +990,8 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_IMPORT_RECIPE, - {ATTR_URL: "http://example.com"}, + MealieService.IMPORT_RECIPE, + {MealieServiceArgument.URL: "http://example.com"}, "import_recipe", MealieValidationError, ServiceValidationError, @@ -1001,8 +999,11 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_SET_RANDOM_MEALPLAN, - {ATTR_DATE: "2023-10-21", ATTR_ENTRY_TYPE: "lunch"}, + MealieService.SET_RANDOM_MEALPLAN, + { + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + }, "random_mealplan", MealieConnectionError, HomeAssistantError, @@ -1010,11 +1011,11 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_SET_MEALPLAN, + MealieService.SET_MEALPLAN, { - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + MealieServiceArgument.RECIPE_ID: "recipe_id", }, "set_mealplan", MealieConnectionError, @@ -1023,8 +1024,8 @@ async def test_service_get_ingredient_parse_failure( True, ), ( - SERVICE_DELETE_MEALPLAN, - {ATTR_MEALPLAN_ID: "16"}, + MealieService.DELETE_MEALPLAN, + {MealieServiceArgument.MEALPLAN_ID: "16"}, "delete_mealplan", MealieConnectionError, HomeAssistantError, @@ -1032,12 +1033,12 @@ async def test_service_get_ingredient_parse_failure( False, ), ( - SERVICE_UPDATE_MEALPLAN, + MealieService.UPDATE_MEALPLAN, { - ATTR_MEALPLAN_ID: "16", - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.MEALPLAN_ID: "16", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + MealieServiceArgument.RECIPE_ID: "recipe_id", }, "update_mealplan", MealieConnectionError, @@ -1079,42 +1080,60 @@ async def test_services_connection_error( ("service", "payload", "return_response"), [ pytest.param( - SERVICE_PARSE_INGREDIENT, - {ATTR_INGREDIENT: "1 can acorn squash"}, + MealieService.PARSE_INGREDIENT, + {MealieServiceArgument.INGREDIENT: "1 can acorn squash"}, True, id="parse-ingredient", ), - (SERVICE_GET_MEALPLAN, {}, True), - (SERVICE_GET_RECIPE, {ATTR_RECIPE_ID: "recipe_id"}, True), - (SERVICE_GET_RECIPES, {}, True), + (MealieService.GET_MEALPLAN, {}, True), ( - SERVICE_GET_RECIPES, - {ATTR_SEARCH_TERMS: "pasta", ATTR_RESULT_LIMIT: 5}, + MealieService.GET_RECIPE, + {MealieServiceArgument.RECIPE_ID: "recipe_id"}, True, ), - (SERVICE_IMPORT_RECIPE, {ATTR_URL: "http://example.com"}, True), + (MealieService.GET_RECIPES, {}, True), ( - SERVICE_SET_RANDOM_MEALPLAN, - {ATTR_DATE: "2023-10-21", ATTR_ENTRY_TYPE: "lunch"}, - True, - ), - ( - SERVICE_SET_MEALPLAN, + MealieService.GET_RECIPES, { - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.SEARCH_TERMS: "pasta", + MealieServiceArgument.RESULT_LIMIT: 5, }, True, ), - (SERVICE_DELETE_MEALPLAN, {ATTR_MEALPLAN_ID: "16"}, False), ( - SERVICE_UPDATE_MEALPLAN, + MealieService.IMPORT_RECIPE, + {MealieServiceArgument.URL: "http://example.com"}, + True, + ), + ( + MealieService.SET_RANDOM_MEALPLAN, { - ATTR_MEALPLAN_ID: "16", - ATTR_DATE: "2023-10-21", - ATTR_ENTRY_TYPE: "lunch", - ATTR_RECIPE_ID: "recipe_id", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + }, + True, + ), + ( + MealieService.SET_MEALPLAN, + { + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + MealieServiceArgument.RECIPE_ID: "recipe_id", + }, + True, + ), + ( + MealieService.DELETE_MEALPLAN, + {MealieServiceArgument.MEALPLAN_ID: "16"}, + False, + ), + ( + MealieService.UPDATE_MEALPLAN, + { + MealieServiceArgument.MEALPLAN_ID: "16", + MealieServiceArgument.DATE: "2023-10-21", + MealieServiceArgument.ENTRY_TYPE: "lunch", + MealieServiceArgument.RECIPE_ID: "recipe_id", }, True, ),