More cleanup in OmnipodPumpPlugin

This commit is contained in:
Bart Sopers 2020-08-23 14:55:12 +02:00
parent 5cd46a90a0
commit 91d0da9f51
4 changed files with 38 additions and 62 deletions

View file

@ -57,6 +57,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
@ -109,6 +110,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private final PumpDescription pumpDescription;
private final ServiceConnection serviceConnection;
private final PumpType pumpType = PumpType.Insulet_Omnipod;
private final OmnipodUIComm commandExecutor;
private final List<CustomAction> customActions = new ArrayList<>();
// TODO: BS: Not really sure what this is all about, have a closer look at it some time
@ -143,7 +145,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
RileyLinkServiceData rileyLinkServiceData,
ServiceTaskExecutor serviceTaskExecutor,
DateUtil dateUtil,
OmnipodUtil omnipodUtil
OmnipodUtil omnipodUtil,
RileyLinkUtil rileyLinkUtil
) {
super(new PluginDescription() //
.mainType(PluginType.PUMP) //
@ -172,6 +175,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
customActions.add(new CustomAction(
R.string.omnipod_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true));
commandExecutor = new OmnipodUIComm(injector, aapsLogger, aapsOmnipodManager, rileyLinkUtil, rxBus);
this.serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
@ -418,7 +423,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
OmnipodStatusRequest omnipodStatusRequest = iterator.next();
OmnipodUITask omnipodUITask;
if (omnipodStatusRequest == OmnipodStatusRequest.GetPodPulseLog) {
omnipodUITask = getDeviceCommandExecutor().executeCommand(omnipodStatusRequest.getCommandType());
omnipodUITask = commandExecutor.executeCommand(omnipodStatusRequest.getCommandType());
PodInfoRecentPulseLog result = (PodInfoRecentPulseLog) omnipodUITask.returnDataObject;
@ -437,16 +442,12 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
} else {
omnipodUITask = getDeviceCommandExecutor().executeCommand(omnipodStatusRequest.getCommandType());
}
if (!omnipodUITask.wasCommandSuccessful()) {
// TODO Refresh buttons
commandExecutor.executeCommand(omnipodStatusRequest.getCommandType());
}
iterator.remove();
}
} else if (this.hasTimeDateOrTimeZoneChanged) {
OmnipodUITask omnipodUITask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetTime);
OmnipodUITask omnipodUITask = commandExecutor.executeCommand(OmnipodCommandType.SetTime);
if (omnipodUITask.wasCommandSuccessful()) {
this.hasTimeDateOrTimeZoneChanged = false;
@ -472,7 +473,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@NotNull
@Override
public PumpEnactResult setNewBasalProfile(Profile profile) {
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBasalProfile,
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.SetBasalProfile,
profile);
PumpEnactResult result = responseTask.getResult();
@ -564,7 +565,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@Override
public void stopBolusDelivering() {
getDeviceCommandExecutor().executeCommand(OmnipodCommandType.CancelBolus);
commandExecutor.executeCommand(OmnipodCommandType.CancelBolus);
}
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
@ -585,13 +586,13 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
if (tbrCurrent != null && !enforceNew) {
if (Round.isSame(tbrCurrent.absoluteRate, absoluteRate)) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
refreshOverview("TBR");
rxBus.send(new EventRefreshOverview("Omnipod command: TBR", true));
return new PumpEnactResult(getInjector()).success(true).enacted(false);
}
}
// now start new TBR
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetTemporaryBasal,
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.SetTemporaryBasal,
absoluteRate, durationInMinutes);
PumpEnactResult result = responseTask.getResult();
@ -602,7 +603,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
incrementStatistics(OmnipodConst.Statistics.TBRsSet);
}
refreshOverview("TBR");
return result;
}
@ -624,16 +624,14 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
if (tbrCurrent == null) {
aapsLogger.info(LTag.PUMP, "cancelTempBasal - TBR already canceled.");
refreshOverview("TBR");
rxBus.send(new EventRefreshOverview("Omnipod command: TBR", true));
return new PumpEnactResult(getInjector()).success(true).enacted(false);
}
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.CancelTemporaryBasal);
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.CancelTemporaryBasal);
PumpEnactResult result = responseTask.getResult();
refreshOverview("TBR");
if (result.success) {
// TODO is this necessary?
TemporaryBasal tempBasal = new TemporaryBasal(getInjector()) //
@ -818,17 +816,13 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return false;
}
public OmnipodUIComm getDeviceCommandExecutor() {
return rileyLinkOmnipodService.getDeviceCommandExecutor();
}
public void addPodStatusRequest(OmnipodStatusRequest pumpStatusRequest) {
omnipodStatusRequestList.add(pumpStatusRequest);
}
private void initializePump() {
if (podStateManager.isPodInitialized() && podStateManager.getPodProgressStatus().isAtLeast(PodProgressStatus.PAIRING_COMPLETED)) {
OmnipodUITask omnipodUITask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.GetPodStatus);
OmnipodUITask omnipodUITask = commandExecutor.executeCommand(OmnipodCommandType.GetPodStatus);
if (omnipodUITask.wasCommandSuccessful()) {
aapsLogger.debug(LTag.PUMP, "Successfully retrieved Pod status on startup");
} else {
@ -838,8 +832,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
aapsLogger.debug(LTag.PUMP, "Not retrieving Pod status on startup: no Pod running");
}
refreshOverview("Omnipod Pump");
if (!sentIdToFirebase) {
Bundle params = new Bundle();
params.putString("version", BuildConfig.VERSION);
@ -854,23 +846,19 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@NonNull
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
try {
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBolus,
detailedBolusInfo);
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.SetBolus,
detailedBolusInfo);
PumpEnactResult result = responseTask.getResult();
PumpEnactResult result = responseTask.getResult();
if (result.success) {
incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses
: OmnipodConst.Statistics.StandardBoluses);
if (result.success) {
incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses
: OmnipodConst.Statistics.StandardBoluses);
result.carbsDelivered(detailedBolusInfo.carbs);
}
return result;
} finally {
refreshOverview("Bolus");
result.carbsDelivered(detailedBolusInfo.carbs);
}
return result;
}
private void incrementStatistics(String statsKey) {
@ -883,10 +871,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
}
protected void refreshOverview(String overviewKey) {
rxBus.send(new EventRefreshOverview(overviewKey, false));
}
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
}

View file

@ -86,11 +86,6 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
disposables.clear()
}
override fun onDestroy() {
super.onDestroy()
rxBus.send(EventRefreshOverview("Omnipod Pod Management"))
}
fun initPodAction() {
val pagerSettings = WizardPagerSettings()

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
@ -15,22 +17,24 @@ public class OmnipodUIComm {
private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger;
private final IOmnipodManager omnipodCommunicationManager;
private RileyLinkUtil rileyLinkUtil;
private final IOmnipodManager omnipodManager;
private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus;
public OmnipodUIComm(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
IOmnipodManager omnipodCommunicationManager,
RileyLinkUtil rileyLinkUtil
IOmnipodManager omnipodManager,
RileyLinkUtil rileyLinkUtil,
RxBusWrapper rxBus
) {
this.injector = injector;
this.aapsLogger = aapsLogger;
this.omnipodCommunicationManager = omnipodCommunicationManager;
this.omnipodManager = omnipodManager;
this.rileyLinkUtil = rileyLinkUtil;
this.rxBus = rxBus;
}
public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) {
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
@ -38,12 +42,14 @@ public class OmnipodUIComm {
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
task.execute(this.omnipodCommunicationManager);
task.execute(this.omnipodManager);
if (!task.isReceived()) {
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
}
rxBus.send(new EventRefreshOverview("Omnipod command: "+ commandType.name(), true));
return task;
}

View file

@ -23,7 +23,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.R;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -48,8 +47,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private String rileyLinkAddress;
private String errorDescription;
OmnipodUIComm omnipodUIComm;
public RileyLinkOmnipodService() {
super();
}
@ -79,15 +76,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rfspy.startReader();
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, aapsOmnipodManager, rileyLinkUtil);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkOmnipodService newly constructed");
}
public OmnipodUIComm getDeviceCommandExecutor() {
return this.omnipodUIComm;
}
@Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return omnipodCommunicationManager;