Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when we don't have new_state or old_state in websocket. #2004

Merged
merged 1 commit into from Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,13 +26,13 @@ import io.homeassistant.companion.android.common.data.url.UrlRepository
import io.homeassistant.companion.android.common.data.websocket.WebSocketRepository
import io.homeassistant.companion.android.common.data.websocket.impl.entities.GetConfigResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.json.JSONArray
import java.util.regex.Pattern
import javax.inject.Inject
import javax.inject.Named
import kotlin.Exception

class IntegrationRepositoryImpl @Inject constructor(
private val integrationService: IntegrationService,
Expand Down Expand Up @@ -464,16 +464,18 @@ class IntegrationRepositoryImpl @Inject constructor(
}

override suspend fun getEntityUpdates(): Flow<Entity<*>> {
return webSocketRepository.getStateChanges().map {
Entity(
it.newState.entityId,
it.newState.state,
it.newState.attributes,
it.newState.lastChanged,
it.newState.lastUpdated,
it.newState.context
)
}
return webSocketRepository.getStateChanges()
.filter { it.newState != null }
.map {
Entity(
it.newState!!.entityId,
it.newState.state,
it.newState.attributes,
it.newState.lastChanged,
it.newState.lastUpdated,
it.newState.context
)
}
}

private suspend fun canRegisterEntityCategoryStateClass(): Boolean {
Expand Down
Expand Up @@ -6,6 +6,6 @@ import io.homeassistant.companion.android.common.data.integration.Entity
@JsonIgnoreProperties(ignoreUnknown = true)
data class StateChangedEvent(
val entityId: String,
val oldState: Entity<*>,
val newState: Entity<*>
val oldState: Entity<*>?,
val newState: Entity<*>?
)