Skip to content

Commit 6add42f

Browse files
kdavhkhart-twilio
authored andcommitted
Use state-aware icons for Wear OS shortcut tiles
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.
1 parent 79d5fa6 commit 6add42f

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

wear/src/main/kotlin/io/homeassistant/companion/android/tiles/ShortcutsTile.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ import io.homeassistant.companion.android.common.R as commonR
3838
import io.homeassistant.companion.android.common.data.prefs.WearPrefsRepository
3939
import io.homeassistant.companion.android.common.data.servers.ServerManager
4040
import io.homeassistant.companion.android.data.SimplifiedEntity
41+
import io.homeassistant.companion.android.common.data.integration.getIcon
4142
import io.homeassistant.companion.android.util.getIcon
4243
import java.nio.ByteBuffer
4344
import javax.inject.Inject
4445
import kotlin.math.min
4546
import kotlin.math.roundToInt
47+
import kotlinx.coroutines.async
4648
import kotlinx.coroutines.CoroutineScope
4749
import kotlinx.coroutines.Dispatchers
4850
import kotlinx.coroutines.Job
@@ -107,16 +109,32 @@ class ShortcutsTile : TileService() {
107109
val iconSizePx = (iconSize * density).roundToInt()
108110
val entities = getEntities(requestParams.tileId)
109111

112+
val fullEntities = entities.map { entity ->
113+
async {
114+
try {
115+
serverManager.integrationRepository().getEntity(entity.entityId)
116+
} catch (e: Exception) {
117+
null
118+
}
119+
}
120+
}.map { it.await() }
121+
val entityMap = fullEntities.filterNotNull().associateBy { it.entityId }
122+
110123
Resources.Builder()
111124
.setVersion(entities.toString())
112125
.apply {
113126
entities.map { entity ->
114-
// Find icon and create Bitmap
115-
val iconIIcon = getIcon(
116-
entity.icon,
117-
entity.domain,
118-
this@ShortcutsTile,
119-
)
127+
// Find icon: try state-aware icon from full entity, fall back to domain icon
128+
val fullEntity = entityMap[entity.entityId]
129+
val iconIIcon = if (fullEntity != null) {
130+
fullEntity.getIcon(this@ShortcutsTile)
131+
} else {
132+
getIcon(
133+
entity.icon,
134+
entity.domain,
135+
this@ShortcutsTile,
136+
)
137+
}
120138
val iconBitmap = IconicsDrawable(this@ShortcutsTile, iconIIcon).apply {
121139
colorInt = Color.WHITE
122140
sizeDp = iconSize.roundToInt()

0 commit comments

Comments
 (0)