Merge pull request #236 from saydo-co/dev
Prevent NPE when checking for battery level
This commit is contained in:
commit
cd3b779936
1 changed files with 10 additions and 4 deletions
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble;
|
||||||
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -111,13 +113,17 @@ public class RFSpy {
|
||||||
public Integer retrieveBatteryLevel() {
|
public Integer retrieveBatteryLevel() {
|
||||||
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID);
|
BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID);
|
||||||
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
|
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
|
||||||
int value = result.value[0];
|
if (ArrayUtils.isNotEmpty(result.value)) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "BLE battery level: {}", value);
|
int value = result.value[0];
|
||||||
return value;
|
aapsLogger.debug(LTag.PUMPBTCOMM, "BLE battery level: {}", value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
aapsLogger.error(LTag.PUMPBTCOMM, "getBatteryLevel received an empty result. Value: " + result.value);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "getBatteryLevel failed with code: " + result.resultCode);
|
aapsLogger.error(LTag.PUMPBTCOMM, "getBatteryLevel failed with code: " + result.resultCode);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This gets the version from the BLE113, not from the CC1110.
|
// This gets the version from the BLE113, not from the CC1110.
|
||||||
|
|
Loading…
Reference in a new issue