Skip to content

Match UniFi discovery against every address a console announces - #180343

Open
RaHehl wants to merge 1 commit into
home-assistant:devfrom
RaHehl:unifi-discovery-vlan-hosts
Open

Match UniFi discovery against every address a console announces#180343
RaHehl wants to merge 1 commit into
home-assistant:devfrom
RaHehl:unifi-discovery-vlan-hosts

Conversation

@RaHehl

@RaHehl RaHehl commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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_ip
carried the most fields. An entry configured on another interface therefore did
not match and the console was offered as a new device. For unifi the unique ID
does not help either: configured entries carry the site ID, so
_abort_if_unique_id_configured never matches a discovery flow keyed by MAC.

The console announces its interfaces in the payload, so unifi_discovery now
derives announced_ips from ip_info and primary_addr, and both consumers
match against it. Doing it in the dispatcher keeps the protocol knowledge in one
place instead of three.

ip_info also 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_addr are kept. The OUI alone would pull in every
other Ubiquiti device on the network.

For unifi the unique ID check moved ahead of the host match, so a MAC-keyed
entry still gets its host refreshed. For unifi_access the same match is what
stamps the MAC onto a manually created entry, which previously could not happen
for a console reached on another interface.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI balanced review requested due to automatic review settings August 26, 2026 20:18
@RaHehl
RaHehl requested a review from Kane610 as a code owner August 26, 2026 20:18
@home-assistant home-assistant Bot added bugfix cla-signed has-tests integration: unifi integration: unifi_access integration: unifi_discovery Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage labels Aug 26, 2026
@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @imhotep, mind taking a look at this pull request as it has been labeled with an integration (unifi_access) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of unifi_access can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign unifi_access Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @Kane610, mind taking a look at this pull request as it has been labeled with an integration (unifi) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of unifi can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign unifi Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +27 to +31
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
Comment on lines +752 to +754
async def test_discovery_matches_other_announced_address(
hass: HomeAssistant, mock_client: MagicMock
) -> None:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UniFi Network reports new device "UDM-Pro-Max" when "UDM Pro Max" (no dashes) is already present

4 participants