Skip to content

Add WAN status sensors to UniFi integration#166918

Open
cln-io wants to merge 1 commit intohome-assistant:devfrom
cln-io:unifi-wan-status-sensor
Open

Add WAN status sensors to UniFi integration#166918
cln-io wants to merge 1 commit intohome-assistant:devfrom
cln-io:unifi-wan-status-sensor

Conversation

@cln-io
Copy link
Copy Markdown

@cln-io cln-io commented Mar 30, 2026

Bump aiounifi from 88 to 90, which exposes WAN TypedDicts, device properties needed for WAN sensor data, and SSO 2FA support.

Add per-interface WAN Status enum sensors (online/offline) for up to 6 WAN interfaces, disabled by default. Non-existent WANs are filtered out per-device via supported_fn.

Breaking change

N/A — this PR only adds new sensors, no existing functionality is changed.

Proposed change

Add WAN Status enum sensors to the UniFi integration for gateway devices (UDM, UCG, EFG, etc.).

For each WAN interface (up to 6, matching the UXG Fiber's max port count):

  • Status (online/offline enum)

All sensors are disabled by default and classified as EntityCategory.DIAGNOSTIC. The supported_fn check ensures sensors only appear for WANs that actually exist on each device.

This is PR 1 of 5, split from #164818 per reviewer request. The full series:

  1. WAN Status sensors + aiounifi bump (this PR)
  2. WAN IP Address, Availability, Latency sensors
  3. WAN RX/TX Rate sensors
  4. Active WAN sensor
  5. Speedtest sensors

Dependency

Bumps aiounifi from 88 to 90, which includes:

Changes

sensor.py:

  • async_device_wan_status_supported_fn — checks specific WAN interface presence in device.raw
  • async_device_wan_status_value_fn — reads from device.last_wan_status
  • make_wan_status_sensors() factory generating status sensors for WAN1–WAN6

strings.json:

  • Added wan_status translation key with online/offline states

manifest.json / requirements_all.txt / requirements_test_all.txt:

  • aiounifi 88 → 90

Testing

Verified against a live UCG Ultra (UDRULT) with dual-WAN:

  • WAN Status correctly reports online for both WANs
  • WAN Status correctly transitions to offline when a WAN is disconnected
  • Sensors for non-existent WANs (WAN3–6) do not appear

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:

Bump aiounifi from 88 to 90, which exposes WAN TypedDicts, device
properties needed for WAN sensor data, and SSO 2FA support.

Add per-interface WAN Status enum sensors (online/offline) for
up to 6 WAN interfaces, disabled by default. Non-existent WANs
are filtered out per-device via supported_fn.
@home-assistant
Copy link
Copy Markdown

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 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 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new diagnostic WAN status enum sensors to the UniFi integration (for gateway devices), enabled via an aiounifi dependency bump that exposes the required WAN fields.

Changes:

  • Bump aiounifi from 88 → 90 across integration manifest and pinned requirements.
  • Add factory-generated WAN status (online/offline) enum sensors for WAN1–WAN6, disabled by default and filtered per-device.
  • Add wan_status enum state translations and a new unit test covering online→offline transitions.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
homeassistant/components/unifi/sensor.py Adds supported/value helpers plus a factory to create up to 6 WAN status enum sensors and registers them with existing entity descriptions.
homeassistant/components/unifi/strings.json Adds translations for wan_status enum states (online/offline).
homeassistant/components/unifi/manifest.json Pins UniFi integration dependency to aiounifi==90.
requirements_all.txt Updates global pinned aiounifi version to 90.
requirements_test_all.txt Updates test pinned aiounifi version to 90.
tests/components/unifi/test_sensor.py Adds a WAN-status sensor test using a gateway device payload and websocket updates.


# WAN3-6 sensors should not exist (no data)
assert entity_registry.async_get("sensor.gateway_wan3_status") is None
assert entity_registry.async_get("sensor.gateway_wan4_status") is None
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

Align the test with the comment by either asserting WAN5/WAN6 are also absent or updating the comment to match the actual assertions.

Suggested change
assert entity_registry.async_get("sensor.gateway_wan4_status") is None
assert entity_registry.async_get("sensor.gateway_wan4_status") is None
assert entity_registry.async_get("sensor.gateway_wan5_status") is None
assert entity_registry.async_get("sensor.gateway_wan6_status") is None

Copilot uses AI. Check for mistakes.
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 Integration - UCG Ultra no internet status?

3 participants