Update sensors bugfix (#879)

* Update sensors fix

* Include unregistering into the condition check
This commit is contained in:
Oleksandr Kapshuk 2020-09-04 15:28:11 +03:00 committed by GitHub
parent 8f017f3b90
commit 1b5cbf1712
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,28 +101,30 @@ class SensorReceiver : BroadcastReceiver() {
Log.e(TAG, "Issue registering sensor: ${reg.uniqueId}", e)
}
}
if (fullSensor != null && sensor?.registered == true) {
if (sensor?.enabled == true && fullSensor != null && sensor?.registered) {
enabledRegistrations.add(fullSensor.toSensorRegistration())
}
}
}
var success = false
try {
success = integrationUseCase.updateSensors(enabledRegistrations.toTypedArray())
} catch (e: Exception) {
Log.e(TAG, "Exception while updating sensors.", e)
}
if (enabledRegistrations.isNotEmpty()) {
var success = false
try {
success = integrationUseCase.updateSensors(enabledRegistrations.toTypedArray())
} catch (e: Exception) {
Log.e(TAG, "Exception while updating sensors.", e)
}
// We failed to update a sensor, we should re register next time
if (!success) {
enabledRegistrations.forEach {
val sensor = sensorDao.get(it.uniqueId)
if (sensor != null) {
sensor.registered = false
sensorDao.update(sensor)
// We failed to update a sensor, we should re register next time
if (!success) {
enabledRegistrations.forEach {
val sensor = sensorDao.get(it.uniqueId)
if (sensor != null) {
sensor.registered = false
sensorDao.update(sensor)
}
}
}
}
} else Log.d(TAG, "Nothing to update")
}
}