Conversation
… handling in network.py to send only essential fields, preventing InvalidPayload errors on older UniFi Network versions.
Updated network API to send only essential fields, preventing InvalidPayload errors on older UniFi Network versions
…ity with older UniFi Network versions. Implemented a dual approach using DeviceSetLedStatus with a fallback to a minimal payload, enhancing error handling and logging for better debugging.
Refactor LED toggle functionality in network.py to use DeviceSetLedStatus with fallback
- Corrected typos in the coding standards section of the rules file. - Added a new copilot instructions file outlining the project structure, libraries, and coding standards for the custom Home Assistant integration.
- Implemented a new method in `coordinator.py` to check for device state changes and fire corresponding triggers. - Enhanced `fire_device_trigger_via_dispatcher` to dispatch device change events using Home Assistant's dispatcher pattern. - Updated `switch.py` to fire immediate device triggers for LED toggles, improving responsiveness. - Added support for device change triggers in `trigger.py`, allowing for manual firing and filtering based on device ID and change type. - Improved logging for device trigger events to facilitate better monitoring and debugging.
- Introduced a new trigger for device changes to enhance the integration's capabilities. - Updated the triggers.yaml file to include the 'device_changed' rule so HA properly registers the new trigger.
- now using aiounifi type Device for LED API integration and coordinator data - removing device state management as that is no longer in scope of this integration - other minor updates to comments and trigger functionality
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces device LED state change detection and triggering capabilities to the UniFi Network Rules integration, along with code quality improvements and documentation updates. The primary focus is on enabling Home Assistant automations to respond to LED state changes on UniFi devices.
- Added device change detection with immediate and polling-based LED state monitoring
- Implemented new
device_changedtrigger type with dispatcher-based event handling - Enhanced LED device management with proper Device object typing and state tracking
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| custom_components/unifi_network_rules/udm/network.py | Refactored get_device_led_states to return typed Device objects instead of raw dictionaries |
| custom_components/unifi_network_rules/triggers.yaml | Added device_changed trigger type configuration |
| custom_components/unifi_network_rules/trigger.py | Implemented device trigger handling with dispatcher pattern and filtering |
| custom_components/unifi_network_rules/switch.py | Added immediate trigger firing for LED toggles with optimistic state updates |
| custom_components/unifi_network_rules/manifest.json | Updated version from 3.1.0 to 3.2.0 |
| custom_components/unifi_network_rules/coordinator.py | Added device state change detection and dispatcher-based trigger firing |
| .github/copilot-instructions.md | Added project documentation with structure and coding standards |
| .cursor/rules/unr-rules.mdc | Fixed spelling errors in coding practices documentation |
Comments suppressed due to low confidence (2)
custom_components/unifi_network_rules/switch.py:594
- The LED state values 'default' and 'off' should be defined as constants to avoid magic strings and improve maintainability.
return True
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several enhancements and fixes to the custom Home Assistant integration for managing UniFi Network policies and rules. The most significant changes include the addition of device LED state change detection and triggering, improved logging and dispatcher patterns, documentation updates, and minor corrections to coding standards and spelling errors.
fixes #84
New Features and Enhancements:
Device LED State Change Detection and Triggering:
fire_device_trigger_via_dispatcherand_check_for_device_state_changesincoordinator.py). [1] [2]switch.pyfile to improve responsiveness (_async_toggle_rulemethod).Improved Logging and Dispatcher Patterns:
LOG_TRIGGERSto enable or disable logging for triggers. [1] [2]Documentation Updates:
.github/copilot-instructions.mdfile to provide a detailed overview of the project, including directory structure, libraries, and coding standards.Bug Fixes and Code Quality Improvements:
Spelling Corrections:
.cursor/rules/unr-rules.mdc(e.g., "fuctionality" → "functionality", "retrived" → "retrieved"). [1] [2]Version Update:
manifest.jsonfrom3.1.0to3.2.0.