mirror of
https://github.com/home-assistant/android
synced 2024-10-02 22:34:46 +00:00
Don't crash on sensor update on on/off/setting change (#2391)
* Don't crash on sensor update on on/off/setting change * Update logging message, also for Wear OS
This commit is contained in:
parent
ead6a9377f
commit
965ee61b11
|
@ -141,7 +141,11 @@ class SensorDetailViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
updateSensorEntity(isEnabled)
|
||||
if (isEnabled) sensorManager?.requestSensorUpdate(app)
|
||||
if (isEnabled) try {
|
||||
sensorManager?.requestSensorUpdate(app)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Exception while requesting update for sensor $sensorId", e)
|
||||
}
|
||||
}
|
||||
|
||||
fun onSettingWithDialogPressed(setting: SensorSetting) {
|
||||
|
@ -181,7 +185,11 @@ class SensorDetailViewModel @Inject constructor(
|
|||
|
||||
fun setSetting(setting: SensorSetting) {
|
||||
sensorDao.add(setting)
|
||||
sensorManager?.requestSensorUpdate(app)
|
||||
try {
|
||||
sensorManager?.requestSensorUpdate(app)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Exception while requesting update for sensor $sensorId", e)
|
||||
}
|
||||
refreshSensorData()
|
||||
}
|
||||
|
||||
|
|
|
@ -261,8 +261,11 @@ class MainViewModel @Inject constructor(application: Application) : AndroidViewM
|
|||
.first { basicSensor -> basicSensor.id == sensorId }
|
||||
updateSensorEntity(sensorsDao, basicSensor, isEnabled)
|
||||
|
||||
if (isEnabled)
|
||||
if (isEnabled) try {
|
||||
sensorManager.requestSensorUpdate(app)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Exception while requesting update for sensor $sensorId", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue