Introduce observe entity for display#7189
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the GetEntitiesForDisplayUseCase API to support continuous updates via a new observe(...) Flow (driven by entity state changes and registry update events) while replacing the previous invoke operator usage with explicit snapshot(...) methods for one-time resolution.
Changes:
- Added
GetEntitiesForDisplayUseCase.observe(...)to emit updatedEntityDisplayState.Loadedsnapshots when entity states/registries change, and renamed the old entry points tosnapshot(...). - Refactored display resolution so
EntityDisplayItemcan be constructed from anEntityto resolve state-derived fields once (state, raw state, active/executing, coordinates, alarm metadata). - Updated callers and tests to use
snapshot(...), and added comprehensive Turbine-based tests covering observe behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/integration/display/GetEntitiesForDisplayUseCase.kt | Introduces observe(...), refactors registry snapshot fetching, and renames one-shot API to snapshot(...). |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/integration/display/EntityDisplayItem.kt | Expands EntityDisplayItem to include entity-derived display fields and adds a constructor that resolves them from an Entity. |
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/integration/display/GetEntitiesForDisplayUseCaseTest.kt | Updates snapshot tests and adds a new nested test suite validating observe(...) update behavior. |
| app/src/test/kotlin/io/homeassistant/companion/android/settings/qs/ManageTilesViewModelTest.kt | Updates mocks to the new snapshot(...) API. |
| app/src/main/kotlin/io/homeassistant/companion/android/widgets/todo/TodoWidgetConfigureViewModel.kt | Switches to getEntitiesForDisplay.snapshot(...). |
| app/src/main/kotlin/io/homeassistant/companion/android/util/compose/entity/EntityPicker.kt | Uses the EntityDisplayItem(Entity) constructor for metadata-free display mapping. |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/vehicle/ManageAndroidAutoViewModel.kt | Switches to getEntitiesForDisplay.snapshot(...). |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/shortcuts/legacy/ManageShortcutsViewModel.kt | Switches to getEntitiesForDisplay.snapshot(...). |
| app/src/main/kotlin/io/homeassistant/companion/android/settings/qs/ManageTilesViewModel.kt | Switches to getEntitiesForDisplay.snapshot(...). |
| app/src/full/kotlin/io/homeassistant/companion/android/settings/wear/views/SettingsWearFavoritesView.kt | Replaces EntityDisplayItem.from(entity) with the new constructor. |
| val coordinates: EntityCoordinates? = null, | ||
| /** Alarm panel display information, only set for `alarm_control_panel` entities. */ | ||
| val alarm: AlarmDisplay? = null, |
There was a problem hiding this comment.
@jpelgrom I was going to introduce a sealed class on top of the EntityDisplayItem but I'm not sure at the moment and went with the null approach and kept a generic entity.
ff4698d to
79d050d
Compare
32efdf6 to
45808fe
Compare
Test Results 276 files 278 suites 19m 34s ⏱️ For more details on these failures, see this check. Results for commit 7c91332. ♻️ This comment has been updated with latest results. |
79d050d to
876c428
Compare
45808fe to
09f0a07
Compare
876c428 to
aab31e8
Compare
d9d9a56 to
3956afd
Compare
I think we shouldn't use |
That's the direction I've followed in this PR but I wanted your opinion. It's nice to see the list updating but I think probably overkill. |
3956afd to
bdc62e5
Compare
Remove AlarmDisplay from this PR
2ee00a1 to
7c91332
Compare
Summary
In the automotive screen we are going to need to be able to have updates of the entity that we are going to be display. This PR add the
obversecapability to theGetEntityForDisplayUseCaseso that a consumer can get the entity updates from the WebSocket when available. I replace the invoke operator with asnapshotmethod.I tested the
observemethod by simply replacing the snapshot per a observe in theManageTileViewModeland the entities were properly updating within the UI when the state was changing.Checklist
Any other notes
I'm not sure if we should use
observeinstead ofsnapshotin the EntityPicker. @jpelgrom wdyt?