@@ -35,22 +35,24 @@ import com.mikepenz.iconics.utils.sizeDp
3535import dagger.hilt.android.AndroidEntryPoint
3636import io.homeassistant.companion.android.R
3737import io.homeassistant.companion.android.common.R as commonR
38+ import io.homeassistant.companion.android.common.data.integration.getIcon
3839import io.homeassistant.companion.android.common.data.prefs.WearPrefsRepository
3940import io.homeassistant.companion.android.common.data.servers.ServerManager
4041import io.homeassistant.companion.android.data.SimplifiedEntity
41- import io.homeassistant.companion.android.common.data.integration.getIcon
4242import io.homeassistant.companion.android.util.getIcon
4343import java.nio.ByteBuffer
4444import javax.inject.Inject
45+ import kotlin.coroutines.cancellation.CancellationException
4546import kotlin.math.min
4647import kotlin.math.roundToInt
47- import kotlinx.coroutines.async
4848import kotlinx.coroutines.CoroutineScope
4949import kotlinx.coroutines.Dispatchers
5050import kotlinx.coroutines.Job
51+ import kotlinx.coroutines.async
5152import kotlinx.coroutines.guava.future
5253import kotlinx.coroutines.runBlocking
5354import kotlinx.coroutines.withContext
55+ import timber.log.Timber
5456
5557// Dimensions (dp)
5658private 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