mirror of
https://github.com/home-assistant/android
synced 2024-09-19 16:11:37 +00:00
Update sensors bugfix (#879)
* Update sensors fix * Include unregistering into the condition check
This commit is contained in:
parent
8f017f3b90
commit
1b5cbf1712
|
@ -101,28 +101,30 @@ class SensorReceiver : BroadcastReceiver() {
|
||||||
Log.e(TAG, "Issue registering sensor: ${reg.uniqueId}", e)
|
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())
|
enabledRegistrations.add(fullSensor.toSensorRegistration())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var success = false
|
if (enabledRegistrations.isNotEmpty()) {
|
||||||
try {
|
var success = false
|
||||||
success = integrationUseCase.updateSensors(enabledRegistrations.toTypedArray())
|
try {
|
||||||
} catch (e: Exception) {
|
success = integrationUseCase.updateSensors(enabledRegistrations.toTypedArray())
|
||||||
Log.e(TAG, "Exception while updating sensors.", e)
|
} catch (e: Exception) {
|
||||||
}
|
Log.e(TAG, "Exception while updating sensors.", e)
|
||||||
|
}
|
||||||
|
|
||||||
// We failed to update a sensor, we should re register next time
|
// We failed to update a sensor, we should re register next time
|
||||||
if (!success) {
|
if (!success) {
|
||||||
enabledRegistrations.forEach {
|
enabledRegistrations.forEach {
|
||||||
val sensor = sensorDao.get(it.uniqueId)
|
val sensor = sensorDao.get(it.uniqueId)
|
||||||
if (sensor != null) {
|
if (sensor != null) {
|
||||||
sensor.registered = false
|
sensor.registered = false
|
||||||
sensorDao.update(sensor)
|
sensorDao.update(sensor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else Log.d(TAG, "Nothing to update")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue