Skip to content

Expose UniFi Policy Engine rules as switches#169675

Draft
ryanr14 wants to merge 2 commits intohome-assistant:devfrom
ryanr14:add-unifi-policy-engine-switches
Draft

Expose UniFi Policy Engine rules as switches#169675
ryanr14 wants to merge 2 commits intohome-assistant:devfrom
ryanr14:add-unifi-policy-engine-switches

Conversation

@ryanr14
Copy link
Copy Markdown

@ryanr14 ryanr14 commented May 3, 2026

Proposed change

Expose supported UniFi Policy Engine / Object-Oriented Network rules as switch entities.

The UniFi Network application creates simple Policy Engine rules, such as "turn off internet" rules, as object-oriented network configs at /object-oriented-network-configs. Those configs then generate predefined firewall policy rows, but the predefined firewall policy rows are not controllable directly and are filtered out by the existing firewall-policy switch support.

This adds a new switch description backed by api.object_oriented_network_configs so Home Assistant can list and toggle the underlying Policy Engine rule itself. The switch description is intentionally constrained to secure internet rules with mode: TURN_OFF_INTERNET so route/QoS-style object-oriented configs are not duplicated with the existing traffic route support.

Depends on aiounifi==91 from:

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

Related background:

Checklist

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

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings May 3, 2026 03:08
@home-assistant home-assistant Bot added cla-needed has-tests integration: unifi Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage labels May 3, 2026
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @ryanr14

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 3, 2026

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.

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 UniFi Policy Engine (object-oriented network config) rules as controllable switch entities in the UniFi integration, enabling Home Assistant to toggle “simple rules” (e.g., “turn off internet”) that are not represented by the existing firewall-policy switch support.

Changes:

  • Add a new switch entity description backed by api.object_oriented_network_configs to expose Policy Engine rules as switches.
  • Add polling coordination for object_oriented_network_configs to keep state updated after toggles.
  • Bump aiounifi dependency to ==91 and add/extend tests and fixtures for the new endpoint.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
homeassistant/components/unifi/switch.py Introduces a new switch description and control function for Policy Engine rules via object_oriented_network_configs.
homeassistant/components/unifi/hub/entity_loader.py Adds a polling UnifiDataUpdateCoordinator for object-oriented network configs to refresh state.
homeassistant/components/unifi/manifest.json Updates integration requirement to aiounifi==91.
requirements_all.txt Updates global dependency pin to aiounifi==91.
requirements_test_all.txt Updates test dependency pin to aiounifi==91.
tests/components/unifi/conftest.py Adds fixture payload + GET mocking for /object-oriented-network-configs.
tests/components/unifi/test_switch.py Adds coverage for listing/toggling Policy Engine rule switches and expected API calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed has-tests integration: unifi Quality Scale: silver Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants