Move basal profile mapping to AapsOmnipodManager

This commit is contained in:
Bart Sopers 2019-11-27 22:13:48 +01:00
parent f2615d977b
commit 120243908f
3 changed files with 26 additions and 33 deletions

View file

@ -10,7 +10,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; 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.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.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; 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.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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.SP; 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 // 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 finished (10 seconds), the pod state is verified.
// The result of that verification is passed to the SetupActionResultHandler // 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)) { if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
// TODO use string resource // TODO use string resource
return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first"); return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first");
@ -92,8 +91,7 @@ public class OmnipodManager {
} }
try { try {
communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, basalSchedule));
BasalScheduleMapper.mapProfileToBasalSchedule(profile)));
executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), // executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), //
SetupProgress.COMPLETED, resultHandler), SetupProgress.COMPLETED, resultHandler),
@ -159,14 +157,13 @@ public class OmnipodManager {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
public PumpEnactResult setBasalProfile(Profile basalProfile) { public PumpEnactResult setBasalSchedule(BasalSchedule schedule) {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
} }
try { try {
communicationService.executeAction(new SetBasalScheduleAction(podState, communicationService.executeAction(new SetBasalScheduleAction(podState, schedule,
BasalScheduleMapper.mapProfileToBasalSchedule(basalProfile),
false, podState.getScheduleOffset(), true)); false, podState.getScheduleOffset(), true));
} catch (Exception ex) { } catch (Exception ex) {
// TODO distinguish between certain and uncertain failures // TODO distinguish between certain and uncertain failures

View file

@ -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<BasalScheduleEntry> entries = new ArrayList<>();
for(Profile.ProfileValue basalValue : basalValues) {
entries.add(new BasalScheduleEntry(basalValue.value, Duration.standardSeconds(basalValue.timeAsSeconds)));
}
return new BasalSchedule(entries);
}
}

View file

@ -2,6 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joda.time.DateTime; 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.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; 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.OmnipodCommunicationService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; 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.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.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; 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.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; 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.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; 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.driver.db.PodDbEntryType;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -48,7 +52,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
return result; return result;
} else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) { } 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)); podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res));
OmnipodUtil.setPodSessionState(delegate.getPodState()); OmnipodUtil.setPodSessionState(delegate.getPodState());
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
@ -82,7 +86,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult setBasalProfile(Profile basalProfile) { public PumpEnactResult setBasalProfile(Profile basalProfile) {
return delegate.setBasalProfile(basalProfile); return delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile));
} }
@Override @Override
@ -179,12 +183,25 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
String comment = null; String comment = null;
switch(res.getResultType()) { switch(res.getResultType()) {
case FAILURE: case FAILURE:
// TODO use string resource
comment = "Unexpected setup progress: "+ res.getSetupProgress(); comment = "Unexpected setup progress: "+ res.getSetupProgress();
break; break;
case VERIFICATION_FAILURE: case VERIFICATION_FAILURE:
// TODO use string resource
comment = "Verification failed: "+ res.getException().getClass().getSimpleName() +": "+ res.getException().getMessage(); comment = "Verification failed: "+ res.getException().getClass().getSimpleName() +": "+ res.getException().getMessage();
break; break;
} }
return comment; return comment;
} }
// TODO add tests
static BasalSchedule mapProfileToBasalSchedule(Profile profile) {
Profile.ProfileValue[] basalValues = profile.getBasalValues();
List<BasalScheduleEntry> entries = new ArrayList<>();
for(Profile.ProfileValue basalValue : basalValues) {
entries.add(new BasalScheduleEntry(basalValue.value, Duration.standardSeconds(basalValue.timeAsSeconds)));
}
return new BasalSchedule(entries);
}
} }