Automatically retry bolus cancellation and show error when setting TBR fails due to a PodFaultException

This commit is contained in:
Bart Sopers 2020-01-02 01:08:18 +01:00
parent 57c35bad58
commit b08045b326
2 changed files with 26 additions and 12 deletions

View file

@ -320,7 +320,7 @@ public class OmnipodManager {
}
}
if (activeBolusData != null) {
if (hasActiveBolus()) {
activeBolusData.bolusCompletionSubject.onSuccess(new BolusDeliveryResult(units));
activeBolusData = null;
}
@ -460,6 +460,13 @@ public class OmnipodManager {
return podState != null && podState.getSetupProgress() == SetupProgress.COMPLETED;
}
public boolean hasActiveBolus() {
synchronized (bolusDataMutex) {
return activeBolusData != null;
}
}
// FIXME this is dirty, we should not expose the original pod state
public PodSessionState getPodState() {
return this.podState;
}

View file

@ -331,18 +331,23 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override
public PumpEnactResult cancelBolus() {
long time = System.currentTimeMillis();
try {
delegate.cancelBolus(isBolusBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
} catch (PodFaultException ex) {
showErrorDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), null);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment);
String comment = null;
while (delegate.hasActiveBolus()) {
try {
delegate.cancelBolus(isBolusBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult().success(true).enacted(true);
} catch (PodFaultException ex) {
showErrorDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), null);
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) {
comment = handleAndTranslateException(ex);
}
}
return new PumpEnactResult().success(true).enacted(true);
addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment);
}
@Override
@ -353,7 +358,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled);
time = System.currentTimeMillis();
} catch (Exception ex) {
if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
if (ex instanceof PodFaultException) {
showErrorDialog(createPodFaultErrorMessage(((PodFaultException) ex).getFaultEvent().getFaultEventType()), R.raw.urgentalarm);
} else if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
addToHistory(time, PodHistoryEntryType.SetTemporaryBasal, "Uncertain failure", false);
return new PumpEnactResult().success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_set_temp_basal_failed_uncertain));
}