When bolusing, only read history in case of error or cancellation.
This commit is contained in:
parent
8c04d12904
commit
98ba0fbf87
2 changed files with 21 additions and 41 deletions
|
@ -438,7 +438,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rewrite to read last bolus (via mydata) only when bolus failed or if it was cancelled midways
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
// guard against boluses issued multiple times within a minute
|
// guard against boluses issued multiple times within a minute
|
||||||
|
@ -455,28 +454,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
pump.activity = MainApp.sResources.getString(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
pump.activity = MainApp.sResources.getString(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||||
|
|
||||||
// refresh pump data
|
|
||||||
CommandResult reservoirBolusResult = runCommand(null, 3,
|
|
||||||
ruffyScripter::readReservoirLevelAndLastBolus);
|
|
||||||
if (!reservoirBolusResult.success) {
|
|
||||||
log.error("Bolus delivery failure at stage 1", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check enough insulin left for bolus
|
|
||||||
if (Math.round(detailedBolusInfo.insulin + 0.5) > reservoirBolusResult.reservoirLevel) {
|
|
||||||
log.error("Bolus delivery failure at stage 2", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_reservoir_level_insufficient_for_bolus));
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify we're update to date and know the most recent bolus
|
|
||||||
if (!Objects.equals(lastKnownBolus, reservoirBolusResult.lastBolus)) {
|
|
||||||
log.error("Bolus delivery failure at stage 3", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_history_state_mismatch));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cancelBolus) {
|
if (cancelBolus) {
|
||||||
return new PumpEnactResult().success(true).enacted(false);
|
return new PumpEnactResult().success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
@ -488,28 +465,29 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
|
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
|
||||||
bolusInProgress = false;
|
bolusInProgress = false;
|
||||||
|
|
||||||
if (!bolusCmdResult.success) {
|
if (!cancelBolus && bolusCmdResult.success) {
|
||||||
new Thread(this::checkPumpHistory).start();
|
detailedBolusInfo.date = bolusCmdResult.state.timestamp;
|
||||||
log.error("Bolus delivery failure at stage 4", new Exception());
|
detailedBolusInfo.source = Source.USER;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
|
return new PumpEnactResult().success(true).enacted(true)
|
||||||
|
.bolusDelivered(detailedBolusInfo.insulin)
|
||||||
|
.carbsDelivered(detailedBolusInfo.carbs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case of error check what was actually delivered
|
||||||
|
CommandResult historyResult = runCommand(null, 1,
|
||||||
|
() -> ruffyScripter.readHistory(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
||||||
|
if (!historyResult.success) {
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
||||||
}
|
}
|
||||||
|
Bolus lastPumpBolus = historyResult.lastBolus;
|
||||||
// verify delivered bolus
|
|
||||||
reservoirBolusResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus);
|
|
||||||
if (!reservoirBolusResult.success) {
|
|
||||||
log.error("Bolus delivery failure at stage 5", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
|
|
||||||
}
|
|
||||||
Bolus lastPumpBolus = reservoirBolusResult.lastBolus;
|
|
||||||
if (cancelBolus) {
|
if (cancelBolus) {
|
||||||
// if cancellation was requested, the delivered bolus is allowed to differ from requested
|
// if cancellation was requested, the delivered bolus is allowed to differ from requested
|
||||||
} else if (lastPumpBolus == null || Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01
|
} else if (lastPumpBolus == null || Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01
|
||||||
|| System.currentTimeMillis() - lastPumpBolus.timestamp > 5 * 60 * 1000) {
|
|| System.currentTimeMillis() - lastPumpBolus.timestamp > 5 * 60 * 1000) {
|
||||||
log.error("Bolus delivery failure at stage 6", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false).
|
return new PumpEnactResult().success(false).enacted(false).
|
||||||
comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
|
comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add treatment record to DB (if it wasn't cancelled)
|
// add treatment record to DB (if it wasn't cancelled)
|
||||||
|
@ -538,6 +516,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
|
// TODO if the pump is busy setting a TBR while a bolus was requested,
|
||||||
|
// cancelling here, when the TBR is still being set will fail to cancel the bolus.
|
||||||
|
// See if the queue might solve this, otherwise we could add a check in runCommand
|
||||||
|
// (but can't currently determine if the request is a basal request)
|
||||||
|
// or have the scripter skip the next bolus that comes in
|
||||||
if (bolusInProgress) {
|
if (bolusInProgress) {
|
||||||
ruffyScripter.cancelBolus();
|
ruffyScripter.cancelBolus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -784,11 +784,8 @@
|
||||||
<string name="key_raise_urgent_alarms_as_android_notification" translatable="false">raise_urgent_alarms_as_android_notification</string>
|
<string name="key_raise_urgent_alarms_as_android_notification" translatable="false">raise_urgent_alarms_as_android_notification</string>
|
||||||
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
|
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
|
||||||
<string name="combo_pump_never_connected">Never</string>
|
<string name="combo_pump_never_connected">Never</string>
|
||||||
<string name="combo_reservoir_level_insufficient_for_bolus">Not enough insulin left in reservoir for bolus</string>
|
|
||||||
<string name="combo_pump_bolus_history_state_mismatch">A bolus has been delivered directly on the pump recently, of which AndroidAPS has only just become aware of. The pump\'s history is currently being read. Please check the Combo page, verify the last bolus and IOB and bolus again if needed. No bolus has been delivered.</string>
|
|
||||||
<string name="combo_pump_bolus_verification_failed">Bolus delivery verification failed. The pump history will be read again on the next loop run or when refreshing from the Combo page. Please check and bolus again if needed.</string>
|
|
||||||
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
|
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
|
||||||
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please check the Combo page and bolus again as needed.</string>
|
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please the pump and treatments tabs and bolus again as needed.</string>
|
||||||
<string name="combo_force_disabled_notification">Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours or the selected basal rate is not 1. Loop mode has been set to low-suspend only until 6 hours after the last unsupported bolus or basal rate profile. Only normal boluses are supported in loop mode with basal rate profile 1.</string>
|
<string name="combo_force_disabled_notification">Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours or the selected basal rate is not 1. Loop mode has been set to low-suspend only until 6 hours after the last unsupported bolus or basal rate profile. Only normal boluses are supported in loop mode with basal rate profile 1.</string>
|
||||||
<string name="combo_notification_check_time_date">Check pump time and date</string>
|
<string name="combo_notification_check_time_date">Check pump time and date</string>
|
||||||
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
|
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
|
||||||
|
|
Loading…
Reference in a new issue