Abort bolusing when reading initial state fails.
Otherwise request time is zero and and any old bolus will be regarded as the last bolus delivered when recovery kicks in. Also add a safety check to not count a bolus bigger than the requested bolus as a partially delivered bolus.
This commit is contained in:
parent
790d5f21e1
commit
f658da42a7
1 changed files with 17 additions and 11 deletions
|
@ -467,7 +467,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
|
||||
|
||||
long pumpTimeWhenBolusWasRequested = runCommand(null, 1, ruffyScripter::readPumpState).state.pumpTime;
|
||||
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
|
||||
long pumpTimeWhenBolusWasRequested = stateResult .state.pumpTime;
|
||||
if (!stateResult.success || pumpTimeWhenBolusWasRequested == 0) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.sResources.getString(R.string.combo_error_no_bolus_delivered));
|
||||
}
|
||||
|
||||
try {
|
||||
pump.activity = MainApp.sResources.getString(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
||||
|
@ -539,6 +544,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
if (lastBolus == null // no bolus ever given
|
||||
|| lastBolus.timestamp < pumpTimeWhenBolusWasRequested // this is not the bolus you're looking for
|
||||
|| lastBolus.amount - detailedBolusInfo.insulin > 0.01 // this one neither, big than requested bolus
|
||||
|| !lastBolus.isValid) { // ext/multiwave bolus
|
||||
log.debug("No bolus was delivered");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
|
@ -549,21 +555,21 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
detailedBolusInfo.insulin = lastBolus.amount;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug(String.format(Locale.getDefault(), "Added partial bolus of %.2f to treatments (requested: %.2f", lastBolus.amount, requestedBolus));
|
||||
log.debug(String.format(Locale.getDefault(), "Added partial bolus of %.2f to treatments (requested: %.2f"), lastBolus.amount, requestedBolus);
|
||||
|
||||
return new PumpEnactResult().success(false).enacted(true)
|
||||
.comment(MainApp.sResources.getString(R.string.combo_error_partial_bolus_delivered,
|
||||
lastBolus.amount, requestedBolus));
|
||||
} else {
|
||||
// bolus was correctly and fully delivered
|
||||
detailedBolusInfo.insulin = lastBolus.amount;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug("Added correctly delivered bolus to treatments");
|
||||
return new PumpEnactResult().success(true).enacted(true)
|
||||
.bolusDelivered(lastBolus.amount)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
}
|
||||
|
||||
// bolus was correctly and fully delivered
|
||||
detailedBolusInfo.insulin = lastBolus.amount;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug("Added correctly delivered bolus to treatments");
|
||||
return new PumpEnactResult().success(true).enacted(true)
|
||||
.bolusDelivered(lastBolus.amount)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue