Skip to content

Conversation

@bgoncal
Copy link
Member

@bgoncal bgoncal commented Jan 6, 2026

Summary

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

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.
@bgoncal bgoncal self-assigned this Jan 6, 2026
Copilot AI review requested due to automatic review settings January 6, 2026 03:17
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

⚠️ Unused L10n strings detected

Found 1 unused localization strings in the codebase.

Click to see details
Parsing Strings.swift...
Found 1298 L10n strings

Reading all Swift source code...
Read 4959088 characters of Swift code

Checking for unused strings...
Checked 100/1298 strings...
Checked 200/1298 strings...
Checked 300/1298 strings...
Checked 400/1298 strings...
Checked 500/1298 strings...
Checked 600/1298 strings...
Checked 700/1298 strings...
Checked 800/1298 strings...
Checked 900/1298 strings...
Checked 1000/1298 strings...
Checked 1100/1298 strings...
Checked 1200/1298 strings...

================================================================================
UNUSED STRINGS REPORT
================================================================================

Found 1 unused strings:


WATCH:
  - L10n.Watch.Labels.noAction
    Key: watch.labels.no_action
    Line: 3986

================================================================================
Total unused: 1
================================================================================

To clean up these strings, manually remove them from the Localizable.strings files
and regenerate Strings.swift using SwiftGen.

Copy link
Contributor

Copilot AI left a 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 EntityRegistryEntry and DeviceRegistryEntry models with corresponding database tables (AppEntityRegistry and AppDeviceRegistry)
  • Updates AppDatabaseUpdater to fetch and persist registry data every 2 minutes (changed from 5 seconds)
  • Refactors AreasService and 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

@bgoncal bgoncal enabled auto-merge (squash) January 6, 2026 03:24
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 42.18415% with 270 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@8cdfb4f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ources/Shared/Environment/AppDatabaseUpdater.swift 0.98% 101 Missing ⚠️
Sources/Extensions/EntityProvider+Details.swift 0.00% 63 Missing ⚠️
Sources/Shared/Environment/EntityRegistry.swift 58.58% 41 Missing ⚠️
...urces/Shared/Environment/DeviceRegistryEntry.swift 59.30% 35 Missing ⚠️
Sources/Shared/AreasService.swift 13.33% 13 Missing ⚠️
Sources/Shared/ControlEntityProvider.swift 0.00% 13 Missing ⚠️
Sources/Shared/HATypedRequest+App.swift 0.00% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal bgoncal merged commit 39be820 into main Jan 6, 2026
17 checks passed
@bgoncal bgoncal deleted the persist-device-registry branch January 6, 2026 04:00
@bgoncal bgoncal restored the persist-device-registry branch January 6, 2026 10:06
@bgoncal bgoncal deleted the persist-device-registry branch January 6, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants