prevent NPE

This commit is contained in:
Milos Kozak 2021-01-21 09:37:04 +01:00
parent feb2d9045a
commit c6438f5df9

View file

@ -182,19 +182,19 @@ class ActionStringHandler @Inject constructor(
return return
} }
val bgReading = iobCobCalculatorPlugin.actualBg() val bgReading = iobCobCalculatorPlugin.actualBg()
if (bgReading == null && useBG) { if (bgReading == null) {
sendError("No recent BG to base calculation on!") sendError("No recent BG to base calculation on!")
return return
} }
val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "Wizard wear") val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "Wizard wear")
if (useCOB && (cobInfo.displayCob == null)) { if (cobInfo.displayCob == null) {
sendError("Unknown COB! BG reading missing or recent app restart?") sendError("Unknown COB! BG reading missing or recent app restart?")
return return
} }
val format = DecimalFormat("0.00") val format = DecimalFormat("0.00")
val formatInt = DecimalFormat("0") val formatInt = DecimalFormat("0")
val bolusWizard = BolusWizard(injector).doCalc(profile, profileName, activePlugin.activeTreatments.tempTargetFromHistory, val bolusWizard = BolusWizard(injector).doCalc(profile, profileName, activePlugin.activeTreatments.tempTargetFromHistory,
carbsAfterConstraints, cobInfo.displayCob!!, bgReading!!.valueToUnits(profileFunction.getUnits()), carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(profileFunction.getUnits()),
0.0, percentage.toDouble(), useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend, false) 0.0, percentage.toDouble(), useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend, false)
if (Math.abs(bolusWizard.insulinAfterConstraints - bolusWizard.calculatedTotalInsulin) >= 0.01) { if (Math.abs(bolusWizard.insulinAfterConstraints - bolusWizard.calculatedTotalInsulin) >= 0.01) {
sendError("Insulin constraint violation!" + sendError("Insulin constraint violation!" +