Introduce AapsOmnipodManager to match OmnipodCommunicationManagerInterface interface

This commit is contained in:
Bart Sopers 2019-09-01 22:54:59 +02:00
parent c6d94284d7
commit 5ac0df4b4b
5 changed files with 134 additions and 56 deletions

View file

@ -0,0 +1,125 @@
package info.nightscout.androidaps.plugins.pump.omnipod;
import org.joda.time.DateTime;
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.OmnipodCommunicationService;
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.state.PodSessionState;
public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface {
private final OmnipodManager delegate;
private static AapsOmnipodManager instance;
// FIXME this is dirty
public static AapsOmnipodManager getInstance() {
return instance;
}
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) {
delegate = new OmnipodManager(communicationService, podState);
instance = this;
}
@Override
public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver) {
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
PumpEnactResult result = delegate.pairAndPrime();
podInitReceiver.returnInitTaskStatus(podInitActionType, result.success, (result.success ? null : result.comment));
return result;
} else if(PodInitActionType.FillCannulaWizardStep.equals(podInitActionType)) {
// FIXME we need a basal profile here
PumpEnactResult result = delegate.insertCannula(null);
podInitReceiver.returnInitTaskStatus(podInitActionType, result.success, (result.success ? null : result.comment));
return result;
}
return new PumpEnactResult().success(false).enacted(false).comment("Illegal PodInitActionType: "+ podInitActionType.name());
}
@Override
public PumpEnactResult getPodStatus() {
return delegate.getPodStatus();
}
@Override
public PumpEnactResult deactivatePod() {
return delegate.deactivatePod();
}
@Override
public PumpEnactResult setBasalProfile(Profile basalProfile) {
return delegate.setBasalProfile(basalProfile);
}
@Override
public PumpEnactResult resetPodStatus() {
return delegate.resetPodState();
}
@Override
public PumpEnactResult setBolus(Double amount) {
return delegate.bolus(amount);
}
@Override
public PumpEnactResult cancelBolus() {
return delegate.cancelBolus();
}
@Override
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
return delegate.setTemporaryBasal(tempBasalPair);
}
@Override
public PumpEnactResult cancelTemporaryBasal() {
return delegate.cancelTemporaryBasal();
}
@Override
public PumpEnactResult acknowledgeAlerts() {
return delegate.acknowledgeAlerts();
}
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult getPodInfo(PodInfoType podInfoType) {
return delegate.getPodInfo(podInfoType);
}
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult suspendDelivery() {
return delegate.suspendDelivery();
}
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult resumeDelivery() {
return delegate.resumeDelivery();
}
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult setTime() {
return delegate.setTime();
}
public OmnipodCommunicationService getCommunicationService() {
return delegate.getCommunicationService();
}
public DateTime getTime() {
return delegate.getTime();
}
public boolean isInitialized() {
return delegate.isInitialized();
}
public String getPodStateAsString() {
return delegate.getPodStateAsString();
}
}

View file

@ -32,25 +32,16 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.SetTe
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.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.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.PodInitReceiver;
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.BasalScheduleMapper;
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;
public class OmnipodManager implements OmnipodCommunicationManagerInterface { public class OmnipodManager {
private final OmnipodCommunicationService communicationService; private final OmnipodCommunicationService communicationService;
private PodSessionState podState; private PodSessionState podState;
private static OmnipodManager instance;
// FIXME this is dirty
public static OmnipodManager getInstance() {
return instance;
}
public OmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) { public OmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) {
if (communicationService == null) { if (communicationService == null) {
@ -58,10 +49,8 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
} }
this.communicationService = communicationService; this.communicationService = communicationService;
this.podState = podState; this.podState = podState;
instance = this;
} }
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)) {
// TODO use string resource // TODO use string resource
@ -88,7 +77,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
public PumpEnactResult pairAndPrime() { public PumpEnactResult pairAndPrime() {
try { try {
if (podState == null) { if (podState == null) {
@ -114,7 +102,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult cancelBolus() { public PumpEnactResult cancelBolus() {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -131,12 +118,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podIniReceiver) {
return null;
}
@Override
public PumpEnactResult getPodStatus() { public PumpEnactResult getPodStatus() {
if (podState == null) { if (podState == null) {
// TODO use string resource // TODO use string resource
@ -155,7 +136,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult deactivatePod() { public PumpEnactResult deactivatePod() {
if (podState == null) { if (podState == null) {
// TODO use string resource // TODO use string resource
@ -174,7 +154,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult setBasalProfile(Profile basalProfile) { public PumpEnactResult setBasalProfile(Profile basalProfile) {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -193,18 +172,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult resetPodStatus() {
return null;
}
@Override
public PumpEnactResult setBolus(Double amount) {
return null;
}
// TODO rename back
public PumpEnactResult resetPodState() { public PumpEnactResult resetPodState() {
podState = null; podState = null;
SP.remove(OmnipodConst.Prefs.PodState); SP.remove(OmnipodConst.Prefs.PodState);
@ -212,7 +179,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
// TODO rename back
public PumpEnactResult bolus(Double units) { public PumpEnactResult bolus(Double units) {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -229,7 +195,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) { public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -248,7 +213,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult cancelTemporaryBasal() { public PumpEnactResult cancelTemporaryBasal() {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -265,7 +229,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@Override
public PumpEnactResult acknowledgeAlerts() { public PumpEnactResult acknowledgeAlerts() {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -299,7 +262,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult suspendDelivery() { public PumpEnactResult suspendDelivery() {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -316,7 +278,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult resumeDelivery() { public PumpEnactResult resumeDelivery() {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();
@ -334,7 +295,6 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult setTime() { public PumpEnactResult setTime() {
if (!isInitialized()) { if (!isInitialized()) {
return createNotInitializedResult(); return createNotInitializedResult();

View file

@ -109,7 +109,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
OmnipodUtil.setOmnipodPodType(OmnipodPodType.Eros); OmnipodUtil.setOmnipodPodType(OmnipodPodType.Eros);
if (omnipodCommunicationManager == null) { if (omnipodCommunicationManager == null) {
omnipodCommunicationManager = OmnipodManager.getInstance(); omnipodCommunicationManager = AapsOmnipodManager.getInstance();
} }
omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager); omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager);

View file

@ -11,14 +11,7 @@ public interface OmnipodCommunicationManagerInterface {
/** /**
* Initialize Pod * Initialize Pod
*/ */
PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podIniReceiver); PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver);
// TODO remove
//PumpEnactResult pairAndPrime();
// TODO remove
//PumpEnactResult insertCannula(Profile basalProfile);
/** /**
* Get Pod Status (is pod running, battery left ?, reservoir, etc) * Get Pod Status (is pod running, battery left ?, reservoir, etc)

View file

@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
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.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
@ -112,7 +112,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
} }
private void initializeErosOmnipodManager() { private void initializeErosOmnipodManager() {
if(OmnipodManager.getInstance() == null) { if(AapsOmnipodManager.getInstance() == null) {
PodSessionState podState = null; PodSessionState podState = null;
if (SP.contains(OmnipodConst.Prefs.PodState)) { if (SP.contains(OmnipodConst.Prefs.PodState)) {
try { try {
@ -123,9 +123,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
LOG.error("Could not deserialize Pod state: " + ex.getClass().getSimpleName() + ": " + ex.getMessage()); LOG.error("Could not deserialize Pod state: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
} }
} }
omnipodCommunicationManager = new OmnipodManager(new OmnipodCommunicationService(rfspy), podState); omnipodCommunicationManager = new AapsOmnipodManager(new OmnipodCommunicationService(rfspy), podState);
} else { } else {
omnipodCommunicationManager = OmnipodManager.getInstance(); omnipodCommunicationManager = AapsOmnipodManager.getInstance();
} }
} }
@ -137,8 +137,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Override @Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() { public RileyLinkCommunicationManager getDeviceCommunicationManager() {
if(omnipodCommunicationManager instanceof OmnipodManager) { // Eros if(omnipodCommunicationManager instanceof AapsOmnipodManager) { // Eros
return ((OmnipodManager) omnipodCommunicationManager).getCommunicationService(); return ((AapsOmnipodManager) omnipodCommunicationManager).getCommunicationService();
} }
// FIXME is this correct for Dash? // FIXME is this correct for Dash?
return (RileyLinkCommunicationManager)omnipodCommunicationManager; return (RileyLinkCommunicationManager)omnipodCommunicationManager;