From 120243908fae0c17c09c3f6a3b827be08a0b131d Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Wed, 27 Nov 2019 22:13:48 +0100 Subject: [PATCH] Move basal profile mapping to AapsOmnipodManager --- .../pump/omnipod/comm/OmnipodManager.java | 13 ++++------ .../defs/schedule/BasalScheduleMapper.java | 21 ---------------- .../driver/comm/AapsOmnipodManager.java | 25 ++++++++++++++++--- 3 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalScheduleMapper.java 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 a64b23932e..04d0fb6b49 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.Profile; 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; @@ -33,7 +32,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.pod 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.SetupProgress; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleMapper; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.utils.SP; @@ -82,7 +81,7 @@ public class OmnipodManager { // 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. // The result of that verification is passed to the SetupActionResultHandler - public PumpEnactResult insertCannula(Profile profile, SetupActionResultHandler resultHandler) { + public PumpEnactResult 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"); @@ -92,8 +91,7 @@ public class OmnipodManager { } try { - communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, - BasalScheduleMapper.mapProfileToBasalSchedule(profile))); + communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, basalSchedule)); executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), // SetupProgress.COMPLETED, resultHandler), @@ -159,14 +157,13 @@ public class OmnipodManager { return new PumpEnactResult().success(true).enacted(true); } - public PumpEnactResult setBasalProfile(Profile basalProfile) { + public PumpEnactResult setBasalSchedule(BasalSchedule schedule) { if (!isInitialized()) { return createNotInitializedResult(); } try { - communicationService.executeAction(new SetBasalScheduleAction(podState, - BasalScheduleMapper.mapProfileToBasalSchedule(basalProfile), + communicationService.executeAction(new SetBasalScheduleAction(podState, schedule, false, podState.getScheduleOffset(), true)); } catch (Exception ex) { // TODO distinguish between certain and uncertain failures diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalScheduleMapper.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalScheduleMapper.java deleted file mode 100644 index f0a2fa7e9d..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalScheduleMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule; - -import org.joda.time.Duration; - -import java.util.ArrayList; -import java.util.List; - -import info.nightscout.androidaps.data.Profile; - -public class BasalScheduleMapper { - // TODO add tests - public static BasalSchedule mapProfileToBasalSchedule(Profile profile) { - Profile.ProfileValue[] basalValues = profile.getBasalValues(); - List entries = new ArrayList<>(); - for(Profile.ProfileValue basalValue : basalValues) { - entries.add(new BasalScheduleEntry(basalValue.value, Duration.standardSeconds(basalValue.timeAsSeconds))); - } - - return new BasalSchedule(entries); - } -} 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 35dd152157..7e9e5fc947 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 @@ -2,6 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm; import org.jetbrains.annotations.Nullable; import org.joda.time.DateTime; +import org.joda.time.Duration; + +import java.util.ArrayList; +import java.util.List; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; @@ -10,14 +14,14 @@ import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; 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.action.OmnipodAction; 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; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleEntry; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; -import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntry; import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntryType; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; @@ -48,7 +52,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface } return result; } else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) { - PumpEnactResult result = delegate.insertCannula(profile, res -> { + PumpEnactResult result = delegate.insertCannula(mapProfileToBasalSchedule(profile), res -> { podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res)); OmnipodUtil.setPodSessionState(delegate.getPodState()); RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); @@ -82,7 +86,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface @Override public PumpEnactResult setBasalProfile(Profile basalProfile) { - return delegate.setBasalProfile(basalProfile); + return delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile)); } @Override @@ -179,12 +183,25 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface String comment = null; switch(res.getResultType()) { case FAILURE: + // TODO use string resource comment = "Unexpected setup progress: "+ res.getSetupProgress(); break; case VERIFICATION_FAILURE: + // TODO use string resource comment = "Verification failed: "+ res.getException().getClass().getSimpleName() +": "+ res.getException().getMessage(); break; } return comment; } + + // TODO add tests + static BasalSchedule mapProfileToBasalSchedule(Profile profile) { + Profile.ProfileValue[] basalValues = profile.getBasalValues(); + List entries = new ArrayList<>(); + for(Profile.ProfileValue basalValue : basalValues) { + entries.add(new BasalScheduleEntry(basalValue.value, Duration.standardSeconds(basalValue.timeAsSeconds))); + } + + return new BasalSchedule(entries); + } }