diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java index 77f2a30cdf..0c020a7986 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java @@ -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; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java index b6c0247c95..72a0065322 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java @@ -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)); }