diff --git a/homeassistant/components/lamarzocco/config_flow.py b/homeassistant/components/lamarzocco/config_flow.py index 3a85a01c3fc8..a072b6edeff3 100644 --- a/homeassistant/components/lamarzocco/config_flow.py +++ b/homeassistant/components/lamarzocco/config_flow.py @@ -7,6 +7,7 @@ import uuid from aiohttp import ClientSession from pylamarzocco import LaMarzoccoCloudClient +from pylamarzocco.const import DeviceType from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful from pylamarzocco.models import Thing from pylamarzocco.util import InstallationKey, generate_installation_key @@ -105,7 +106,11 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.error("Error connecting to server: %s", exc) errors["base"] = "cannot_connect" else: - self._things = {thing.serial_number: thing for thing in things} + self._things = { + thing.serial_number: thing + for thing in things + if thing.type is DeviceType.MACHINE + } if not self._things: errors["base"] = "no_machines" diff --git a/tests/components/lamarzocco/test_config_flow.py b/tests/components/lamarzocco/test_config_flow.py index 5106b6db6e99..5af778f31d3a 100644 --- a/tests/components/lamarzocco/test_config_flow.py +++ b/tests/components/lamarzocco/test_config_flow.py @@ -4,8 +4,9 @@ from collections.abc import Generator from copy import deepcopy from unittest.mock import AsyncMock, MagicMock, patch -from pylamarzocco.const import ModelName +from pylamarzocco.const import DeviceType, ModelName from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful +from pylamarzocco.models import Thing import pytest from homeassistant.components.lamarzocco.config_flow import CONF_MACHINE @@ -35,7 +36,7 @@ from . import ( get_bluetooth_service_info, ) -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, async_load_json_object_fixture @pytest.fixture(autouse=True) @@ -197,6 +198,30 @@ async def test_form_no_machines( await __do_sucessful_machine_selection_step(hass, result) +async def test_grinders_not_configurable( + hass: HomeAssistant, + mock_cloud_client: MagicMock, +) -> None: + """Test that grinders are filtered out so only machines can be configured.""" + grinder = await async_load_json_object_fixture(hass, "thing.json", DOMAIN) + grinder["type"] = DeviceType.GRINDER + grinder["serialNumber"] = "GR012345" + grinder["name"] = "GR012345" + + mock_cloud_client.list_things.return_value = [ + *mock_cloud_client.list_things.return_value, + Thing.from_dict(grinder), + ] + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + result = await __do_successful_user_step(hass, result, mock_cloud_client) + + options = result["data_schema"].schema[CONF_MACHINE].config["options"] + assert [option["value"] for option in options] == ["GS012345"] + + async def test_reauth_flow( hass: HomeAssistant, mock_cloud_client: MagicMock,