Skip to content

Simplying LED api integration and state managmenet - #86

Merged
sirkirby merged 3 commits into
devfrom
trigger_cleanup
Jul 30, 2025
Merged

Simplying LED api integration and state managmenet#86
sirkirby merged 3 commits into
devfrom
trigger_cleanup

Conversation

@sirkirby

Copy link
Copy Markdown
Owner

This pull request refines the UniFi Network Rules integration to focus exclusively on managing LED-capable devices, improving clarity, consistency, and functionality. Key changes include narrowing the scope of device state monitoring to LED-specific states, enhancing data handling by using typed Device objects, and improving logging and trigger mechanisms for LED state changes.

Refactoring for LED State Monitoring:

  • Updated _check_for_device_state_changes to monitor only LED state changes, removing connection state handling. Added device lookups for full Device objects to ensure consistent trigger payloads. [1] [2] [3] [4]
  • Adjusted _async_update_data to reflect the narrowed scope by renaming checks to "LED State Changes."

Enhanced Data Handling:

  • Replaced raw LED state dictionaries with typed Device objects in get_device_led_states, simplifying device creation and ensuring consistency with other components. [1] [2]
  • Simplified _update_devices_in_dict by directly using Device objects from the API, removing redundant manual object creation.

Improved Trigger Mechanisms:

  • Updated triggers to handle only LED state changes and clarified trigger descriptions in trigger.py. [1] [2]
  • Enhanced _async_toggle_rule to include optimistic state updates for immediate triggers, ensuring consistency with rule-based triggers.

Logging and Documentation:

  • Improved logging messages to clearly distinguish LED-related operations, including HA-initiated and external changes. [1] [2]
  • Updated docstrings and comments to reflect the LED-focused scope of the integration, improving maintainability. [1] [2]

… integration and state mangement

- Updated the device state change detection method in `coordinator.py` to specifically monitor LED state changes for managed devices.
- Improved logging to clarify the nature of state changes being detected and dispatched.
- Refactored the immediate trigger firing in `switch.py` to utilize full device objects for consistency with rule triggers.
- Adjusted the API call in `network.py` to return properly typed Device objects for LED-capable devices, enhancing integration reliability.
- Updated trigger descriptions in `trigger.py` to reflect the focus on LED state changes.
@sirkirby
sirkirby requested a review from Copilot July 30, 2025 14:45
@sirkirby sirkirby self-assigned this Jul 30, 2025
@sirkirby sirkirby added the enhancement New feature or request label Jul 30, 2025

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 pull request refactors the UniFi Network Rules integration to focus exclusively on LED state management for access points, removing connection state monitoring and improving data handling consistency. The changes streamline the codebase by using typed Device objects throughout and enhance trigger mechanisms for LED state changes.

Key changes include:

  • Refactored device state monitoring to focus only on LED state changes, removing connection state handling
  • Enhanced data handling by returning typed Device objects instead of raw dictionaries from the API
  • Improved trigger mechanisms with optimistic state updates and better logging for LED operations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
coordinator.py Refactored device state monitoring to focus on LED changes only, improved logging and trigger handling
udm/network.py Changed get_device_led_states to return typed Device objects instead of dictionaries
switch.py Enhanced LED toggle function with optimistic state updates for immediate triggers
trigger.py Updated trigger descriptions to clarify LED-focused scope

Comment thread custom_components/unifi_network_rules/trigger.py
Comment thread custom_components/unifi_network_rules/udm/network.py Outdated
Comment thread custom_components/unifi_network_rules/coordinator.py Outdated
sirkirby and others added 2 commits July 30, 2025 10:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sirkirby
sirkirby merged commit 8f65668 into dev Jul 30, 2025
9 checks passed
@sirkirby
sirkirby deleted the trigger_cleanup branch July 30, 2025 14:51
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