Skip to content

Reference

Cookidoo API package.

Cookidoo

Unofficial Cookidoo API interface.

Init function for Bring API.

Parameters:

Name Type Description Default
session ClientSession

The client session for aiohttp requests

required
cfg CookidooConfig

Cookidoo config

DEFAULT_COOKIDOO_CONFIG
Source code in cookidoo_api/cookidoo.py
def __init__(
    self,
    session: ClientSession,
    cfg: CookidooConfig = DEFAULT_COOKIDOO_CONFIG,
) -> None:
    """Init function for Bring API.

    Parameters
    ----------
    session
        The client session for aiohttp requests
    cfg
        Cookidoo config


    """
    self._session = session
    self._cfg = cfg
    self._token_headers = DEFAULT_TOKEN_HEADERS.copy()
    self._api_headers = DEFAULT_API_HEADERS.copy()
    self.__expires_in: int
    self._auth_data = None

localization: CookidooLocalizationConfig property

Localization.

expires_in: int property writable

Refresh token expiration.

auth_data: CookidooAuthResponse | None property writable

Auth data.

api_endpoint: URL property

Get the api endpoint.

refresh_token async

Try to refresh the token.

Returns:

Type Description
CookidooAuthResponse

The auth response object.

Raises:

Type Description
CookidooConfigException

If no login has happened yet

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

CookidooAuthException

If the login fails due invalid credentials. You should check your email and password.

Source code in cookidoo_api/cookidoo.py
async def refresh_token(self) -> CookidooAuthResponse:
    """Try to refresh the token.

    Returns
    -------
    CookidooAuthResponse
        The auth response object.

    Raises
    ------
    CookidooConfigException
        If no login has happened yet
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.
    CookidooAuthException
        If the login fails due invalid credentials.
        You should check your email and password.

    """
    if not self._auth_data:
        raise CookidooConfigException("No auth data available, please log in first")

    refresh_data = FormData()
    refresh_data.add_field("grant_type", "refresh_token")
    refresh_data.add_field("refresh_token", self._auth_data["refresh_token"])
    refresh_data.add_field("client_id", COOKIDOO_CLIENT_ID)

    return await self._request_access_token(refresh_data)

login async

Try to login.

Returns:

Type Description
CookidooAuthResponse

The auth response object.

Raises:

Type Description
CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

CookidooAuthException

If the login fails due invalid credentials. You should check your email and password.

Source code in cookidoo_api/cookidoo.py
async def login(self) -> CookidooAuthResponse:
    """Try to login.

    Returns
    -------
    CookidooAuthResponse
        The auth response object.

    Raises
    ------
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.
    CookidooAuthException
        If the login fails due invalid credentials.
        You should check your email and password.

    """
    user_data = FormData()
    user_data.add_field("grant_type", "password")
    user_data.add_field("username", self._cfg["email"])
    user_data.add_field("password", self._cfg["password"])

    return await self._request_access_token(user_data)

get_user_info async

Get user info.

Returns:

Type Description
CookidooUserInfo

The user info

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def get_user_info(
    self,
) -> CookidooUserInfo:
    """Get user info.

    Returns
    -------
    CookidooUserInfo
        The user info

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """

    try:
        url = self.api_endpoint / COMMUNITY_PROFILE_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.get(url, headers=self._api_headers) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot get user info: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Loading user info failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()

            try:
                return cast(
                    CookidooUserInfo,
                    {
                        key: val
                        for key, val in (await r.json())["userInfo"].items()
                        if key in CookidooUserInfo.__annotations__
                    },
                )

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get user info:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading user info failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot get user info:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading user info failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot user info:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading user info failed due to request exception."
        ) from e

get_active_subscription async

Get active subscription if any.

Returns:

Type Description
CookidooSubscription

The active subscription

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def get_active_subscription(
    self,
) -> CookidooSubscription | None:
    """Get active subscription if any.

    Returns
    -------
    CookidooSubscription
        The active subscription

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """

    try:
        url = self.api_endpoint / SUBSCRIPTIONS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.get(url, headers=self._api_headers) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot get active subscription: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Loading active subscription failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()

            try:
                if subscription := next(
                    (
                        subscription
                        for subscription in (await r.json())
                        if subscription["active"]
                    ),
                    None,
                ):
                    return cast(
                        CookidooSubscription,
                        {
                            key: val
                            for key, val in subscription.items()
                            if key in CookidooSubscription.__annotations__
                        },
                    )
                else:
                    return None

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get active subscription:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading active subscription failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot get active subscription:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading user info failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot active subscription:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading active subscription failed due to request exception."
        ) from e

get_ingredients async

Get recipe items.

Returns:

Type Description
list[CookidooItem]

The list of the recipe items

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def get_ingredients(
    self,
) -> list[CookidooItem]:
    """Get recipe items.

    Returns
    -------
    list[CookidooItem]
        The list of the recipe items

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """

    try:
        url = self.api_endpoint / INGREDIENTS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.get(url, headers=self._api_headers) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot get recipe items: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Loading recipe items failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()

            try:
                return [
                    cookidoo_item_from_ingredient(cast(IngredientJSON, ingredient))
                    for recipe in (await r.json())["recipes"]
                    for ingredient in recipe["recipeIngredientGroups"]
                ]

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get recipe items:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading recipe items failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot get recipe items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading recipe items failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot recipe items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading recipe items failed due to request exception."
        ) from e

add_ingredients_for_recipes async

Add ingredients for recipes.

Parameters:

Name Type Description Default
recipe_ids list[str]

The recipe ids for the ingredients to add to the shopping list

required

Returns:

Type Description
list[CookidooItem]

The list of the added ingredients

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def add_ingredients_for_recipes(
    self,
    recipe_ids: list[str],
) -> list[CookidooItem]:
    """Add ingredients for recipes.

    Parameters
    ----------
    recipe_ids
        The recipe ids for the ingredients to add to the shopping list

    Returns
    -------
    list[CookidooItem]
        The list of the added ingredients

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {"recipeIDs": recipe_ids}
    try:
        url = self.api_endpoint / ADD_INGREDIENTS_FOR_RECIPES_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot add ingredients for recipes: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Add ingredients for recipes failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
            try:
                return [
                    cookidoo_item_from_ingredient(cast(IngredientJSON, ingredient))
                    for recipe in (await r.json())["data"]
                    for ingredient in recipe["recipeIngredientGroups"]
                ]
            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get added ingredients:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading added ingredients failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute add ingredients for recipes:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Add ingredients for recipes failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute add ingredients for recipes:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Add ingredients for recipes failed due to request exception."
        ) from e

remove_ingredients_for_recipes async

Remove ingredients for recipes.

Parameters:

Name Type Description Default
recipe_ids list[str]

The recipe ids for the ingredients to remove to the shopping list

required

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def remove_ingredients_for_recipes(
    self,
    recipe_ids: list[str],
) -> None:
    """Remove ingredients for recipes.

    Parameters
    ----------
    recipe_ids
        The recipe ids for the ingredients to remove to the shopping list

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {"recipeIDs": recipe_ids}
    try:
        url = self.api_endpoint / REMOVE_INGREDIENTS_FOR_RECIPES_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot remove ingredients for recipes: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Remove ingredients for recipes failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute remove ingredients for recipes:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Remove ingredients for recipes failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute remove ingredients for recipes:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Remove ingredients for recipes failed due to request exception."
        ) from e

edit_ingredients_ownership async

Edit ownership recipe items.

Parameters:

Name Type Description Default
ingredients list[CookidooItem]

The recipe items to change the the is_owned value for

required

Returns:

Type Description
list[CookidooItem]

The list of the edited recipe items

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def edit_ingredients_ownership(
    self,
    ingredients: list[CookidooItem],
) -> list[CookidooItem]:
    """Edit ownership recipe items.

    Parameters
    ----------
    ingredients
        The recipe items to change the the `is_owned` value for

    Returns
    -------
    list[CookidooItem]
        The list of the edited recipe items

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {
        "ingredients": [
            {
                "id": ingredient["id"],
                "isOwned": ingredient["isOwned"],
                "ownedTimestamp": int(time.time()),
            }
            for ingredient in ingredients
        ]
    }
    try:
        url = self.api_endpoint / EDIT_OWNERSHIP_INGREDIENTS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot edit recipe item ownership: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Edit recipe items ownership failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
            try:
                return [
                    cookidoo_item_from_ingredient(cast(IngredientJSON, ingredient))
                    for ingredient in (await r.json())["data"]
                ]

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get edited recipe items:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading edited recipe items failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute edit recipe items ownership:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Edit recipe items ownership failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute edit recipe items ownership:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Edit recipe items ownership failed due to request exception."
        ) from e

get_additional_items async

Get additional items.

Returns:

Type Description
list[CookidooItem]

The list of the additional items

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def get_additional_items(
    self,
) -> list[CookidooItem]:
    """Get additional items.

    Returns
    -------
    list[CookidooItem]
        The list of the additional items

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """

    try:
        url = self.api_endpoint / ADDITIONAL_ITEMS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.get(url, headers=self._api_headers) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot get additional items: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Loading additional items failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()

            try:
                return [
                    cast(
                        CookidooItem,
                        {
                            key: val
                            for key, val in additional_item.items()
                            if key in CookidooItem.__annotations__
                        },
                    )
                    for additional_item in (await r.json())["additionalItems"]
                ]

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get additional items:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading additional items failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot get additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading additional items failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Loading additional items failed due to request exception."
        ) from e

add_additional_items async

Create additional items.

Parameters:

Name Type Description Default
additional_item_names list[str]

The additional item names to create, only the label can be set, as the default state is_owned=false is forced (chain with immediate update call for work-around)

required

Returns:

Type Description
list[CookidooItem]

The list of the added additional items

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def add_additional_items(
    self,
    additional_item_names: list[str],
) -> list[CookidooItem]:
    """Create additional items.

    Parameters
    ----------
    additional_item_names
        The additional item names to create, only the label can be set, as the default state `is_owned=false` is forced (chain with immediate update call for work-around)

    Returns
    -------
    list[CookidooItem]
        The list of the added additional items

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {"itemsValue": additional_item_names}
    try:
        url = self.api_endpoint / ADD_ADDITIONAL_ITEMS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot add additional items: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Add additional items failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
            try:
                return [
                    cast(CookidooItem, additional_item)
                    for additional_item in (await r.json())["data"]
                ]

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get added additional items:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading added additional items failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute add additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Add additional items failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute add additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Add additional items failed due to request exception."
        ) from e

edit_additional_items async

Edit additional items.

Parameters:

Name Type Description Default
additional_items list[CookidooItem]

The additional items to change the the name value for

required

Returns:

Type Description
list[CookidooItem]

The list of the edited additional items

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def edit_additional_items(
    self,
    additional_items: list[CookidooItem],
) -> list[CookidooItem]:
    """Edit additional items.

    Parameters
    ----------
    additional_items
        The additional items to change the the `name` value for

    Returns
    -------
    list[CookidooItem]
        The list of the edited additional items

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {
        "additionalItems": [
            {
                "id": additional_item["id"],
                "name": additional_item["name"],
            }
            for additional_item in additional_items
        ]
    }
    try:
        url = self.api_endpoint / EDIT_ADDITIONAL_ITEMS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot edit additional items: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Edit additional items failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
            try:
                return [
                    cast(CookidooItem, additional_item)
                    for additional_item in (await r.json())["data"]
                ]

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get edited additional items:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading edited additional items failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute edit additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Edit additional items failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute edit additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Edit additional items failed due to request exception."
        ) from e

edit_additional_items_ownership async

Edit ownership additional items.

Parameters:

Name Type Description Default
additional_items list[CookidooItem]

The additional items to change the the is_owned value for

required

Returns:

Type Description
list[CookidooItem]

The list of the edited additional items

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def edit_additional_items_ownership(
    self,
    additional_items: list[CookidooItem],
) -> list[CookidooItem]:
    """Edit ownership additional items.

    Parameters
    ----------
    additional_items
        The additional items to change the the `is_owned` value for

    Returns
    -------
    list[CookidooItem]
        The list of the edited additional items

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {
        "additionalItems": [
            {
                "id": additional_item["id"],
                "isOwned": additional_item["isOwned"],
                "ownedTimestamp": int(time.time()),
            }
            for additional_item in additional_items
        ]
    }
    try:
        url = self.api_endpoint / EDIT_OWNERSHIP_ADDITIONAL_ITEMS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot edit additional items ownership: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Edit additional items ownership failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
            try:
                return [
                    cast(CookidooItem, additional_item)
                    for additional_item in (await r.json())["data"]
                ]

            except (JSONDecodeError, KeyError) as e:
                _LOGGER.debug(
                    "Exception: Cannot get edited additional items:\n%s",
                    traceback.format_exc(),
                )
                raise CookidooParseException(
                    "Loading edited additional items failed during parsing of request response."
                ) from e
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute edit additional items ownership:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Edit additional items ownership failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute edit additional items ownership:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Edit additional items ownership failed due to request exception."
        ) from e

remove_additional_items async

Remove additional items.

Parameters:

Name Type Description Default
additional_item_ids list[str]

The additional item ids to remove

required

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def remove_additional_items(
    self,
    additional_item_ids: list[str],
) -> None:
    """Remove additional items.

    Parameters
    ----------
    additional_item_ids
        The additional item ids to remove

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    json_data = {"additionalItemIDs": additional_item_ids}
    try:
        url = self.api_endpoint / REMOVE_ADDITIONAL_ITEMS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.post(
            url, headers=self._api_headers, json=json_data
        ) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot remove additional items: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Remove additional items failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute remove additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Remove additional items failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute remove additional items:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Remove additional items failed due to request exception."
        ) from e

clear_shopping_list async

Remove all additional items, ingredients and recipes.

Raises:

Type Description
CookidooAuthException

When the access token is not valid anymore

CookidooRequestException

If the request fails.

CookidooParseException

If the parsing of the request response fails.

Source code in cookidoo_api/cookidoo.py
async def clear_shopping_list(
    self,
) -> None:
    """Remove all additional items, ingredients and recipes.

    Raises
    ------
    CookidooAuthException
        When the access token is not valid anymore
    CookidooRequestException
        If the request fails.
    CookidooParseException
        If the parsing of the request response fails.

    """
    try:
        url = self.api_endpoint / INGREDIENTS_PATH.format(
            **self._cfg["localization"]
        )
        async with self._session.delete(url, headers=self._api_headers) as r:
            _LOGGER.debug(
                "Response from %s [%s]: %s", url, r.status, await r.text()
            )

            if r.status == HTTPStatus.UNAUTHORIZED:
                try:
                    errmsg = await r.json()
                except (JSONDecodeError, ClientError):
                    _LOGGER.debug(
                        "Exception: Cannot parse request response:\n %s",
                        traceback.format_exc(),
                    )
                else:
                    _LOGGER.debug(
                        "Exception: Cannot clear shopping list: %s",
                        errmsg["error_description"],
                    )
                raise CookidooAuthException(
                    "Clear shopping list failed due to authorization failure, "
                    "the authorization token is invalid or expired."
                )

            r.raise_for_status()
    except TimeoutError as e:
        _LOGGER.debug(
            "Exception: Cannot execute clear shopping list:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Clear shopping list failed due to connection timeout."
        ) from e
    except ClientError as e:
        _LOGGER.debug(
            "Exception: Cannot execute clear shopping list:\n%s",
            traceback.format_exc(),
        )
        raise CookidooRequestException(
            "Clear shopping list failed due to request exception."
        ) from e

CookidooAuthException

Bases: CookidooException

When an authentication error is encountered.

CookidooConfigException

Bases: CookidooException

When the config is invalid.

CookidooException

Bases: Exception

General exception occurred.

CookidooParseException

Bases: CookidooException

When data could not be parsed.

CookidooRequestException

Bases: CookidooException

When a request returns an error.

CookidooResponseException

Bases: CookidooException

When a response could not be parsed.

CookidooUnavailableException

Bases: CookidooException

When the network or server is not available.

CookidooAuthResponse

Bases: TypedDict

An auth response class.

CookidooConfig

Bases: TypedDict

Cookidoo config type.

Attributes:

Name Type Description
localization CookidooLocalizationConfig

The localization for the api including country, language and url

email str

The email to login

password str

The password to login

CookidooItem

Bases: TypedDict

Cookidoo item type.

Attributes:

Name Type Description
id str

The id of the item

name str

The label of the item

description str | None

The description of the item, including the quantity or other helpful information

isOwned bool

Whether the items is checked or not

CookidooLocalizationConfig

Bases: TypedDict

A localization config class.

CookidooSubscription

Bases: TypedDict

A subscription class.

CookidooUserInfo

Bases: TypedDict

A user info class.

get_country_options async

Get a list of possible country options.

Source code in cookidoo_api/helpers.py
async def get_country_options() -> list[str]:
    """Get a list of possible country options."""
    return list({option["country_code"] for option in await get_localization_options()})

get_language_options async

Get a list of possible language options.

Source code in cookidoo_api/helpers.py
async def get_language_options() -> list[str]:
    """Get a list of possible language options."""
    return list({option["language"] for option in await get_localization_options()})

get_localization_options async

Get a list of possible localization options.

Source code in cookidoo_api/helpers.py
async def get_localization_options(
    country: str | None = None,
    language: str | None = None,
) -> list[CookidooLocalizationConfig]:
    """Get a list of possible localization options."""
    return await asyncio.get_running_loop().run_in_executor(
        None, __get_localization_options, country, language
    )