Skip to content

Commit 9189b98

Browse files
kdavhclaude
authored andcommitted
Address PR review: fix CancellationException and add isRegistered guard
- 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>
1 parent c64c2c1 commit 9189b98

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,24 @@ import com.mikepenz.iconics.utils.sizeDp
3535
import dagger.hilt.android.AndroidEntryPoint
3636
import io.homeassistant.companion.android.R
3737
import io.homeassistant.companion.android.common.R as commonR
38+
import io.homeassistant.companion.android.common.data.integration.getIcon
3839
import io.homeassistant.companion.android.common.data.prefs.WearPrefsRepository
3940
import io.homeassistant.companion.android.common.data.servers.ServerManager
4041
import io.homeassistant.companion.android.data.SimplifiedEntity
41-
import io.homeassistant.companion.android.common.data.integration.getIcon
4242
import io.homeassistant.companion.android.util.getIcon
4343
import java.nio.ByteBuffer
4444
import javax.inject.Inject
45+
import kotlin.coroutines.cancellation.CancellationException
4546
import kotlin.math.min
4647
import kotlin.math.roundToInt
47-
import kotlinx.coroutines.async
4848
import kotlinx.coroutines.CoroutineScope
4949
import kotlinx.coroutines.Dispatchers
5050
import kotlinx.coroutines.Job
51+
import kotlinx.coroutines.async
5152
import kotlinx.coroutines.guava.future
5253
import kotlinx.coroutines.runBlocking
5354
import kotlinx.coroutines.withContext
55+
import timber.log.Timber
5456

5557
// Dimensions (dp)
5658
private const val CIRCLE_SIZE = 56f
@@ -109,16 +111,23 @@ class ShortcutsTile : TileService() {
109111
val iconSizePx = (iconSize * density).roundToInt()
110112
val entities = getEntities(requestParams.tileId)
111113

112-
val fullEntities = entities.map { entity ->
113-
async {
114-
try {
115-
serverManager.integrationRepository().getEntity(entity.entityId)
116-
} catch (e: Exception) {
117-
null
114+
val entityMap = if (serverManager.isRegistered()) {
115+
val fullEntities = entities.map { entity ->
116+
async {
117+
try {
118+
serverManager.integrationRepository().getEntity(entity.entityId)
119+
} catch (e: CancellationException) {
120+
throw e
121+
} catch (e: Exception) {
122+
Timber.w(e, "Failed to fetch entity ${entity.entityId} for tile")
123+
null
124+
}
118125
}
119-
}
120-
}.map { it.await() }
121-
val entityMap = fullEntities.filterNotNull().associateBy { it.entityId }
126+
}.map { it.await() }
127+
fullEntities.filterNotNull().associateBy { it.entityId }
128+
} else {
129+
emptyMap()
130+
}
122131

123132
Resources.Builder()
124133
.setVersion(entities.toString())

0 commit comments

Comments
 (0)