Guard against hostname change in lamarzocco discovery (#131873)

* Guard against hostname change in lamarzocco discovery

* switch to abort_entries_match
This commit is contained in:
Josef Zweck 2024-11-30 04:31:56 +01:00 committed by GitHub
parent a760786faf
commit d9cef1e708
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -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",

View File

@ -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,