Skip to content

Use state-aware icons for Wear OS shortcut tiles#6618

Draft
kdavh wants to merge 4 commits intohome-assistant:mainfrom
kdavh:state-aware-shortcut-tile-icons
Draft

Use state-aware icons for Wear OS shortcut tiles#6618
kdavh wants to merge 4 commits intohome-assistant:mainfrom
kdavh:state-aware-shortcut-tile-icons

Conversation

@kdavh
Copy link
Copy Markdown

@kdavh kdavh commented Mar 23, 2026

Summary

Shortcut tiles on Wear OS currently use domain-based fallback icons that don't reflect entity state. For example, a lock entity always shows the same padlock icon regardless of whether it's locked or unlocked.

This change fetches full entity state from the server when building tile resources, and uses Entity.getIcon() to resolve state-aware icons. The fallback to domain-based icons via getIcon(icon, domain, context) is preserved when the full entity can't be fetched.

Before: All lock entities show the same generic padlock icon.
After: Locked entities show a closed padlock, unlocked entities show an open padlock (and similar state-aware icons for other domains like covers, fans, etc.).

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.

Screenshots

Fallback icons (no entity state):

tile_screenshot

State-aware icons (locked vs unlocked):

tile_screenshot_stateaware

Any other notes

  • The icon resolution follows the same pattern already used in Entity.getIcon() throughout the app — state-aware icons are only used when the entity doesn't have a custom icon attribute set.
  • Each entity is fetched concurrently via async to minimize latency.
  • If any entity fetch fails (e.g., server unreachable), it gracefully falls back to the domain-based icon, so there is no regression in offline or error scenarios.

Copilot AI review requested due to automatic review settings March 23, 2026 14:55
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @khart-twilio

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft March 23, 2026 14:55
@home-assistant
Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copy link
Copy Markdown
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

Updates Wear OS shortcut tiles to use state-aware icons (via full entity state + Entity.getIcon()), improving visual accuracy (e.g., locked vs unlocked) while preserving the existing domain-based fallback behavior.

Changes:

  • Fetch full entity state for shortcut entries when building tile resources and resolve icons via Entity.getIcon()
  • Keep domain-based fallback icon resolution when entity fetch fails
  • Add a Wear changelog entry describing the user-visible change

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
wear/src/main/kotlin/io/homeassistant/companion/android/tiles/ShortcutsTile.kt Concurrently fetches full entity state and uses state-aware icon resolution for tile resources
app/src/main/res/xml/changelog_master.xml Documents the Wear shortcut tile icon behavior change

Comment thread wear/src/main/kotlin/io/homeassistant/companion/android/tiles/ShortcutsTile.kt Outdated
Comment thread wear/src/main/kotlin/io/homeassistant/companion/android/tiles/ShortcutsTile.kt Outdated
Comment on lines 123 to +131
Resources.Builder()
.setVersion(entities.toString())
.apply {
entities.map { entity ->
// Find icon and create Bitmap
val iconIIcon = getIcon(
entity.icon,
entity.domain,
this@ShortcutsTile,
)
// Find icon: try state-aware icon from full entity, fall back to domain icon
val fullEntity = entityMap[entity.entityId]
val iconIIcon = if (fullEntity != null) {
fullEntity.getIcon(this@ShortcutsTile)
} else {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Resources.Builder().setVersion(entities.toString()) is still based only on the shortcut list, but the actual icon bitmaps now depend on live entity state. This can cause cached resources to keep showing an outdated icon (e.g., locked icon after unlocking) because the resource version may not change. Consider including relevant state in the version (or otherwise forcing a refresh/update strategy) so state changes invalidate cached resources.

Copilot uses AI. Check for mistakes.
@dshokouhi
Copy link
Copy Markdown
Member

Has the situation described in #2045 get resolved now? Last I recall we could not reliably add this because its very easy for the state to get out of sync.

@kdavh kdavh marked this pull request as ready for review March 23, 2026 15:01
@kdavh kdavh marked this pull request as draft March 23, 2026 15:06
kdavh and others added 3 commits March 23, 2026 13:04
  Shortcut tiles previously used the same icon regardless of entity state. This switches to using Entity.getIcon(), which returns state-specific icons for locks, fans, switches, covers, and more — matching the behavior already used in complications and other tiles.

Full entities are fetched in parallel to minimize latency, with a graceful fallback to the original domain-only icon if a fetch fails. Custom icons set in Home Assistant are still respected.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rethrow CancellationException instead of swallowing it in catch block
- Add Timber.w logging for failed entity fetches
- Wrap entity fetch in serverManager.isRegistered() check

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kdavh kdavh force-pushed the state-aware-shortcut-tile-icons branch from 3bdbd68 to 9189b98 Compare March 23, 2026 17:52
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @kdavh

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

…t tiles

Include entity state in the tile resource version string so Wear OS
invalidates cached icon bitmaps when entity state changes. Previously
the version only reflected which entities were configured, causing
stale icons to persist indefinitely.

Also add a loading indicator (progress clock icon) when an entity is
tapped. The tile polls for state changes at 1s and 4s after tap,
clearing the loading state once the entity state has changed or after
a 5s timeout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

3 participants