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 0570d2ce3f..0b65cdb635 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 @@ -10,7 +10,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AcknowledgeAlertsAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.BolusAction; @@ -52,74 +51,37 @@ public class OmnipodManager { this.podState = podState; } - // Returns a PumpEnactResult which describes whether or not all commands have been sent successfully - // After priming should have finished (55 seconds), the pod state is verified. + // After priming should have been finished, the pod state is verified. // The result of that verification is passed to the SetupActionResultHandler - public PumpEnactResult pairAndPrime(SetupActionResultHandler resultHandler) { - try { - if (podState == null) { - podState = communicationService.executeAction(new PairAction(new PairService())); - } - if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { - communicationService.executeAction(new PrimeAction(new PrimeService(), podState)); - - executeDelayed(() -> verifySetupAction(statusResponse -> PrimeAction.updatePrimingStatus(podState, statusResponse), // - SetupProgress.PRIMING_FINISHED, resultHandler), // - calculateBolusDuration(OmnipodConst.POD_PRIME_BOLUS_UNITS, OmnipodConst.POD_PRIMING_DELIVERY_RATE)); - } else { - // TODO use string resource - return new PumpEnactResult().success(false).enacted(false).comment("Illegal setup state: " + podState.getSetupProgress().name()); - } - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + public void pairAndPrime(SetupActionResultHandler resultHandler) { + if (podState == null) { + podState = communicationService.executeAction(new PairAction(new PairService())); } + if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { + communicationService.executeAction(new PrimeAction(new PrimeService(), podState)); - return new PumpEnactResult().success(true).enacted(true); + executeDelayed(() -> verifySetupAction(statusResponse -> PrimeAction.updatePrimingStatus(podState, statusResponse), // + SetupProgress.PRIMING_FINISHED, resultHandler), // + calculateBolusDuration(OmnipodConst.POD_PRIME_BOLUS_UNITS, OmnipodConst.POD_PRIMING_DELIVERY_RATE)); + } else { + throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podState.getSetupProgress()); + } } - // Returns a PumpEnactResult which describes whether or not all commands have been sent successfully - // After inserting the cannula should have finished (10 seconds), the pod state is verified. + // After inserting the cannula should have been finished, the pod state is verified. // The result of that verification is passed to the SetupActionResultHandler - public PumpEnactResult insertCannula(BasalSchedule basalSchedule, SetupActionResultHandler resultHandler) { + public void insertCannula(BasalSchedule basalSchedule, SetupActionResultHandler resultHandler) { if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { - // TODO use string resource - return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first"); + throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, podState == null ? null : podState.getSetupProgress()); } else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) { - // TODO use string resource - return new PumpEnactResult().success(false).enacted(false).comment("Illegal setup state: " + podState.getSetupProgress().name()); + throw new IllegalSetupProgressException(SetupProgress.CANNULA_INSERTING, podState.getSetupProgress()); } - try { - communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, basalSchedule)); + communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, basalSchedule)); - executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), // - SetupProgress.COMPLETED, resultHandler), - calculateBolusDuration(OmnipodConst.POD_CANNULA_INSERTION_BOLUS_UNITS, OmnipodConst.POD_CANNULA_INSERTION_DELIVERY_RATE)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult cancelBolus() { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); + executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), // + SetupProgress.COMPLETED, resultHandler), + calculateBolusDuration(OmnipodConst.POD_CANNULA_INSERTION_BOLUS_UNITS, OmnipodConst.POD_CANNULA_INSERTION_DELIVERY_RATE)); } public StatusResponse getPodStatus() { @@ -130,204 +92,108 @@ public class OmnipodManager { return communicationService.executeAction(new GetStatusAction(podState)); } - public PumpEnactResult deactivatePod() { + public PodInfoResponse getPodInfo(PodInfoType podInfoType) { + assertReadyForDelivery(); + + return communicationService.executeAction(new GetPodInfoAction(podState, podInfoType)); + } + + public void acknowledgeAlerts() { + assertReadyForDelivery(); + + communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts())); + } + + public void setBasalSchedule(BasalSchedule schedule) { + assertReadyForDelivery(); + + communicationService.executeAction(new SetBasalScheduleAction(podState, schedule, + false, podState.getScheduleOffset(), true)); + } + + public void setTemporaryBasal(TempBasalPair tempBasalPair) { + assertReadyForDelivery(); + + communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(), + podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), + true, true)); + } + + public void cancelTemporaryBasal() { + assertReadyForDelivery(); + + communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, true)); + } + + public void bolus(Double units, StatusResponseHandler bolusCompletionHandler) { + assertReadyForDelivery(); + + communicationService.executeAction(new BolusAction(podState, units, true, true)); + + if (bolusCompletionHandler != null) { + executeDelayed(() -> { + for (int i = 0; ACTION_VERIFICATION_TRIES > i; i++) { + StatusResponse statusResponse = null; + try { + statusResponse = getPodStatus(); + if (statusResponse.getDeliveryStatus().isBolusing()) { + break; + } + } catch (Exception ex) { + // Ignore + } + bolusCompletionHandler.handle(statusResponse); + } + }, calculateBolusDuration(units, OmnipodConst.POD_BOLUS_DELIVERY_RATE)); + } + } + + public void cancelBolus() { + assertReadyForDelivery(); + communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, true)); + } + + public void suspendDelivery() { + assertReadyForDelivery(); + + communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), true)); + } + + public void resumeDelivery() { + assertReadyForDelivery(); + + communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), + true, podState.getScheduleOffset(), true)); + } + + // If this command fails, it it possible that delivery has been suspended + public void setTime() { + assertReadyForDelivery(); + + // Suspend delivery + communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), false)); + + // Joda seems to cache the default time zone, so we use the JVM's + DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault())); + podState.setTimeZone(DateTimeZone.getDefault()); + + // Resume delivery + StatusResponse statusResponse = communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), + true, podState.getScheduleOffset(), true)); + } + + public void deactivatePod() { if (podState == null) { - // TODO use string resource - return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first"); + throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null); } - try { - communicationService.executeAction(new DeactivatePodAction(podState, true)); - resetPodState(); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); + communicationService.executeAction(new DeactivatePodAction(podState, true)); + resetPodState(); } - public PumpEnactResult setBasalSchedule(BasalSchedule schedule) { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new SetBasalScheduleAction(podState, schedule, - false, podState.getScheduleOffset(), true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult resetPodState() { + public void resetPodState() { podState = null; SP.remove(OmnipodConst.Prefs.PodState); - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult bolus(Double units, StatusResponseHandler bolusCompletionHandler) { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new BolusAction(podState, units, true, true)); - - if(bolusCompletionHandler != null) { - executeDelayed(() -> { - for (int i = 0; ACTION_VERIFICATION_TRIES > i; i++) { - StatusResponse statusResponse = null; - try { - statusResponse = getPodStatus(); - if (statusResponse.getDeliveryStatus().isBolusing()) { - break; - } - } catch (Exception ex) { - // Ignore - } - bolusCompletionHandler.handle(statusResponse); - } - }, calculateBolusDuration(units, OmnipodConst.POD_BOLUS_DELIVERY_RATE)); - } - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(), - podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), - true, true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult cancelTemporaryBasal() { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult acknowledgeAlerts() { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts())); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - return new PumpEnactResult().success(true).enacted(true); - } - - // TODO should we add this to the OmnipodCommunicationManager interface? - public PumpEnactResult getPodInfo(PodInfoType podInfoType) { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - // TODO how can we return the PodInfo response? - PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, podInfoType)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult suspendDelivery() { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult resumeDelivery() { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), - true, podState.getScheduleOffset(), true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); - } - - public PumpEnactResult setTime() { - if (!isInitialized()) { - return createNotInitializedResult(); - } - - try { - // Suspend delivery - communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), false)); - - // Joda seems to cache the default time zone, so we use the JVM's - DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault())); - podState.setTimeZone(DateTimeZone.getDefault()); - - // Resume delivery - communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), - true, podState.getScheduleOffset(), true)); - } catch (Exception ex) { - // TODO distinguish between certain and uncertain failures - // TODO user friendly error messages (string resources) - return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); - } - - return new PumpEnactResult().success(true).enacted(true); } public OmnipodCommunicationService getCommunicationService() { @@ -338,16 +204,20 @@ public class OmnipodManager { return podState.getTime(); } - public boolean isInitialized() { + public boolean isReadyForDelivery() { return podState != null && podState.getSetupProgress() == SetupProgress.COMPLETED; } + public PodSessionState getPodState() { + return this.podState; + } + public String getPodStateAsString() { return podState == null ? "null" : podState.toString(); } private Duration calculateBolusDuration(double units, double deliveryRate) { - return Duration.standardSeconds((long)Math.ceil(units / deliveryRate)); + return Duration.standardSeconds((long) Math.ceil(units / deliveryRate)); } private void executeDelayed(Runnable r, Duration timeout) { @@ -355,13 +225,10 @@ public class OmnipodManager { scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS); } - private PumpEnactResult createNotInitializedResult() { - // TODO use string resource - return new PumpEnactResult().success(false).enacted(false).comment("Pod should be initialized first"); - } - - public PodSessionState getPodState() { - return this.podState; + private void assertReadyForDelivery() { + if (!isReadyForDelivery()) { + throw new IllegalSetupProgressException(SetupProgress.COMPLETED, podState == null ? null : podState.getSetupProgress()); + } } private void verifySetupAction(StatusResponseHandler statusResponseHandler, SetupProgress expectedSetupProgress, SetupActionResultHandler resultHandler) { 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 5bd181c50e..b49cd0a043 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 @@ -14,6 +14,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunication import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; @@ -45,23 +46,30 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface @Override public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) { if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) { - PumpEnactResult result = delegate.pairAndPrime(res -> // - podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res))); - if (!result.success) { - podInitReceiver.returnInitTaskStatus(podInitActionType, false, result.comment); + try { + delegate.pairAndPrime(res -> // + podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res))); + return new PumpEnactResult().success(true).enacted(true); + } catch (Exception ex) { + // TODO use string resource instead of exception message + podInitReceiver.returnInitTaskStatus(podInitActionType, false, ex.getMessage()); + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); } - return result; } else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) { - PumpEnactResult result = delegate.insertCannula(mapProfileToBasalSchedule(profile), res -> { - podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res)); - OmnipodUtil.setPodSessionState(delegate.getPodState()); - RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); - }); - if (!result.success) { - podInitReceiver.returnInitTaskStatus(podInitActionType, false, result.comment); + try { + delegate.insertCannula(mapProfileToBasalSchedule(profile), res -> { + podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res)); + OmnipodUtil.setPodSessionState(delegate.getPodState()); + RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); + }); + return new PumpEnactResult().success(true).enacted(true); + } catch (Exception ex) { + // TODO use string resource instead of exception message + podInitReceiver.returnInitTaskStatus(podInitActionType, false, ex.getMessage()); + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); } - return result; } + // Todo use string resource return new PumpEnactResult().success(false).enacted(false).comment("Illegal PodInitActionType: " + podInitActionType.name()); } @@ -70,77 +78,120 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface try { StatusResponse statusResponse = delegate.getPodStatus(); return new PumpEnactResult().success(true).enacted(false); - } catch(Exception ex) { - // TODO return string resource + } catch (Exception ex) { + // TODO use string resource instead of exception message return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); } } @Override public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { - - PumpEnactResult result = delegate.deactivatePod(); - podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, result.success, (result.success ? null : result.comment)); - - if (result.success) { - OmnipodUtil.setPodSessionState(null); - RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); + try { + delegate.deactivatePod(); + } catch (Exception ex) { + // TODO use string resource instead of exception message + podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, ex.getMessage()); + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); } - return result; + podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, true, null); + + OmnipodUtil.setPodSessionState(null); + RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); + + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult setBasalProfile(Profile basalProfile) { - return delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile)); + try { + delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile)); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult resetPodStatus() { - - PumpEnactResult result = delegate.resetPodState(); + delegate.resetPodState(); //addToHistory(System.currentTimeMillis(), PodDbEntryType.ResetPodState, null, null, null, null); OmnipodUtil.setPodSessionState(null); - RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); - return result; + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult setBolus(Double amount) { - return delegate.bolus(amount, statusResponse -> { - if(statusResponse == null) { - // Failed to retrieve status response after bolus - // Bolus probably finished anyway - } else if(statusResponse.getDeliveryStatus().isBolusing()) { - // This shouldn't happen - } else { - // Bolus successfully completed - } - }); + try { + delegate.bolus(amount, statusResponse -> { + if (statusResponse == null) { + // Failed to retrieve status response after bolus + // Bolus probably finished anyway + } else if (statusResponse.getDeliveryStatus().isBolusing()) { + // This shouldn't happen + } else { + // Bolus successfully completed + } + }); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult cancelBolus() { - return delegate.cancelBolus(); + try { + delegate.cancelBolus(); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) { - return delegate.setTemporaryBasal(tempBasalPair); + try { + delegate.setTemporaryBasal(tempBasalPair); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult cancelTemporaryBasal() { - return delegate.cancelTemporaryBasal(); + try { + delegate.cancelTemporaryBasal(); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } @Override public PumpEnactResult acknowledgeAlerts() { - return delegate.acknowledgeAlerts(); + try { + delegate.acknowledgeAlerts(); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + return new PumpEnactResult().success(true).enacted(true); } @Override @@ -151,20 +202,51 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface // TODO should we add this to the OmnipodCommunicationManager interface? public PumpEnactResult getPodInfo(PodInfoType podInfoType) { - return delegate.getPodInfo(podInfoType); + try { + // TODO how can we return the PodInfo response? + // This method is useless unless we return the PodInfoResponse, + // because the pod state we keep, doesn't get updated from a PodInfoResponse. + // We use StatusResponses for that, which can be obtained from the getPodStatus method + PodInfoResponse podInfo = delegate.getPodInfo(podInfoType); + return new PumpEnactResult().success(true).enacted(true); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } } public PumpEnactResult suspendDelivery() { - return delegate.suspendDelivery(); + try { + delegate.suspendDelivery(); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } public PumpEnactResult resumeDelivery() { - return delegate.resumeDelivery(); + try { + delegate.resumeDelivery(); + } catch (Exception ex) { + // TODO use string resource instead of exception message + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); } // TODO should we add this to the OmnipodCommunicationManager interface? public PumpEnactResult setTime() { - return delegate.setTime(); + try { + delegate.setTime(); + } catch (Exception ex) { + // TODO distinguish between certain and uncertain failures + // TODO user friendly error messages (string resources) + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + return new PumpEnactResult().success(true).enacted(true); } public OmnipodCommunicationService getCommunicationService() { @@ -176,7 +258,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface } public boolean isInitialized() { - return delegate.isInitialized(); + return delegate.isReadyForDelivery(); } public String getPodStateAsString() {