Move exception handling and PumpEnactResult creation from OmnipodManager to AapsOmnipodManager
This commit is contained in:
parent
f2e439a485
commit
71db5e541e
|
@ -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.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;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.BolusAction;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.BolusAction;
|
||||||
|
@ -52,74 +51,37 @@ public class OmnipodManager {
|
||||||
this.podState = podState;
|
this.podState = podState;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a PumpEnactResult which describes whether or not all commands have been sent successfully
|
// After priming should have been finished, the pod state is verified.
|
||||||
// After priming should have finished (55 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 pairAndPrime(SetupActionResultHandler resultHandler) {
|
public void pairAndPrime(SetupActionResultHandler resultHandler) {
|
||||||
try {
|
if (podState == null) {
|
||||||
if (podState == null) {
|
podState = communicationService.executeAction(new PairAction(new PairService()));
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
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 been finished, 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(BasalSchedule basalSchedule, SetupActionResultHandler resultHandler) {
|
public void 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
|
throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, podState == null ? null : podState.getSetupProgress());
|
||||||
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)) {
|
||||||
// TODO use string resource
|
throw new IllegalSetupProgressException(SetupProgress.CANNULA_INSERTING, podState.getSetupProgress());
|
||||||
return new PumpEnactResult().success(false).enacted(false).comment("Illegal setup state: " + podState.getSetupProgress().name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, basalSchedule));
|
||||||
communicationService.executeAction(new InsertCannulaAction(new InsertCannulaService(), podState, basalSchedule));
|
|
||||||
|
|
||||||
executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), //
|
executeDelayed(() -> verifySetupAction(statusResponse -> InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), //
|
||||||
SetupProgress.COMPLETED, resultHandler),
|
SetupProgress.COMPLETED, resultHandler),
|
||||||
calculateBolusDuration(OmnipodConst.POD_CANNULA_INSERTION_BOLUS_UNITS, OmnipodConst.POD_CANNULA_INSERTION_DELIVERY_RATE));
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatusResponse getPodStatus() {
|
public StatusResponse getPodStatus() {
|
||||||
|
@ -130,204 +92,108 @@ public class OmnipodManager {
|
||||||
return communicationService.executeAction(new GetStatusAction(podState));
|
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) {
|
if (podState == null) {
|
||||||
// TODO use string resource
|
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null);
|
||||||
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).comment(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PumpEnactResult().success(true).enacted(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpEnactResult setBasalSchedule(BasalSchedule schedule) {
|
public void resetPodState() {
|
||||||
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() {
|
|
||||||
podState = null;
|
podState = null;
|
||||||
SP.remove(OmnipodConst.Prefs.PodState);
|
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() {
|
public OmnipodCommunicationService getCommunicationService() {
|
||||||
|
@ -338,16 +204,20 @@ public class OmnipodManager {
|
||||||
return podState.getTime();
|
return podState.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isReadyForDelivery() {
|
||||||
return podState != null && podState.getSetupProgress() == SetupProgress.COMPLETED;
|
return podState != null && podState.getSetupProgress() == SetupProgress.COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PodSessionState getPodState() {
|
||||||
|
return this.podState;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPodStateAsString() {
|
public String getPodStateAsString() {
|
||||||
return podState == null ? "null" : podState.toString();
|
return podState == null ? "null" : podState.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Duration calculateBolusDuration(double units, double deliveryRate) {
|
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) {
|
private void executeDelayed(Runnable r, Duration timeout) {
|
||||||
|
@ -355,13 +225,10 @@ public class OmnipodManager {
|
||||||
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);
|
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PumpEnactResult createNotInitializedResult() {
|
private void assertReadyForDelivery() {
|
||||||
// TODO use string resource
|
if (!isReadyForDelivery()) {
|
||||||
return new PumpEnactResult().success(false).enacted(false).comment("Pod should be initialized first");
|
throw new IllegalSetupProgressException(SetupProgress.COMPLETED, podState == null ? null : podState.getSetupProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PodSessionState getPodState() {
|
|
||||||
return this.podState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifySetupAction(StatusResponseHandler statusResponseHandler, SetupProgress expectedSetupProgress, SetupActionResultHandler resultHandler) {
|
private void verifySetupAction(StatusResponseHandler statusResponseHandler, SetupProgress expectedSetupProgress, SetupActionResultHandler resultHandler) {
|
||||||
|
|
|
@ -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.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.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.PodInfoResponse;
|
||||||
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;
|
||||||
|
@ -45,23 +46,30 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) {
|
public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) {
|
||||||
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
|
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
|
||||||
PumpEnactResult result = delegate.pairAndPrime(res -> //
|
try {
|
||||||
podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res)));
|
delegate.pairAndPrime(res -> //
|
||||||
if (!result.success) {
|
podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res)));
|
||||||
podInitReceiver.returnInitTaskStatus(podInitActionType, false, result.comment);
|
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)) {
|
} else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) {
|
||||||
PumpEnactResult result = delegate.insertCannula(mapProfileToBasalSchedule(profile), res -> {
|
try {
|
||||||
podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res));
|
delegate.insertCannula(mapProfileToBasalSchedule(profile), res -> {
|
||||||
OmnipodUtil.setPodSessionState(delegate.getPodState());
|
podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), createCommentForSetupActionResult(res));
|
||||||
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
|
OmnipodUtil.setPodSessionState(delegate.getPodState());
|
||||||
});
|
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
|
||||||
if (!result.success) {
|
});
|
||||||
podInitReceiver.returnInitTaskStatus(podInitActionType, false, result.comment);
|
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());
|
return new PumpEnactResult().success(false).enacted(false).comment("Illegal PodInitActionType: " + podInitActionType.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,77 +78,120 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
try {
|
try {
|
||||||
StatusResponse statusResponse = delegate.getPodStatus();
|
StatusResponse statusResponse = delegate.getPodStatus();
|
||||||
return new PumpEnactResult().success(true).enacted(false);
|
return new PumpEnactResult().success(true).enacted(false);
|
||||||
} catch(Exception ex) {
|
} catch (Exception ex) {
|
||||||
// TODO return string resource
|
// TODO use string resource instead of exception message
|
||||||
return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage());
|
return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
|
public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
|
||||||
|
try {
|
||||||
PumpEnactResult result = delegate.deactivatePod();
|
delegate.deactivatePod();
|
||||||
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, result.success, (result.success ? null : result.comment));
|
} catch (Exception ex) {
|
||||||
|
// TODO use string resource instead of exception message
|
||||||
if (result.success) {
|
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, ex.getMessage());
|
||||||
OmnipodUtil.setPodSessionState(null);
|
return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage());
|
||||||
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, true, null);
|
||||||
|
|
||||||
|
OmnipodUtil.setPodSessionState(null);
|
||||||
|
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
|
||||||
|
|
||||||
|
return new PumpEnactResult().success(true).enacted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setBasalProfile(Profile basalProfile) {
|
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
|
@Override
|
||||||
public PumpEnactResult resetPodStatus() {
|
public PumpEnactResult resetPodStatus() {
|
||||||
|
delegate.resetPodState();
|
||||||
PumpEnactResult result = delegate.resetPodState();
|
|
||||||
|
|
||||||
//addToHistory(System.currentTimeMillis(), PodDbEntryType.ResetPodState, null, null, null, null);
|
//addToHistory(System.currentTimeMillis(), PodDbEntryType.ResetPodState, null, null, null, null);
|
||||||
|
|
||||||
OmnipodUtil.setPodSessionState(null);
|
OmnipodUtil.setPodSessionState(null);
|
||||||
|
|
||||||
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
|
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
|
||||||
|
|
||||||
return result;
|
return new PumpEnactResult().success(true).enacted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setBolus(Double amount) {
|
public PumpEnactResult setBolus(Double amount) {
|
||||||
return delegate.bolus(amount, statusResponse -> {
|
try {
|
||||||
if(statusResponse == null) {
|
delegate.bolus(amount, statusResponse -> {
|
||||||
// Failed to retrieve status response after bolus
|
if (statusResponse == null) {
|
||||||
// Bolus probably finished anyway
|
// Failed to retrieve status response after bolus
|
||||||
} else if(statusResponse.getDeliveryStatus().isBolusing()) {
|
// Bolus probably finished anyway
|
||||||
// This shouldn't happen
|
} else if (statusResponse.getDeliveryStatus().isBolusing()) {
|
||||||
} else {
|
// This shouldn't happen
|
||||||
// Bolus successfully completed
|
} 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
|
@Override
|
||||||
public PumpEnactResult cancelBolus() {
|
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
|
@Override
|
||||||
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
|
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
|
@Override
|
||||||
public PumpEnactResult cancelTemporaryBasal() {
|
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
|
@Override
|
||||||
public PumpEnactResult acknowledgeAlerts() {
|
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
|
@Override
|
||||||
|
@ -151,20 +202,51 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
|
|
||||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
public PumpEnactResult getPodInfo(PodInfoType podInfoType) {
|
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() {
|
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() {
|
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?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
public PumpEnactResult setTime() {
|
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() {
|
public OmnipodCommunicationService getCommunicationService() {
|
||||||
|
@ -176,7 +258,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return delegate.isInitialized();
|
return delegate.isReadyForDelivery();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPodStateAsString() {
|
public String getPodStateAsString() {
|
||||||
|
|
Loading…
Reference in a new issue