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

Improve sensor re-registration on app version change for offline server #3380

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.IOException
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.util.Locale
import javax.inject.Inject

Expand Down Expand Up @@ -213,6 +215,7 @@ abstract class SensorReceiverBase : BroadcastReceiver() {
null
}

var serverIsReachable = true
val enabledRegistrations = mutableListOf<SensorRegistration<Any>>()

managers.forEach { manager ->
Expand Down Expand Up @@ -296,6 +299,7 @@ abstract class SensorReceiverBase : BroadcastReceiver() {
}
} else if (
canBeRegistered &&
serverIsReachable &&
(sensor.enabled || supportsDisabledSensors) &&
(currentAppVersion != sensor.appRegistration || currentHAversion != sensor.coreRegistration)
) {
Expand All @@ -309,6 +313,10 @@ abstract class SensorReceiverBase : BroadcastReceiver() {
sensorDao.update(sensor)
} catch (e: Exception) {
Log.e(tag, "Issue re-registering sensor ${basicSensor.id}", e)
if (e is IntegrationException && (e.cause is ConnectException || e.cause is SocketTimeoutException)) {
Log.w(tag, "Server can't be reached, skipping other registrations for sensors due to version change")
serverIsReachable = false
}
}
}

Expand Down