From e87c568253054c9063ff26b6b9141bd2b3a0cfdd Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 26 Jan 2020 18:21:31 +0100 Subject: [PATCH] Improve Pod fault notifications --- .../pump/omnipod/comm/OmnipodManager.java | 19 ++++++++++++------- .../driver/comm/AapsOmnipodManager.java | 15 +++++++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) 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 51f858c283..3acaa7e712 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 @@ -33,7 +33,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; @@ -305,16 +304,25 @@ public class OmnipodManager { .observeOn(Schedulers.io()) // .doOnComplete(() -> { synchronized (bolusDataMutex) { - StatusResponse statusResponse = null; + double unitsNotDelivered = 0.0d; + for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) { try { // Retrieve a status response in order to update the pod state - statusResponse = getPodStatus(); + StatusResponse statusResponse = getPodStatus(); if (statusResponse.getDeliveryStatus().isBolusing()) { throw new IllegalDeliveryStatusException(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); } else { break; } + } catch (PodFaultException ex) { + // Substract units not delivered in case of a Pod failure + unitsNotDelivered = ex.getFaultEvent().getInsulinNotDelivered(); + + if (isLoggingEnabled()) { + LOG.debug("Caught PodFaultException in bolus completion verification", ex); + } + break; } catch (Exception ex) { if (isLoggingEnabled()) { LOG.debug("Ignoring exception in bolus completion verification", ex); @@ -322,9 +330,6 @@ public class OmnipodManager { } } - // Substract units not delivered in case of a Pod failure - double unitsNotDelivered = statusResponse != null && PodProgressStatus.FAULT_EVENT_OCCURRED.equals(statusResponse.getPodProgressStatus()) ? statusResponse.getInsulinNotDelivered() : 0.0D; - if (hasActiveBolus()) { activeBolusData.bolusCompletionSubject.onSuccess(new BolusDeliveryResult(units - unitsNotDelivered)); activeBolusData = null; @@ -450,7 +455,7 @@ public class OmnipodManager { } public void resetPodState(boolean forcedByUser) { - if(isLoggingEnabled()) { + if (isLoggingEnabled()) { LOG.warn("resetPodState has been called. forcedByUser={}", forcedByUser); } podState = null; 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 6e44dfac8e..d257f9d24f 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 @@ -326,6 +326,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); + if (delegate.getPodState().hasFaultEvent()) { + showPodFaultErrorDialog(delegate.getPodState().getFaultEvent().getFaultEventType(), R.raw.urgentalarm); + } + return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered); } @@ -339,7 +343,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); return new PumpEnactResult().success(true).enacted(true); } catch (PodFaultException ex) { - showErrorDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), null); + showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventType(), null); addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); return new PumpEnactResult().success(true).enacted(true); } catch (Exception ex) { @@ -359,9 +363,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface delegate.setTemporaryBasal(PumpType.Insulet_Omnipod.determineCorrectBasalSize(tempBasalPair.getInsulinRate()), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), beepsEnabled, beepsEnabled); time = System.currentTimeMillis(); } catch (Exception ex) { - if (ex instanceof PodFaultException) { - showErrorDialog(createPodFaultErrorMessage(((PodFaultException) ex).getFaultEvent().getFaultEventType()), R.raw.urgentalarm); - } else if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) { + 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)); } @@ -617,6 +619,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface comment = getStringResource(R.string.omnipod_driver_error_not_enough_data); } else if (ex instanceof PodFaultException) { FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType(); + showPodFaultErrorDialog(faultEventType, R.raw.urgentalarm); comment = createPodFaultErrorMessage(faultEventType); } else if (ex instanceof PodReturnedErrorResponseException) { comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response); @@ -648,6 +651,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface RxBus.INSTANCE.send(event); } + private void showPodFaultErrorDialog(FaultEventType faultEventType, Integer sound) { + showErrorDialog(createPodFaultErrorMessage(faultEventType), sound); + } + private void showErrorDialog(String message, Integer sound) { Intent intent = new Intent(MainApp.instance(), ErrorHelperActivity.class); intent.putExtra("soundid", sound == null ? 0 : sound);