Skip to content

Feat/port profile switch entities - #100

Merged
sirkirby merged 2 commits into
devfrom
feat/port-profile-switch-entities
Aug 29, 2025
Merged

Feat/port profile switch entities#100
sirkirby merged 2 commits into
devfrom
feat/port-profile-switch-entities

Conversation

@sirkirby

@sirkirby sirkirby commented Aug 26, 2025

Copy link
Copy Markdown
Owner

New feature adding switch support for all networks, including WAN, LAN, and new UniFi WAN magic, along with Port Profile switches. Based on the requested features #87 and #99

This pull request adds support for managing UniFi network and port profile entities within the coordinator, improves VPN client/server derivation by using network data, and enhances helper functions to better handle these new types. The changes increase feature coverage and robustness for entity management and naming.

Entity management and feature expansion:

  • Added support for storing and updating port_profiles and networks in the coordinator, including new async update methods (_update_port_profiles_in_dict, _update_networks_in_dict) and updates to the coordinator's state and refresh logic. [1] [2] [3] [4] [5] [6] [7]
  • Improved VPN client and server derivation by extracting these entities from the already-fetched network data, with fallback to the API if needed. This increases reliability and reduces unnecessary API calls. [1] [2]

Helper and utility enhancements:

  • Updated helper functions in helpers/rule.py to handle NetworkConf and PortProfile types for enabled state, ID generation, descriptive naming, and rule type prefixing. Also added logic to filter out VPN networks for switch entities. [1] [2] [3] [4] [5] [6] [7]

Code robustness and cleanup:

  • Improved error handling and logging throughout new update methods and VPN derivation logic to ensure resilience against API failures and conversion errors. [1] [2]
  • Minor code cleanup and refactoring, such as removing unused imports and improving variable naming for clarity in authentication error handling and forced refresh logic. [1] [2] [3] [4] [5]

These changes collectively improve the coordinator's ability to track and manage new types of UniFi entities, provide better naming and identification, and ensure robust operation during API or conversion errors.

…d filtering

- Updated the UnifiRuleUpdateCoordinator to derive VPN clients and servers from existing network data, improving efficiency and accuracy.
- Introduced a new helper function to filter out VPN networks, ensuring only suitable networks are exposed as switch entities.
- Added methods for updating and toggling network configurations in the API, enhancing network management capabilities.
- Improved error handling and logging for network operations.
@sirkirby sirkirby self-assigned this Aug 26, 2025
@sirkirby sirkirby added the enhancement New feature or request label Aug 26, 2025
@sirkirby
sirkirby requested a review from Copilot August 27, 2025 18:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for managing UniFi networks and port profiles as switch entities in Home Assistant, expanding the integration beyond just traditional firewall rules. The key enhancement is the ability to toggle network and port profile states directly from the Home Assistant UI.

  • Added NetworkConf and PortProfile typed models with computed enabled states
  • Extended the coordinator to fetch and manage networks and port profiles alongside existing entities
  • Created new switch entity classes for networks and port profiles with proper toggle functionality

Reviewed Changes

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

Show a summary per file
File Description
udm/profiles.py Added toggle_port_profile method to enable/disable port profiles by managing native network assignment
udm/network.py Added network management methods including get_networks, update_network, and toggle_network
switch.py Added UnifiPortProfileSwitch and UnifiNetworkSwitch entity classes with toggle logic and state attributes
models/port_profile.py New typed model for port profiles with computed enabled state based on native network configuration
models/network.py New typed model for network configurations with purpose and enabled state accessors
helpers/rule.py Extended helper functions to support NetworkConf and PortProfile types, added VPN network filtering
coordinator.py Added port profile and network data management, improved VPN derivation from network data

Comment thread custom_components/unifi_network_rules/udm/profiles.py
Comment thread custom_components/unifi_network_rules/udm/network.py
Comment thread custom_components/unifi_network_rules/switch.py
Comment thread custom_components/unifi_network_rules/models/network.py
Comment thread custom_components/unifi_network_rules/coordinator.py
@sirkirby
sirkirby marked this pull request as ready for review August 27, 2025 19:10
@sirkirby
sirkirby merged commit 9f9e24a into dev Aug 29, 2025
9 checks passed
@sirkirby
sirkirby deleted the feat/port-profile-switch-entities branch August 29, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants