More improvements for PodStateManager

This commit is contained in:
Bart Sopers 2020-08-08 19:05:36 +02:00
parent 2a73127202
commit 10cde3e744
4 changed files with 23 additions and 22 deletions

View file

@ -487,17 +487,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
public boolean isSuspended() {
return (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) ||
(omnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && omnipodUtil.getPodStateManager().isSuspended());
(omnipodUtil.getPodStateManager().hasState() && omnipodUtil.getPodStateManager().isSuspended());
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (OmnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
//
// TODO ddd
// return (OmnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) ||
// (OmnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
//
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (OmnipodUtil.getPodStateManager() != null && omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
}
@Override
@ -579,6 +579,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
//getPodPumpStatusObject().driverState = OmnipodDriverState.Initalized_PodAvailable;
//driverState = OmnipodDriverState.Initalized_PodAvailable;
// FIXME this does not seem to make sense
omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached);
// we would probably need to read Basal Profile here too
}
@ -621,21 +622,20 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
setRefreshButtonEnabled(false);
PodStateManager podStateManager = omnipodUtil.getPodStateManager();
if (podStateManager != null) {
if (!isRefresh) {
pumpState = PumpDriverState.Initialized;
}
// TODO handle if session state too old
getPodPumpStatus();
} else {
aapsLogger.error(LTag.PUMP, "No PodStateManager found");
try {
PodStateManager podStateManager = omnipodUtil.getPodStateManager();
} catch(Exception ex) {
omnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod);
throw ex;
}
if (!isRefresh) {
pumpState = PumpDriverState.Initialized;
}
// TODO handle if pod state too old
getPodPumpStatus();
finishAction("Omnipod Pump");
// if (!sentIdToFirebase) {

View file

@ -99,7 +99,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
wizardPagerContext.clearContext()
wizardPagerContext.pagerSettings = pagerSettings
val podStateManager = omnipodUtil.getPodStateManager()
val isFullInit = podStateManager == null || !podStateManager.isPaired || podStateManager.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED)
val isFullInit = !podStateManager.isPaired || podStateManager.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED)
if (isFullInit) {
wizardPagerContext.wizardModel = FullInitPodWizardModel(applicationContext)
} else {
@ -150,13 +150,11 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}
fun refreshButtons() {
initpod_init_pod.isEnabled = omnipodUtil.podStateManager == null || !omnipodUtil.podStateManager.isPaired() ||
initpod_init_pod.isEnabled = !omnipodUtil.podStateManager.isPaired() ||
omnipodUtil.getPodStateManager().getSetupProgress().isBefore(SetupProgress.COMPLETED)
val isPodSessionActive = omnipodUtil.podStateManager != null && omnipodUtil.podStateManager.hasState()
initpod_remove_pod.isEnabled = isPodSessionActive && omnipodUtil.podStateManager.isPaired
initpod_reset_pod.isEnabled = isPodSessionActive
initpod_remove_pod.isEnabled = omnipodUtil.podStateManager.hasState() && omnipodUtil.podStateManager.isPaired
initpod_reset_pod.isEnabled = omnipodUtil.podStateManager.hasState()
if (omnipodUtil.getDriverState() == OmnipodDriverState.NotInitalized) {
// if rileylink is not running we disable all operations

View file

@ -56,6 +56,7 @@ public class AapsPodStateManager implements PodStateManager {
@Override public void removeState() {
this.podState = null;
persistPodState();
notifyPodStateChanged();
}
@Override
@ -65,6 +66,7 @@ public class AapsPodStateManager implements PodStateManager {
}
podState = new PodState(address);
persistPodState();
notifyPodStateChanged();
}
@Override public boolean isPaired() {

View file

@ -173,6 +173,7 @@ public class OmnipodUtil {
public PodStateManager getPodStateManager() {
if (omnipodPumpStatus.podStateManager == null) {
aapsLogger.error("OmnipodUtil.getPodStateManager was called, but podStateManager is null");
throw new IllegalStateException("Pod state manager is null");
}
return omnipodPumpStatus.podStateManager;