Core Architecture: DataUpdateCoordinator & Diagnostics Integration#98
Conversation
…n and sanitization Co-authored-by: sirkirby <740137+sirkirby@users.noreply.github.com>
Co-authored-by: sirkirby <740137+sirkirby@users.noreply.github.com>
|
@copilot this branch should be merging into |
Branch has been rebased onto |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the UniFi Network Rules integration by improving DataUpdateCoordinator usage and adding comprehensive diagnostics capabilities. The changes focus on leveraging Home Assistant's built-in coordinator patterns more effectively while providing better troubleshooting tools through automated data sanitization and diagnostics export.
- Refactored refresh mechanisms to use DataUpdateCoordinator's
async_request_refresh()instead of custom semaphore handling - Added comprehensive diagnostics system with automatic sensitive data sanitization
- Enhanced failure handling by leveraging coordinator's built-in backoff and throttling mechanisms
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_coordinator_diagnostics.py |
Adds comprehensive test coverage for coordinator failure scenarios and diagnostics functionality |
tests/conftest.py |
Updates test fixture to remove deprecated event_loop parameter |
custom_components/unifi_network_rules/utils/diagnostics.py |
Implements sanitization, coordinator stats collection, and diagnostics export functionality |
custom_components/unifi_network_rules/diagnostics.py |
Adds Home Assistant integration for diagnostics export |
custom_components/unifi_network_rules/coordinator.py |
Updates coordinator to use DataUpdateCoordinator patterns and improved error handling |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot the test are now failing based on committing review suggestions. I see that in utils/diagnostics.py that the HEX_TOKEN_PATTERN and the ALNUM_TOKEN_PATTERN constants which should contain the regular expressions are not defined. There may be other issues as well |
Co-authored-by: sirkirby <740137+sirkirby@users.noreply.github.com>
Fixed both issues in commit 9529485:
All 36 tests are now passing with no regressions. |
This PR refactors the data refresh logic to use Home Assistant's DataUpdateCoordinator patterns more effectively and adds comprehensive diagnostics export for easier troubleshooting.
Key Improvements
🔄 Enhanced DataUpdateCoordinator Integration
_controlled_refresh_wrapper()and_force_refresh_with_cache_clear()with DataUpdateCoordinator's built-inasync_request_refresh()_handle_auth_failure()to leverage coordinator's automatic backoff and throttling instead of manual timing🔍 Comprehensive Diagnostics System
diagnostics.pyfile that integrates with HA's built-in diagnostics framework🛡️ Security & Privacy
The diagnostics system automatically sanitizes sensitive data:
🧪 Robust Testing
Benefits
Usage
Users can now export comprehensive diagnostics through Home Assistant's standard diagnostics interface, providing sanitized snapshots of configuration, recent events, and coordinator health metrics for troubleshooting.
Fixes #92.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.