Bug fixes and improvements in PodStateManager stuff

This commit is contained in:
Bart Sopers 2020-08-08 18:37:10 +02:00
parent b50670cceb
commit 3bc53544a2
4 changed files with 17 additions and 20 deletions

View file

@ -487,17 +487,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
public boolean isSuspended() { public boolean isSuspended() {
return (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) || return (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) ||
(omnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().isSuspended()); (omnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && omnipodUtil.getPodStateManager().isSuspended());
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) || // return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (OmnipodUtil.getPodStateManager() != null && OmnipodUtil.getPodStateManager().isSuspended()); // (OmnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
// //
// TODO ddd // TODO ddd
// return (OmnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) || // return (OmnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) ||
// (OmnipodUtil.getPodStateManager() != null && OmnipodUtil.getPodStateManager().isSuspended()); // (OmnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
// //
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) || // return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (OmnipodUtil.getPodStateManager() != null && OmnipodUtil.getPodStateManager().isSuspended()); // (OmnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
} }
@Override @Override

View file

@ -81,7 +81,7 @@ public class OmnipodManager {
logStartingCommandExecution("pairAndPrime"); logStartingCommandExecution("pairAndPrime");
try { try {
if (!podStateManager.hasState() || !podStateManager.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) { if (!podStateManager.hasState() || !podStateManager.isPaired() || podStateManager.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) {
// Always send both 0x07 and 0x03 on retries // Always send both 0x07 and 0x03 on retries
communicationService.executeAction( communicationService.executeAction(
new AssignAddressAction(podStateManager)); new AssignAddressAction(podStateManager));
@ -105,7 +105,7 @@ public class OmnipodManager {
} }
public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) { public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) {
if (!podStateManager.hasState() || podStateManager.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { if (!podStateManager.hasState() || !podStateManager.isPaired() || podStateManager.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, !podStateManager.hasState() ? null : podStateManager.getSetupProgress()); throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, !podStateManager.hasState() ? null : podStateManager.getSetupProgress());
} else if (podStateManager.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) { } else if (podStateManager.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
throw new IllegalSetupProgressException(SetupProgress.CANNULA_INSERTING, podStateManager.getSetupProgress()); throw new IllegalSetupProgressException(SetupProgress.CANNULA_INSERTING, podStateManager.getSetupProgress());
@ -455,14 +455,6 @@ public class OmnipodManager {
} }
} }
public PodStateManager getPodStateManager() {
return this.podStateManager;
}
public String getPodStateAsString() {
return podStateManager.hasState() ? podStateManager.toString() : "null";
}
// Only works for commands with nonce resyncable message blocks // Only works for commands with nonce resyncable message blocks
// FIXME method is too big, needs refactoring // FIXME method is too big, needs refactoring
private StatusResponse executeAndVerify(VerifiableAction runnable) { private StatusResponse executeAndVerify(VerifiableAction runnable) {

View file

@ -99,7 +99,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
wizardPagerContext.clearContext() wizardPagerContext.clearContext()
wizardPagerContext.pagerSettings = pagerSettings wizardPagerContext.pagerSettings = pagerSettings
val podStateManager = omnipodUtil.getPodStateManager() val podStateManager = omnipodUtil.getPodStateManager()
val isFullInit = podStateManager == null || podStateManager.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED) val isFullInit = podStateManager == null || !podStateManager.isPaired || podStateManager.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED)
if (isFullInit) { if (isFullInit) {
wizardPagerContext.wizardModel = FullInitPodWizardModel(applicationContext) wizardPagerContext.wizardModel = FullInitPodWizardModel(applicationContext)
} else { } else {

View file

@ -84,6 +84,7 @@ import io.reactivex.disposables.Disposable;
public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface { public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface {
private final PodStateManager podStateManager;
private OmnipodUtil omnipodUtil; private OmnipodUtil omnipodUtil;
private AAPSLogger aapsLogger; private AAPSLogger aapsLogger;
private RxBusWrapper rxBus; private RxBusWrapper rxBus;
@ -113,6 +114,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
ResourceHelper resourceHelper, ResourceHelper resourceHelper,
HasAndroidInjector injector, HasAndroidInjector injector,
ActivePluginProvider activePlugin) { ActivePluginProvider activePlugin) {
if (podStateManager == null) {
throw new IllegalArgumentException("Pod state manager can not be null");
}
this.podStateManager = podStateManager;
this.omnipodUtil = omnipodUtil; this.omnipodUtil = omnipodUtil;
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus; this.rxBus = rxBus;
@ -135,7 +140,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
public PodStateManager getPodStateManager() { public PodStateManager getPodStateManager() {
return delegate.getPodStateManager(); return podStateManager;
} }
private void updatePumpStatus(PodStateManager podStateManager) { private void updatePumpStatus(PodStateManager podStateManager) {
@ -368,8 +373,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false); activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
if (delegate.getPodStateManager().hasFaultEvent()) { if (podStateManager.hasFaultEvent()) {
showPodFaultErrorDialog(delegate.getPodStateManager().getFaultEvent().getFaultEventCode(), R.raw.urgentalarm); showPodFaultErrorDialog(podStateManager.getFaultEvent().getFaultEventCode(), R.raw.urgentalarm);
} }
return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(unitsDelivered); return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(unitsDelivered);
@ -468,7 +473,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public void setPumpStatus(OmnipodPumpStatus pumpStatus) { public void setPumpStatus(OmnipodPumpStatus pumpStatus) {
this.pumpStatus = pumpStatus; this.pumpStatus = pumpStatus;
updatePumpStatus(delegate.getPodStateManager()); updatePumpStatus(podStateManager);
} }
// TODO should we add this to the OmnipodCommunicationManager interface? // TODO should we add this to the OmnipodCommunicationManager interface?
@ -553,7 +558,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
public String getPodStateAsString() { public String getPodStateAsString() {
return delegate.getPodStateAsString(); return podStateManager.toString();
} }
private void reportImplicitlyCanceledTbr() { private void reportImplicitlyCanceledTbr() {