Fix key error in Reolink DHCP if still setting up (#164619)

This commit is contained in:
starkillerOG
2026-03-03 16:12:30 +01:00
committed by GitHub
parent 73b28f1ee2
commit abef46864e
2 changed files with 36 additions and 0 deletions

View File

@@ -159,6 +159,15 @@ class ReolinkFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle discovery via dhcp."""
mac_address = format_mac(discovery_info.macaddress)
existing_entry = await self.async_set_unique_id(mac_address)
if existing_entry and CONF_HOST not in existing_entry.data:
_LOGGER.debug(
"Reolink DHCP discovered device with MAC '%s' and IP '%s', "
"but existing config entry does not have host, ignoring",
mac_address,
discovery_info.ip,
)
raise AbortFlow("already_configured")
if (
existing_entry
and CONF_PASSWORD in existing_entry.data

View File

@@ -608,6 +608,33 @@ async def test_dhcp_ip_update_aborted_if_wrong_mac(
assert config_entry.data[CONF_HOST] == TEST_HOST
async def test_dhcp_ip_update_aborted_if_no_host(hass: HomeAssistant) -> None:
"""Test dhcp discovery does not update the IP if the config entry has no host."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id=format_mac(TEST_MAC),
data={},
options={
CONF_PROTOCOL: DEFAULT_PROTOCOL,
},
title=TEST_NVR_NAME,
)
config_entry.add_to_hass(hass)
dhcp_data = DhcpServiceInfo(
ip=TEST_HOST2,
hostname="Reolink",
macaddress=DHCP_FORMATTED_MAC,
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dhcp_data
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
@pytest.mark.parametrize(
("attr", "value", "expected", "host_call_list"),
[