Remove redundant interface and split initPod into two separate methods

This commit is contained in:
Bart Sopers 2020-08-23 17:12:49 +02:00
parent 4a10a04f79
commit afd890a519
3 changed files with 50 additions and 129 deletions

View file

@ -1,74 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
import info.nightscout.androidaps.data.DetailedBolusInfo;
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.message.response.podinfo.PodInfoRecentPulseLog;
// TODO remove?
// We only have this interface for possible Omnipod Dash implementation
public interface IOmnipodManager {
/**
* Initialize Pod
*/
PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile);
/**
* Get Pod Status (is pod running, battery left ?, reservoir, etc)
*/
// TODO we should probably return a (wrapped) StatusResponse instead of a PumpEnactResult
PumpEnactResult getPodStatus();
/**
* Deactivate Pod
*/
PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver);
/**
* Set Basal Profile
*/
PumpEnactResult setBasalProfile(Profile basalProfile);
/**
* Reset Pod status (if we forget to disconnect Pod and want to init new pod, and want to forget current pod)
*/
PumpEnactResult resetPodStatus();
/**
* Set Bolus
*
* @param detailedBolusInfo DetailedBolusInfo instance with amount and all other required data
*/
PumpEnactResult bolus(DetailedBolusInfo detailedBolusInfo);
/**
* Cancel Bolus (if bolus is already stopped, return acknowledgment)
*/
PumpEnactResult cancelBolus();
/**
* Set Temporary Basal
*
* @param tempBasalPair TempBasalPair object containg amount and duration in minutes
*/
PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair);
/**
* Cancel Temporary Basal (if TB is already stopped, return acknowledgment)
*/
PumpEnactResult cancelTemporaryBasal();
/**
* Acknowledge alerts
*/
PumpEnactResult acknowledgeAlerts();
/**
* Set Time on Pod
*/
PumpEnactResult setTime();
PodInfoRecentPulseLog readPulseLog();
}

View file

@ -35,13 +35,12 @@ public class InitPodTask extends AsyncTask<Void, Void, String> {
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
initActionFragment.callResult = aapsOmnipodManager.initPod( initActionFragment.callResult = aapsOmnipodManager.pairAndPrime(
initActionFragment.podInitActionType, initActionFragment.podInitActionType,
initActionFragment, initActionFragment
null
); );
} else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) { } else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
initActionFragment.callResult = aapsOmnipodManager.initPod( initActionFragment.callResult = aapsOmnipodManager.setInitialBasalScheduleAndInsertCannula(
initActionFragment.podInitActionType, initActionFragment.podInitActionType,
initActionFragment, initActionFragment,
profileFunction.getProfile() profileFunction.getProfile()

View file

@ -60,7 +60,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.Sta
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
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.FaultEventCode; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
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;
@ -77,7 +76,7 @@ import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.SingleSubject; import io.reactivex.subjects.SingleSubject;
@Singleton @Singleton
public class AapsOmnipodManager implements IOmnipodManager { public class AapsOmnipodManager {
private final PodStateManager podStateManager; private final PodStateManager podStateManager;
private final OmnipodUtil omnipodUtil; private final OmnipodUtil omnipodUtil;
@ -142,47 +141,54 @@ public class AapsOmnipodManager implements IOmnipodManager {
timeChangeEventEnabled = sp.getBoolean(OmnipodConst.Prefs.TimeChangeEventEnabled, true); timeChangeEventEnabled = sp.getBoolean(OmnipodConst.Prefs.TimeChangeEventEnabled, true);
} }
@Override public PumpEnactResult pairAndPrime(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver) {
public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) { if (podInitActionType != PodInitActionType.PairAndPrimeWizardStep) {
long time = System.currentTimeMillis(); return new PumpEnactResult(injector).success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_illegal_init_action_type, podInitActionType.name()));
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
try {
Disposable disposable = delegate.pairAndPrime().subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment);
addFailureToHistory(time, PodHistoryEntryType.PairAndPrime, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}
} else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) {
try {
BasalSchedule basalSchedule;
try {
basalSchedule = mapProfileToBasalSchedule(profile);
} catch (Exception ex) {
throw new CommandInitializationException("Basal profile mapping failed", ex);
}
Disposable disposable = delegate.insertCannula(basalSchedule).subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, profile));
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment);
addFailureToHistory(time, PodHistoryEntryType.FillCannulaSetBasalProfile, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}
} }
return new PumpEnactResult(injector).success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_illegal_init_action_type, podInitActionType.name())); long time = System.currentTimeMillis();
try {
Disposable disposable = delegate.pairAndPrime().subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment);
addFailureToHistory(time, PodHistoryEntryType.PairAndPrime, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}
}
public PumpEnactResult setInitialBasalScheduleAndInsertCannula(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) {
if (podInitActionType != PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
return new PumpEnactResult(injector).success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_illegal_init_action_type, podInitActionType.name()));
}
long time = System.currentTimeMillis();
try {
BasalSchedule basalSchedule;
try {
basalSchedule = mapProfileToBasalSchedule(profile);
} catch (Exception ex) {
throw new CommandInitializationException("Basal profile mapping failed", ex);
}
Disposable disposable = delegate.insertCannula(basalSchedule).subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, profile));
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment);
addFailureToHistory(time, PodHistoryEntryType.FillCannulaSetBasalProfile, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}
} }
@Override
public PumpEnactResult getPodStatus() { public PumpEnactResult getPodStatus() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
@ -196,7 +202,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
} }
} }
@Override
public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
@ -217,7 +222,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@Override
public PumpEnactResult setBasalProfile(Profile profile) { public PumpEnactResult setBasalProfile(Profile profile) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
@ -246,7 +250,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@Override
public PumpEnactResult resetPodStatus() { public PumpEnactResult resetPodStatus() {
podStateManager.removeState(); podStateManager.removeState();
@ -257,7 +260,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@Override
public PumpEnactResult bolus(DetailedBolusInfo detailedBolusInfo) { public PumpEnactResult bolus(DetailedBolusInfo detailedBolusInfo) {
OmnipodManager.BolusCommandResult bolusCommandResult; OmnipodManager.BolusCommandResult bolusCommandResult;
@ -325,7 +327,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin); return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin);
} }
@Override
public PumpEnactResult cancelBolus() { public PumpEnactResult cancelBolus() {
SingleSubject<Boolean> bolusCommandExecutionSubject = delegate.getBolusCommandExecutionSubject(); SingleSubject<Boolean> bolusCommandExecutionSubject = delegate.getBolusCommandExecutionSubject();
if (bolusCommandExecutionSubject != null) { if (bolusCommandExecutionSubject != null) {
@ -365,7 +366,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment); return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
} }
@Override
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) { public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
boolean beepsEnabled = isTbrBeepsEnabled(); boolean beepsEnabled = isTbrBeepsEnabled();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
@ -398,7 +398,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@Override
public PumpEnactResult cancelTemporaryBasal() { public PumpEnactResult cancelTemporaryBasal() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
@ -413,7 +412,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@Override
public PumpEnactResult acknowledgeAlerts() { public PumpEnactResult acknowledgeAlerts() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
@ -427,7 +425,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult getPodInfo(PodInfoType podInfoType) { public PumpEnactResult getPodInfo(PodInfoType podInfoType) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
@ -467,9 +464,8 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
// Updates the pods current time based on the device timezone and the pod's time zone // Updates the pods current time based on the device timezone and the pod's time zone
@Override public PumpEnactResult setTime() { public PumpEnactResult setTime() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
delegate.setTime(isBasalBeepsEnabled()); delegate.setTime(isBasalBeepsEnabled());
@ -491,7 +487,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@Override public PodInfoRecentPulseLog readPulseLog() { public PodInfoRecentPulseLog readPulseLog() {
PodInfoResponse response = delegate.getPodInfo(PodInfoType.RECENT_PULSE_LOG); PodInfoResponse response = delegate.getPodInfo(PodInfoType.RECENT_PULSE_LOG);
return response.getPodInfo(); return response.getPodInfo();
} }