Replace PodCommsResponse with PumpEnactResult

This commit is contained in:
Bart Sopers 2019-08-29 20:40:34 +02:00
parent 78f402a367
commit ed52070a4c
6 changed files with 88 additions and 128 deletions

View file

@ -11,6 +11,7 @@ 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.OmnipodCommunicationService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AcknowledgeAlertsAction;
@ -28,7 +29,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.Inser
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PairService;
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.data.PodCommResponse;
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;
@ -60,12 +60,8 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
instance = this;
}
public OmnipodManager(OmnipodCommunicationService communicationService) {
this(communicationService, null);
}
@Override
public PodCommResponse insertCannula(Profile profile) {
public PumpEnactResult insertCannula(Profile profile) {
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
throw new IllegalArgumentException("Pod should be paired and primed first");
} else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
@ -84,7 +80,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse pairAndPrime() {
public PumpEnactResult pairAndPrime() {
if (podState == null) {
podState = communicationService.executeAction(new PairAction(new PairService()));
}
@ -103,7 +99,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse cancelBolus() {
public PumpEnactResult cancelBolus() {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
@ -113,7 +109,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse getPodStatus() {
public PumpEnactResult getPodStatus() {
if (podState == null) {
throw new IllegalStateException("Pod should be paired first");
}
@ -123,7 +119,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse deactivatePod() {
public PumpEnactResult deactivatePod() {
if (podState == null) {
throw new IllegalStateException("Pod should be paired first");
}
@ -134,7 +130,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse setBasalProfile(Profile basalProfile) {
public PumpEnactResult setBasalProfile(Profile basalProfile) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
@ -146,7 +142,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse resetPodState() {
public PumpEnactResult resetPodState() {
podState = null;
SP.remove(OmnipodConst.Prefs.PodState);
@ -154,7 +150,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse bolus(Double units) {
public PumpEnactResult bolus(Double units) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
@ -164,7 +160,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair) {
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
@ -176,7 +172,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse cancelTemporaryBasal() {
public PumpEnactResult cancelTemporaryBasal() {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
@ -186,7 +182,7 @@ public class OmnipodManager implements OmnipodCommunicationManagerInterface {
}
@Override
public PodCommResponse acknowledgeAlerts() {
public PumpEnactResult acknowledgeAlerts() {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}

View file

@ -113,12 +113,14 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
serviceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
if (isLoggingEnabled())
LOG.debug("RileyLinkOmnipodService is disconnected");
omnipodService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
if (isLoggingEnabled())
LOG.debug("RileyLinkOmnipodService is connected");
@ -143,12 +145,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
};
}
protected OmnipodPumpPlugin(PluginDescription pluginDescription, PumpType pumpType) {
super(pluginDescription, pumpType);
}
public static OmnipodPumpPlugin getPlugin() {
if (plugin == null)
plugin = new OmnipodPumpPlugin();
@ -186,6 +186,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
}
@Override
public void onStartCustomActions() {
// check status every minute (if any status needs refresh we send readStatus command)
@ -204,6 +205,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
}
@Override
public Class getServiceClass() {
return RileyLinkOmnipodService.class;
}
@ -435,11 +437,13 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
}
@Override
protected void triggerUIChange() {
RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged());
}
@Override
@NonNull
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
@ -452,11 +456,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBolus,
detailedBolusInfo.insulin);
Boolean response = responseTask.wasCommandSuccessful();
PumpEnactResult result = responseTask.getResult();
setRefreshButtonEnabled(true);
if (response) {
if (result.success) {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
@ -474,51 +478,36 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
long time = System.currentTimeMillis() + (bolusTime * 1000);
this.busyTimestamps.add(time);
return new PumpEnactResult().success(true) //
.enacted(true) //
.bolusDelivered(detailedBolusInfo.insulin) //
.carbsDelivered(detailedBolusInfo.carbs);
} else {
return new PumpEnactResult() //
.success(false) //
.enacted(false) //
.comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered));
}
return result;
} finally {
finishAction("Bolus");
}
}
@Override
public void stopBolusDelivering() {
LOG.info(getLogPrefix() + "stopBolusDelivering");
setRefreshButtonEnabled(false);
try {
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.CancelBolus);
Boolean response = responseTask.wasCommandSuccessful();
PumpEnactResult result = responseTask.getResult();
setRefreshButtonEnabled(true);
LOG.info(getLogPrefix() + "stopBolusDelivering - wasSuccess={}", response);
LOG.info(getLogPrefix() + "stopBolusDelivering - wasSuccess={}", result.success);
if (response) {
if (result.success) {
// TODO fix bolus record with cancel
//TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
}
} finally {
finishAction("Bolus");
}
}
private void incrementStatistics(String statsKey) {
@ -551,7 +540,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
}
if (tbrCurrent != null && !enforceNew) {
if (OmnipodUtil.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) {
if (isLoggingEnabled())
LOG.info(getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
@ -568,10 +556,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
// CANCEL
OmnipodUITask responseTask2 = omnipodUIComm.executeCommand(OmnipodCommandType.CancelTemporaryBasal);
Boolean response = responseTask2.wasCommandSuccessful();
;
PumpEnactResult result = responseTask2.getResult();
if (response) {
if (result.success) {
if (isLoggingEnabled())
LOG.info(getLogPrefix() + "setTempBasalAbsolute - Current TBR cancelled.");
} else {
@ -580,8 +567,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
finishAction("TBR");
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op));
return result;
}
}
@ -589,12 +575,12 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetTemporaryBasal,
absoluteRate, durationInMinutes);
Boolean response = responseTask.wasCommandSuccessful();
PumpEnactResult result = responseTask.getResult();
if (isLoggingEnabled())
LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + response);
LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success);
if (response) {
if (result.success) {
pumpStatusLocal.tempBasalStart = System.currentTimeMillis();
pumpStatusLocal.tempBasalAmount = absoluteRate;
pumpStatusLocal.tempBasalLength = durationInMinutes;
@ -609,19 +595,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart);
incrementStatistics(OmnipodConst.Statistics.TBRsSet);
finishAction("TBR");
return new PumpEnactResult().success(true).enacted(true) //
.absolute(absoluteRate).duration(durationInMinutes);
} else {
finishAction("TBR");
return new PumpEnactResult().success(false).enacted(false) //
.comment(MainApp.gs(R.string.medtronic_cmd_tbr_could_not_be_delivered));
}
finishAction("TBR");
return result;
}
protected TempBasalPair readTBR() {
@ -682,11 +659,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
OmnipodUITask responseTask2 = omnipodUIComm.executeCommand(OmnipodCommandType.CancelTemporaryBasal);
Boolean response = responseTask2.wasCommandSuccessful();
PumpEnactResult result = responseTask2.getResult();
finishAction("TBR");
if (response) {
if (result.success) {
if (isLoggingEnabled())
LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR successful.");
@ -696,17 +673,12 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
.source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
return new PumpEnactResult().success(true).enacted(true) //
.isTempCancel(true);
} else {
if (isLoggingEnabled())
LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
return new PumpEnactResult().success(response).enacted(response) //
.comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr));
}
return result;
}
@Override
@ -732,19 +704,16 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBasalProfile,
profile);
Boolean response = responseTask.wasCommandSuccessful();
PumpEnactResult result = responseTask.getResult();
if (isLoggingEnabled())
LOG.info(getLogPrefix() + "Basal Profile was set: " + response);
LOG.info(getLogPrefix() + "Basal Profile was set: " + result.success);
if (response) {
if (result.success) {
this.currentProfile = profile;
return new PumpEnactResult().success(true).enacted(true);
} else {
return new PumpEnactResult().success(response).enacted(response) //
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_could_not_be_set));
}
return result;
}

View file

@ -4,10 +4,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
@ -25,7 +25,7 @@ public class OmnipodUITask {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
public OmnipodCommandType commandType;
public PodCommResponse returnData;
public PumpEnactResult returnData;
private String errorDescription;
private Object[] parameters;
private PodResponseType responseType;
@ -128,11 +128,10 @@ public class OmnipodUITask {
}
public Object getResult() {
return returnData;
public <T> T getResult() {
return (T)returnData;
}
public boolean isReceived() {
return (returnData != null || errorDescription != null);
}
@ -184,12 +183,5 @@ public class OmnipodUITask {
return this.responseType;
}
public boolean wasCommandSuccessful() {
if (returnData == null) {
return false;
}
return returnData.isAcknowledged();
}
}

View file

@ -1,71 +1,70 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
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.data.PodCommResponse;
public interface OmnipodCommunicationManagerInterface {
// TODO add methods that can be used by OmniPod Eros and Omnipod Dash
/**
* Pair and prime
*/
PodCommResponse pairAndPrime();
PumpEnactResult pairAndPrime();
/**
* Insert cannula
*/
PodCommResponse insertCannula(Profile basalProfile);
PumpEnactResult insertCannula(Profile basalProfile);
/**
* Get Pod Status (is pod running, battery left ?, reservoir, etc)
*/
PodCommResponse getPodStatus();
// TODO we should probably return a (wrapped) StatusResponse instead of a PumpEnactResult
PumpEnactResult getPodStatus();
/**
* Deactivate Pod
*/
PodCommResponse deactivatePod();
PumpEnactResult deactivatePod();
/**
* Set Basal Profile
*/
PodCommResponse setBasalProfile(Profile basalProfile);
PumpEnactResult setBasalProfile(Profile basalProfile);
/**
* Reset Pod state (if we forget to disconnect Pod and want to init new pod, and want to forget current pod)
*/
PodCommResponse resetPodState();
PumpEnactResult resetPodState();
/**
* Set Bolus
*
* @param amount amount of bolus in U
*/
PodCommResponse bolus(Double amount);
PumpEnactResult bolus(Double amount);
/**
* Cancel Bolus (if bolus is already stopped, return acknowledgment)
*/
PodCommResponse cancelBolus();
PumpEnactResult cancelBolus();
/**
* Set Temporary Basal
*
* @param tempBasalPair TempBasalPair object containg amount and duration in minutes
*/
PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair);
PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair);
/**
* Cancel Temporary Basal (if TB is already stopped, return acknowledgment)
*/
PodCommResponse cancelTemporaryBasal();
PumpEnactResult cancelTemporaryBasal();
/**
* Acknowledge alerts
*/
PodCommResponse acknowledgeAlerts();
PumpEnactResult acknowledgeAlerts();
}

View file

@ -112,6 +112,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
private void initializeErosOmnipodManager() {
if(OmnipodManager.getInstance() == null) {
PodSessionState podState = null;
if (SP.contains(OmnipodConst.Prefs.PodState)) {
try {
@ -123,6 +124,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
}
omnipodCommunicationManager = new OmnipodManager(new OmnipodCommunicationService(rfspy), podState);
} else {
omnipodCommunicationManager = OmnipodManager.getInstance();
}
}

View file

@ -6,11 +6,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -62,7 +62,7 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
// This are just skeleton methods, we need to see what we can get returned and act accordingly
@Override
public PodCommResponse pairAndPrime() {
public PumpEnactResult pairAndPrime() {
//omnipodManager.pairAndPrime();
@ -70,52 +70,52 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
}
@Override
public PodCommResponse insertCannula(Profile basalProfile) {
public PumpEnactResult insertCannula(Profile basalProfile) {
return null;
}
@Override
public PodCommResponse getPodStatus() {
public PumpEnactResult getPodStatus() {
return null;
}
@Override
public PodCommResponse deactivatePod() {
public PumpEnactResult deactivatePod() {
return null;
}
@Override
public PodCommResponse setBasalProfile(Profile basalProfile) {
public PumpEnactResult setBasalProfile(Profile basalProfile) {
return null;
}
@Override
public PodCommResponse resetPodState() {
public PumpEnactResult resetPodState() {
return null;
}
@Override
public PodCommResponse bolus(Double parameter) {
public PumpEnactResult bolus(Double parameter) {
return null;
}
@Override
public PodCommResponse cancelBolus() {
public PumpEnactResult cancelBolus() {
return null;
}
@Override
public PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair) {
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
return null;
}
@Override
public PodCommResponse cancelTemporaryBasal() {
public PumpEnactResult cancelTemporaryBasal() {
return null;
}
@Override
public PodCommResponse acknowledgeAlerts() {
public PumpEnactResult acknowledgeAlerts() {
return null;
}
}