From d9cef1e7080d69b01d6a75fca5f5c074119ba03b Mon Sep 17 00:00:00 2001 From: Josef Zweck <24647999+zweckj@users.noreply.github.com> Date: Sat, 30 Nov 2024 04:31:56 +0100 Subject: [PATCH] Guard against hostname change in lamarzocco discovery (#131873) * Guard against hostname change in lamarzocco discovery * switch to abort_entries_match --- .../components/lamarzocco/config_flow.py | 1 + .../components/lamarzocco/test_config_flow.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/homeassistant/components/lamarzocco/config_flow.py b/homeassistant/components/lamarzocco/config_flow.py index 0f288e22c4a..a727e3fe357 100644 --- a/homeassistant/components/lamarzocco/config_flow.py +++ b/homeassistant/components/lamarzocco/config_flow.py @@ -291,6 +291,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): CONF_ADDRESS: discovery_info.macaddress, } ) + self._async_abort_entries_match({CONF_ADDRESS: discovery_info.macaddress}) _LOGGER.debug( "Discovered La Marzocco machine %s through DHCP at address %s", diff --git a/tests/components/lamarzocco/test_config_flow.py b/tests/components/lamarzocco/test_config_flow.py index f8103ac3054..b206b7b68a3 100644 --- a/tests/components/lamarzocco/test_config_flow.py +++ b/tests/components/lamarzocco/test_config_flow.py @@ -493,6 +493,27 @@ async def test_dhcp_discovery( } +async def test_dhcp_discovery_abort_on_hostname_changed( + hass: HomeAssistant, + mock_lamarzocco: MagicMock, + mock_cloud_client: MagicMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test dhcp discovery aborts when hostname was changed manually.""" + mock_config_entry.add_to_hass(hass) + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_DHCP}, + data=DhcpServiceInfo( + ip="192.168.1.42", + hostname="custom_name", + macaddress="00:00:00:00:00:00", + ), + ) + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" + + async def test_dhcp_already_configured_and_update( hass: HomeAssistant, mock_lamarzocco: MagicMock,