Match UniFi discovery against every address a console announces - #180343
Match UniFi discovery against every address a console announces#180343RaHehl wants to merge 1 commit into
Conversation
|
Hey there @imhotep, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Hey there @Kane610, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Updates UniFi discovery matching to recognize all console-announced interface addresses and prevent duplicate integrations.
Changes:
- Derives and propagates announced console IP addresses.
- Matches UniFi Network and Access entries across interfaces.
- Adds regression coverage for filtering, matching, and host refreshes.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/unifi_discovery/discovery.py |
Derives announced IP addresses. |
homeassistant/components/unifi/config_flow.py |
Expands host matching and prioritizes MAC matching. |
homeassistant/components/unifi_access/config_flow.py |
Matches manual entries against announced addresses. |
tests/components/unifi_discovery/test_init.py |
Tests address extraction and filtering. |
tests/components/unifi/test_config_flow.py |
Tests cross-interface matching and host refresh. |
tests/components/unifi_access/test_config_flow.py |
Tests matching and unique-ID assignment. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def _announced_ips(device: UnifiDevice) -> list[str]: | ||
| """Return the IPs a device announced as its own. | ||
|
|
||
| A console answers discovery on every VLAN interface it has and lists them | ||
| in ``ip_info`` as ``"mac;ip"``, alongside ``primary_addr``. Only one of |
| async def test_discovery_matches_other_announced_address( | ||
| hass: HomeAssistant, mock_client: MagicMock | ||
| ) -> None: |
Proposed change
A console answers discovery on every VLAN interface it has, but unifi-discovery
collapses those answers into one device and reports whichever
source_ipcarried the most fields. An entry configured on another interface therefore did
not match and the console was offered as a new device. For
unifithe unique IDdoes not help either: configured entries carry the site ID, so
_abort_if_unique_id_configurednever matches a discovery flow keyed by MAC.The console announces its interfaces in the payload, so
unifi_discoverynowderives
announced_ipsfromip_infoandprimary_addr, and both consumersmatch against it. Doing it in the dispatcher keeps the protocol knowledge in one
place instead of three.
ip_infoalso lists addresses that are not the device's own (upstream WAN,neighbouring hosts, all-zero placeholders), so only entries whose MAC shares the
first five octets with
hw_addrare kept. The OUI alone would pull in everyother Ubiquiti device on the network.
For
unifithe unique ID check moved ahead of the host match, so a MAC-keyedentry still gets its host refreshed. For
unifi_accessthe same match is whatstamps the MAC onto a manually created entry, which previously could not happen
for a console reached on another interface.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: