From 05d09e3530c3afcd81c1447ef854b8285ddfeb76 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Mon, 30 Dec 2019 13:11:30 -0500 Subject: [PATCH 1/2] Revert "Prevent TBR from being cancelled twice when setting a new TBR" This reverts commit 12a71b8d3e20cf7f008d695c86d525bf9a992685. --- .../plugins/pump/omnipod/comm/OmnipodManager.java | 13 +++++++++++++ .../omnipod/driver/comm/AapsOmnipodManager.java | 4 ++++ app/src/main/res/values/strings.xml | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) 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 92bb4db134..77f2a30cdf 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 @@ -200,15 +200,28 @@ public class OmnipodManager { } } + // CAUTION: cancels temp basal and then sets new temp basal. An OmnipodException[certainFailure=false] indicates that the pod might have cancelled the previous temp basal, but did not set a new temp basal public synchronized void setTemporaryBasal(TempBasalPair tempBasalPair, boolean acknowledgementBeep, boolean completionBeep) { assertReadyForDelivery(); logStartingCommandExecution("setTemporaryBasal [tempBasalPair=" + tempBasalPair + ", acknowledgementBeep=" + acknowledgementBeep + ", completionBeep=" + completionBeep + "]"); + try { + cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep); + } catch (Exception ex) { + logCommandExecutionFinished("setTemporaryBasal"); + throw ex; + } + try { executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction( podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), acknowledgementBeep, completionBeep))); + } catch (OmnipodException ex) { + // Treat all exceptions as uncertain failures, because all delivery has been suspended here. + // Setting this to an uncertain failure will enable for the user to get an appropriate warning + ex.setCertainFailure(false); + throw ex; } finally { logCommandExecutionFinished("setTemporaryBasal"); } 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 6e0d162bda..c077eb2d44 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 @@ -348,6 +348,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled); time = System.currentTimeMillis(); } catch (Exception ex) { + 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)); + } String comment = handleAndTranslateException(ex); addFailureToHistory(time, PodHistoryEntryType.SetTemporaryBasal, comment); return new PumpEnactResult().success(false).enacted(false).comment(comment); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 916b9c7212..43ce10d7d9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1762,10 +1762,10 @@ Low reservoir Unknown alert Setting basal profile might have failed. Delivery might be suspended! Please refresh Pod status. + Setting temp basal might have failed. If there was a temp basal already running, that may have been cancelled! Please refresh pod status. Setting time might have failed. Delivery might be suspended! Please refresh Pod status. Unable to verify whether the bolus succeeded. Please verify that your Pod is bolusing or cancel the bolus. RL Stats Pulse Log - From a17defb817848247d72014db300aed1c81bbf906 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Mon, 30 Dec 2019 13:32:06 -0500 Subject: [PATCH 2/2] Report implicitly cancelled tbr when deactivating pod or resetting pod state --- .../pump/omnipod/driver/comm/AapsOmnipodManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 c077eb2d44..3fb71a671a 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 @@ -217,7 +217,6 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface long time = System.currentTimeMillis(); try { delegate.deactivatePod(); - addSuccessToHistory(time, PodHistoryEntryType.DeactivatePod, null); } catch (Exception ex) { String comment = handleAndTranslateException(ex); podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment); @@ -225,6 +224,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface return new PumpEnactResult().success(false).enacted(false).comment(comment); } + addSuccessToHistory(time, PodHistoryEntryType.DeactivatePod, null); + + reportImplicitlyCanceledTbr(); + podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, true, null); OmnipodUtil.setPodSessionState(null); @@ -264,6 +267,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface public PumpEnactResult resetPodStatus() { delegate.resetPodState(); + reportImplicitlyCanceledTbr(); + OmnipodUtil.setPodSessionState(null); addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.ResetPodState, null);