Skip to content

Introduce observe entity for display#7189

Open
TimoPtr wants to merge 2 commits into
mainfrom
feature/obverse_entity_state_for_display
Open

Introduce observe entity for display#7189
TimoPtr wants to merge 2 commits into
mainfrom
feature/obverse_entity_state_for_display

Conversation

@TimoPtr

@TimoPtr TimoPtr commented Jul 16, 2026

Copy link
Copy Markdown
Member

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 obverse capability to the GetEntityForDisplayUseCase so that a consumer can get the entity updates from the WebSocket when available. I replace the invoke operator with a snapshot method.

I tested the observe method by simply replacing the snapshot per a observe in the ManageTileViewModel and the entities were properly updating within the UI when the state was changing.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Any other notes

I'm not sure if we should use observe instead of snapshot in the EntityPicker. @jpelgrom wdyt?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 updated EntityDisplayState.Loaded snapshots when entity states/registries change, and renamed the old entry points to snapshot(...).
  • Refactored display resolution so EntityDisplayItem can be constructed from an Entity to 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.

Comment on lines +63 to +65
val coordinates: EntityCoordinates? = null,
/** Alarm panel display information, only set for `alarm_control_panel` entities. */
val alarm: AlarmDisplay? = null,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@TimoPtr
TimoPtr force-pushed the feature/entity_extension_context_free branch from ff4698d to 79d050d Compare July 17, 2026 07:59
@TimoPtr
TimoPtr force-pushed the feature/obverse_entity_state_for_display branch from 32efdf6 to 45808fe Compare July 17, 2026 07:59
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Test Results

  276 files    278 suites   19m 34s ⏱️
2 433 tests 2 430 ✅ 2 💤 1 ❌
2 465 runs  2 462 ✅ 2 💤 1 ❌

For more details on these failures, see this check.

Results for commit 7c91332.

♻️ This comment has been updated with latest results.

@TimoPtr
TimoPtr force-pushed the feature/entity_extension_context_free branch from 79d050d to 876c428 Compare July 17, 2026 09:42
@TimoPtr
TimoPtr force-pushed the feature/obverse_entity_state_for_display branch from 45808fe to 09f0a07 Compare July 17, 2026 09:44
@TimoPtr
TimoPtr force-pushed the feature/entity_extension_context_free branch from 876c428 to aab31e8 Compare July 20, 2026 07:20
@TimoPtr
TimoPtr force-pushed the feature/obverse_entity_state_for_display branch 2 times, most recently from d9d9a56 to 3956afd Compare July 20, 2026 09:53
@jpelgrom

jpelgrom commented Jul 20, 2026

Copy link
Copy Markdown
Member

I'm not sure if we should use observe instead of snapshot in the EntityPicker. @jpelgrom wdyt?

I think we shouldn't use observe unless there is a need to keep things live, to limit data use and recompositions - a picker that just loaded should be fine with snapshot, not expecting it to go out of date.

@TimoPtr

TimoPtr commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

I'm not sure if we should use observe instead of snapshot in the EntityPicker. @jpelgrom wdyt?

I think we shouldn't use observe unless there is a need to keep things live, to limit data use and recompositions - a picker that just loaded should be fine with snapshot, not expecting it to go out of date.

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.

Base automatically changed from feature/entity_extension_context_free to main July 20, 2026 13:33
@TimoPtr
TimoPtr force-pushed the feature/obverse_entity_state_for_display branch from 3956afd to bdc62e5 Compare July 20, 2026 13:43
@TimoPtr
TimoPtr force-pushed the feature/obverse_entity_state_for_display branch from 2ee00a1 to 7c91332 Compare July 20, 2026 14:36
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.

Offer a observe method to get update of Entities to be displayed

3 participants