Skip to content

Commit 40451bd

Browse files
authored
Filter out grinders during CF in lamarzocco (home-assistant#176289)
1 parent 29c4629 commit 40451bd

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

homeassistant/components/lamarzocco/config_flow.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from aiohttp import ClientSession
99
from pylamarzocco import LaMarzoccoCloudClient
10+
from pylamarzocco.const import DeviceType
1011
from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful
1112
from pylamarzocco.models import Thing
1213
from pylamarzocco.util import InstallationKey, generate_installation_key
@@ -105,7 +106,11 @@ async def async_step_user(
105106
_LOGGER.error("Error connecting to server: %s", exc)
106107
errors["base"] = "cannot_connect"
107108
else:
108-
self._things = {thing.serial_number: thing for thing in things}
109+
self._things = {
110+
thing.serial_number: thing
111+
for thing in things
112+
if thing.type is DeviceType.MACHINE
113+
}
109114
if not self._things:
110115
errors["base"] = "no_machines"
111116

tests/components/lamarzocco/test_config_flow.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from copy import deepcopy
55
from unittest.mock import AsyncMock, MagicMock, patch
66

7-
from pylamarzocco.const import ModelName
7+
from pylamarzocco.const import DeviceType, ModelName
88
from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful
9+
from pylamarzocco.models import Thing
910
import pytest
1011

1112
from homeassistant.components.lamarzocco.config_flow import CONF_MACHINE
@@ -35,7 +36,7 @@
3536
get_bluetooth_service_info,
3637
)
3738

38-
from tests.common import MockConfigEntry
39+
from tests.common import MockConfigEntry, async_load_json_object_fixture
3940

4041

4142
@pytest.fixture(autouse=True)
@@ -197,6 +198,30 @@ async def test_form_no_machines(
197198
await __do_sucessful_machine_selection_step(hass, result)
198199

199200

201+
async def test_grinders_not_configurable(
202+
hass: HomeAssistant,
203+
mock_cloud_client: MagicMock,
204+
) -> None:
205+
"""Test that grinders are filtered out so only machines can be configured."""
206+
grinder = await async_load_json_object_fixture(hass, "thing.json", DOMAIN)
207+
grinder["type"] = DeviceType.GRINDER
208+
grinder["serialNumber"] = "GR012345"
209+
grinder["name"] = "GR012345"
210+
211+
mock_cloud_client.list_things.return_value = [
212+
*mock_cloud_client.list_things.return_value,
213+
Thing.from_dict(grinder),
214+
]
215+
216+
result = await hass.config_entries.flow.async_init(
217+
DOMAIN, context={"source": SOURCE_USER}
218+
)
219+
result = await __do_successful_user_step(hass, result, mock_cloud_client)
220+
221+
options = result["data_schema"].schema[CONF_MACHINE].config["options"]
222+
assert [option["value"] for option in options] == ["GS012345"]
223+
224+
200225
async def test_reauth_flow(
201226
hass: HomeAssistant,
202227
mock_cloud_client: MagicMock,

0 commit comments

Comments
 (0)