Return PumpEnactResult instead of throwing Exceptions in OmnipodManager
This commit is contained in:
parent
ed52070a4c
commit
83d95f1e87
1 changed files with 176 additions and 62 deletions
|
@ -30,7 +30,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PairS
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.SetTempBasalService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.SetTempBasalService;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfo;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
|
||||||
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.OmnipodCommunicationManagerInterface;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
|
||||||
|
@ -63,11 +62,14 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult insertCannula(Profile profile) {
|
public PumpEnactResult insertCannula(Profile profile) {
|
||||||
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
|
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
|
||||||
throw new IllegalArgumentException("Pod should be paired and primed first");
|
// TODO use string resource
|
||||||
|
return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first");
|
||||||
} else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
|
} else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
|
||||||
throw new IllegalStateException("Illegal setup state: " + podState.getSetupProgress().name());
|
// TODO use string resource
|
||||||
|
return new PumpEnactResult().success(false).enacted(false).comment("Illegal setup state: " + podState.getSetupProgress().name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState,
|
communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState,
|
||||||
BasalScheduleMapper.mapProfileToBasalSchedule(profile)));
|
BasalScheduleMapper.mapProfileToBasalSchedule(profile)));
|
||||||
|
|
||||||
|
@ -75,12 +77,18 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState));
|
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState));
|
||||||
InsertCannulaAction.updateCannulaInsertionStatus(podState, delayedStatusResponse);
|
InsertCannulaAction.updateCannulaInsertionStatus(podState, delayedStatusResponse);
|
||||||
}, OmnipodConst.POD_CANNULA_INSERTION_DURATION);
|
}, OmnipodConst.POD_CANNULA_INSERTION_DURATION);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// TODO distinguish between certain and uncertain failures
|
||||||
|
// TODO user friendly error messages (string resources)
|
||||||
|
return new PumpEnactResult().success(false).enacted(false);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult pairAndPrime() {
|
public PumpEnactResult pairAndPrime() {
|
||||||
|
try {
|
||||||
if (podState == null) {
|
if (podState == null) {
|
||||||
podState = communicationService.executeAction(new PairAction(new PairService()));
|
podState = communicationService.executeAction(new PairAction(new PairService()));
|
||||||
}
|
}
|
||||||
|
@ -92,7 +100,13 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
PrimeAction.updatePrimingStatus(podState, delayedStatusResponse);
|
PrimeAction.updatePrimingStatus(podState, delayedStatusResponse);
|
||||||
}, OmnipodConst.POD_PRIME_DURATION);
|
}, OmnipodConst.POD_PRIME_DURATION);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Illegal setup state: " + podState.getSetupProgress().name());
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
|
@ -101,9 +115,16 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelBolus() {
|
public PumpEnactResult cancelBolus() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
@ -111,20 +132,37 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult getPodStatus() {
|
public PumpEnactResult getPodStatus() {
|
||||||
if (podState == null) {
|
if (podState == null) {
|
||||||
throw new IllegalStateException("Pod should be paired first");
|
// TODO use string resource
|
||||||
|
return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// TODO how can we return the status response? Also refer to TODO in interface
|
||||||
|
StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// TODO distinguish between certain and uncertain failures
|
||||||
|
// TODO user friendly error messages (string resources)
|
||||||
|
return new PumpEnactResult().success(false).enacted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return communicationService.executeAction(new GetStatusAction(podState));
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deactivatePod() {
|
public PumpEnactResult deactivatePod() {
|
||||||
if (podState == null) {
|
if (podState == null) {
|
||||||
throw new IllegalStateException("Pod should be paired first");
|
// TODO use string resource
|
||||||
|
return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new DeactivatePodAction(podState, true));
|
communicationService.executeAction(new DeactivatePodAction(podState, true));
|
||||||
resetPodState();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
@ -132,11 +170,18 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setBasalProfile(Profile basalProfile) {
|
public PumpEnactResult setBasalProfile(Profile basalProfile) {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new SetBasalScheduleAction(podState,
|
communicationService.executeAction(new SetBasalScheduleAction(podState,
|
||||||
BasalScheduleMapper.mapProfileToBasalSchedule(basalProfile),
|
BasalScheduleMapper.mapProfileToBasalSchedule(basalProfile),
|
||||||
false, podState.getScheduleOffset(), true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
@ -152,9 +197,16 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult bolus(Double units) {
|
public PumpEnactResult bolus(Double units) {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new BolusAction(podState, units, true, true));
|
communicationService.executeAction(new BolusAction(podState, units, 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);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
@ -162,11 +214,18 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
|
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(),
|
communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(),
|
||||||
podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()),
|
podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()),
|
||||||
true, true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
@ -174,9 +233,16 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelTemporaryBasal() {
|
public PumpEnactResult cancelTemporaryBasal() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
@ -184,43 +250,79 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult acknowledgeAlerts() {
|
public PumpEnactResult acknowledgeAlerts() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts()));
|
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);
|
||||||
|
}
|
||||||
return null; // TODO
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
public <T extends PodInfo> T getPodInfo(PodInfoType podInfoType) {
|
public PumpEnactResult getPodInfo(PodInfoType podInfoType) {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// TODO how can we return the PodInfo response?
|
||||||
PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, podInfoType));
|
PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, podInfoType));
|
||||||
return podInfoResponse.getPodInfo();
|
} catch (Exception ex) {
|
||||||
|
// TODO distinguish between certain and uncertain failures
|
||||||
|
// TODO user friendly error messages (string resources)
|
||||||
|
return new PumpEnactResult().success(false).enacted(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
public void suspendDelivery() {
|
public PumpEnactResult suspendDelivery() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
public void resumeDelivery() {
|
public PumpEnactResult resumeDelivery() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(),
|
communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(),
|
||||||
true, podState.getScheduleOffset(), true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
public void setTime() {
|
public PumpEnactResult setTime() {
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
throw new IllegalStateException("Pod should be initialized first");
|
return createNotInitializedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Suspend delivery
|
// Suspend delivery
|
||||||
communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), false));
|
communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), false));
|
||||||
|
|
||||||
|
@ -231,6 +333,13 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
// Resume delivery
|
// Resume delivery
|
||||||
communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(),
|
communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(),
|
||||||
true, podState.getScheduleOffset(), true));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public OmnipodCommunicationService getCommunicationService() {
|
public OmnipodCommunicationService getCommunicationService() {
|
||||||
|
@ -253,4 +362,9 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
||||||
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue