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

View file

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

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui; package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; 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.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod; import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
@ -15,22 +17,24 @@ public class OmnipodUIComm {
private final HasAndroidInjector injector; private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final IOmnipodManager omnipodCommunicationManager; private final IOmnipodManager omnipodManager;
private RileyLinkUtil rileyLinkUtil; private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus;
public OmnipodUIComm( public OmnipodUIComm(
HasAndroidInjector injector, HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
IOmnipodManager omnipodCommunicationManager, IOmnipodManager omnipodManager,
RileyLinkUtil rileyLinkUtil RileyLinkUtil rileyLinkUtil,
RxBusWrapper rxBus
) { ) {
this.injector = injector; this.injector = injector;
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.omnipodCommunicationManager = omnipodCommunicationManager; this.omnipodManager = omnipodManager;
this.rileyLinkUtil = rileyLinkUtil; this.rileyLinkUtil = rileyLinkUtil;
this.rxBus = rxBus;
} }
public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) { public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) {
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name()); aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
@ -38,12 +42,14 @@ public class OmnipodUIComm {
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType)); rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
task.execute(this.omnipodCommunicationManager); task.execute(this.omnipodManager);
if (!task.isReceived()) { if (!task.isReceived()) {
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType); aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
} }
rxBus.send(new EventRefreshOverview("Omnipod command: "+ commandType.name(), true));
return task; 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.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager; 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.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -48,8 +47,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private String rileyLinkAddress; private String rileyLinkAddress;
private String errorDescription; private String errorDescription;
OmnipodUIComm omnipodUIComm;
public RileyLinkOmnipodService() { public RileyLinkOmnipodService() {
super(); super();
} }
@ -79,15 +76,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rfspy.startReader(); rfspy.startReader();
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, aapsOmnipodManager, rileyLinkUtil);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkOmnipodService newly constructed"); aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkOmnipodService newly constructed");
} }
public OmnipodUIComm getDeviceCommandExecutor() {
return this.omnipodUIComm;
}
@Override @Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() { public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return omnipodCommunicationManager; return omnipodCommunicationManager;