mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
Prevent null values for BLE measured power, also allow negative values in case entire field is cleared out (#2158)
* Prevent storing null value for measured power and allow negative values * Use actual default value * Make variable private again
This commit is contained in:
parent
c09fa8d2a3
commit
e4234ec98d
|
@ -22,7 +22,7 @@ class BluetoothSensorManager : SensorManager {
|
|||
private const val SETTING_BLE_TRANSMIT_POWER = "ble_transmit_power"
|
||||
private const val SETTING_BLE_ADVERTISE_MODE = "ble_advertise_mode"
|
||||
private const val SETTING_BLE_TRANSMIT_ENABLED = "ble_transmit_enabled"
|
||||
private const val SETTING_BLE_MEASURED_POWER = "ble_measured_power_at_1m"
|
||||
const val SETTING_BLE_MEASURED_POWER = "ble_measured_power_at_1m"
|
||||
|
||||
private const val DEFAULT_BLE_TRANSMIT_POWER = "ultraLow"
|
||||
private const val DEFAULT_BLE_ADVERTISE_MODE = "lowPower"
|
||||
|
@ -166,7 +166,7 @@ class BluetoothSensorManager : SensorManager {
|
|||
val uuid = getSetting(context, bleTransmitter, SETTING_BLE_ID1, "string", UUID.randomUUID().toString())
|
||||
val major = getSetting(context, bleTransmitter, SETTING_BLE_ID2, "string", DEFAULT_BLE_MAJOR)
|
||||
val minor = getSetting(context, bleTransmitter, SETTING_BLE_ID3, "string", DEFAULT_BLE_MINOR)
|
||||
val measuredPower = getSetting(context, bleTransmitter, SETTING_BLE_MEASURED_POWER, "number", DEFAULT_MEASURED_POWER_AT_1M).toInt()
|
||||
val measuredPower = getSetting(context, bleTransmitter, SETTING_BLE_MEASURED_POWER, "number", DEFAULT_MEASURED_POWER_AT_1M).toIntOrNull() ?: DEFAULT_MEASURED_POWER_AT_1M.toInt()
|
||||
val transmitPower = getSetting(context, bleTransmitter, SETTING_BLE_TRANSMIT_POWER, "list", listOf("ultraLow", "low", "medium", "high"), DEFAULT_BLE_TRANSMIT_POWER)
|
||||
val advertiseMode = getSetting(context, bleTransmitter, SETTING_BLE_ADVERTISE_MODE, "list", listOf("lowPower", "balanced", "lowLatency"), DEFAULT_BLE_ADVERTISE_MODE)
|
||||
|
||||
|
|
|
@ -279,9 +279,14 @@ class SensorDetailFragment(
|
|||
pref.isIconSpaceReserved = false
|
||||
|
||||
pref.setOnBindEditTextListener { fieldType ->
|
||||
if (setting.valueType == "number")
|
||||
if (setting.valueType == "number") {
|
||||
if (setting.name == BluetoothSensorManager.SETTING_BLE_MEASURED_POWER)
|
||||
fieldType.inputType =
|
||||
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED
|
||||
else
|
||||
fieldType.inputType = InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
}
|
||||
|
||||
pref.setOnPreferenceChangeListener { _, newValue ->
|
||||
sensorDao.add(
|
||||
|
|
Loading…
Reference in a new issue