-
Notifications
You must be signed in to change notification settings - Fork 408
Persist Entity and Device registry #4157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduces EntityProvider+Details.swift to provide area and device lookup methods for HAAppEntity. Also increases the minimum interval between database updates from 5 to 120 seconds in AppDatabaseUpdater.
Introduced extensions on [HAAppEntity] to provide areasMap(for:) and devicesMap(for:) methods, enabling efficient mapping of entity IDs to their associated AppArea and AppDeviceRegistry objects for a given server. Also refactored area and device properties on HAAppEntity to computed properties for improved API consistency.
Adds areaName and deviceName to IntentLightEntity and improves subtitle display. Entity filtering now matches device and area names in addition to entity name and ID. Refactors area/device mapping logic for better reuse and clarity.
Enhanced Cover, Fan, Switch, and AppIntent entities to include areaName and deviceName properties. Updated displayRepresentation to show these as subtitles, improving context in UI. Refactored entity queries to fetch and assign area and device names, and streamlined filtering logic.
Refactored MagicItemAddViewModel to build entity subtitles using area and device names, falling back to entityId if needed. Simplified area fetching in EntityProvider+Details and fixed entity config handling in EntityPickerViewModel.
|
Found 1 unused localization strings in the codebase. Click to see detailsTo clean up these strings, manually remove them from the |
There was a problem hiding this comment.
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 persistence for Entity and Device registry data by introducing database-backed storage to reduce API calls and improve performance. The changes migrate from real-time API fetching to cached database reads with periodic background updates.
Key Changes
- Introduces
EntityRegistryEntryandDeviceRegistryEntrymodels with corresponding database tables (AppEntityRegistryandAppDeviceRegistry) - Updates
AppDatabaseUpdaterto fetch and persist registry data every 2 minutes (changed from 5 seconds) - Refactors
AreasServiceand widget components to read from database instead of making API calls - Adds device and area information to widget entity display representations for improved context
Reviewed changes
Copilot reviewed 24 out of 26 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/Shared/Environment/EntityRegistry.swift | New model for entity registry with database persistence support |
| Sources/Shared/Environment/DeviceRegistryEntry.swift | New model for device registry entries with HAData decoding |
| Sources/Shared/Environment/DeviceRegistry.swift | Duplicate definition of DeviceRegistryEntry with inconsistent property types |
| Sources/Shared/Database/AppEntityRegistryTable.swift | Database table schema for entity registry persistence |
| Sources/Shared/Database/AppDeviceRegistryTable.swift | Database table schema for device registry persistence |
| Sources/Shared/Environment/AppDatabaseUpdater.swift | Updates to fetch and persist registry data, increases update interval to 120s |
| Sources/Shared/AreasService.swift | Refactored to read entity and device data from database instead of API |
| Sources/Shared/ControlEntityProvider.swift | Enhanced search to include device name matching |
| Sources/Extensions/EntityProvider+Details.swift | Helper methods for mapping entities to areas and devices |
| Sources/Extensions/Widgets/HAAppEntityAppIntentEntity.swift | Added area and device name to entity display with subtitle formatting |
| Sources/Extensions/Widgets/Controls//IntentEntity.swift | Applied similar area/device display enhancements across all control types |
| Sources/App/Settings/MagicItem/EntityPickerViewModel.swift | Updated to use non-optional entity config result |
| Sources/App/Settings/MagicItem/Add/MagicItemAddViewModel.swift | Enhanced subtitle display with area and device information |
| Tests/Shared/Models/EntityRegistry.test.swift | Test coverage for entity registry JSON decoding |
| Tests/Shared/Models/DeviceRegistry.test.swift | Test coverage for device registry JSON decoding |
| Tests/App/Area/AreasService.test.swift | Updated test helpers to use new registry types |
| Sources/Shared/HATypedRequest+App.swift | Updated type signatures to use new registry models |
| Sources/Shared/HAAreasRegistryResponse.swift | Removed deprecated entity and device registry response types |
Sources/Extensions/Widgets/Controls/Cover/IntentCoverEntity.swift
Outdated
Show resolved
Hide resolved
Sources/Extensions/Widgets/Controls/Light/IntentLightEntity.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4157 +/- ##
=======================================
Coverage ? 45.18%
=======================================
Files ? 249
Lines ? 14285
Branches ? 0
=======================================
Hits ? 6454
Misses ? 7831
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes