mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Prevent multiple dhcp flows from being started for the same device/domain (#65753)
This commit is contained in:
parent
2bcd4f8f93
commit
adbc0e5955
@ -179,6 +179,7 @@ class WatcherBase:
|
|||||||
lowercase_hostname,
|
lowercase_hostname,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
matched_domains = set()
|
||||||
for entry in self._integration_matchers:
|
for entry in self._integration_matchers:
|
||||||
if MAC_ADDRESS in entry and not fnmatch.fnmatch(
|
if MAC_ADDRESS in entry and not fnmatch.fnmatch(
|
||||||
uppercase_mac, entry[MAC_ADDRESS]
|
uppercase_mac, entry[MAC_ADDRESS]
|
||||||
@ -191,6 +192,11 @@ class WatcherBase:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
_LOGGER.debug("Matched %s against %s", data, entry)
|
_LOGGER.debug("Matched %s against %s", data, entry)
|
||||||
|
if entry["domain"] in matched_domains:
|
||||||
|
# Only match once per domain
|
||||||
|
continue
|
||||||
|
|
||||||
|
matched_domains.add(entry["domain"])
|
||||||
discovery_flow.async_create_flow(
|
discovery_flow.async_create_flow(
|
||||||
self.hass,
|
self.hass,
|
||||||
entry["domain"],
|
entry["domain"],
|
||||||
|
@ -255,6 +255,33 @@ async def test_dhcp_match_macaddress(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_dhcp_multiple_match_only_one_flow(hass):
|
||||||
|
"""Test matching the domain multiple times only generates one flow."""
|
||||||
|
integration_matchers = [
|
||||||
|
{"domain": "mock-domain", "macaddress": "B8B7F1*"},
|
||||||
|
{"domain": "mock-domain", "hostname": "connect"},
|
||||||
|
]
|
||||||
|
|
||||||
|
packet = Ether(RAW_DHCP_REQUEST)
|
||||||
|
|
||||||
|
async_handle_dhcp_packet = await _async_get_handle_dhcp_packet(
|
||||||
|
hass, integration_matchers
|
||||||
|
)
|
||||||
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
|
await async_handle_dhcp_packet(packet)
|
||||||
|
|
||||||
|
assert len(mock_init.mock_calls) == 1
|
||||||
|
assert mock_init.mock_calls[0][1][0] == "mock-domain"
|
||||||
|
assert mock_init.mock_calls[0][2]["context"] == {
|
||||||
|
"source": config_entries.SOURCE_DHCP
|
||||||
|
}
|
||||||
|
assert mock_init.mock_calls[0][2]["data"] == dhcp.DhcpServiceInfo(
|
||||||
|
ip="192.168.210.56",
|
||||||
|
hostname="connect",
|
||||||
|
macaddress="b8b7f16db533",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_dhcp_match_macaddress_without_hostname(hass):
|
async def test_dhcp_match_macaddress_without_hostname(hass):
|
||||||
"""Test matching based on macaddress only."""
|
"""Test matching based on macaddress only."""
|
||||||
integration_matchers = [{"domain": "mock-domain", "macaddress": "606BBD*"}]
|
integration_matchers = [{"domain": "mock-domain", "macaddress": "606BBD*"}]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user