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.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

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