Update pump status when it gets assigned; don't schedule on main thread
This commit is contained in:
parent
2905bfba86
commit
29d12eeb26
|
@ -48,8 +48,8 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.Flowable;
|
import io.reactivex.Flowable;
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import io.reactivex.subjects.SingleSubject;
|
import io.reactivex.subjects.SingleSubject;
|
||||||
|
|
||||||
public class OmnipodManager {
|
public class OmnipodManager {
|
||||||
|
@ -97,7 +97,7 @@ public class OmnipodManager {
|
||||||
return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
|
return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
|
||||||
.map(o -> verifySetupAction(statusResponse ->
|
.map(o -> verifySetupAction(statusResponse ->
|
||||||
PrimeAction.updatePrimingStatus(podState, statusResponse), SetupProgress.PRIMING_FINISHED)) //
|
PrimeAction.updatePrimingStatus(podState, statusResponse), SetupProgress.PRIMING_FINISHED)) //
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) {
|
public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) {
|
||||||
|
@ -113,7 +113,7 @@ public class OmnipodManager {
|
||||||
return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
|
return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
|
||||||
.map(o -> verifySetupAction(statusResponse ->
|
.map(o -> verifySetupAction(statusResponse ->
|
||||||
InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), SetupProgress.COMPLETED)) //
|
InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), SetupProgress.COMPLETED)) //
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized StatusResponse getPodStatus() {
|
public synchronized StatusResponse getPodStatus() {
|
||||||
|
@ -190,7 +190,7 @@ public class OmnipodManager {
|
||||||
long progressReportInterval = estimatedRemainingBolusDuration.getMillis() / numberOfProgressReports;
|
long progressReportInterval = estimatedRemainingBolusDuration.getMillis() / numberOfProgressReports;
|
||||||
|
|
||||||
disposables.add(Flowable.intervalRange(0, numberOfProgressReports + 1, 0, progressReportInterval, TimeUnit.MILLISECONDS) //
|
disposables.add(Flowable.intervalRange(0, numberOfProgressReports + 1, 0, progressReportInterval, TimeUnit.MILLISECONDS) //
|
||||||
.observeOn(AndroidSchedulers.mainThread()) //
|
.observeOn(Schedulers.io()) //
|
||||||
.subscribe(count -> {
|
.subscribe(count -> {
|
||||||
int percentage = (int) ((double) count / numberOfProgressReports * 100);
|
int percentage = (int) ((double) count / numberOfProgressReports * 100);
|
||||||
double estimatedUnitsDelivered = activeBolusData == null ? 0 : activeBolusData.estimateUnitsDelivered();
|
double estimatedUnitsDelivered = activeBolusData == null ? 0 : activeBolusData.estimateUnitsDelivered();
|
||||||
|
@ -206,7 +206,7 @@ public class OmnipodManager {
|
||||||
|
|
||||||
disposables.add(Completable.complete() //
|
disposables.add(Completable.complete() //
|
||||||
.delay(estimatedRemainingBolusDuration.getMillis() + 250, TimeUnit.MILLISECONDS) //
|
.delay(estimatedRemainingBolusDuration.getMillis() + 250, TimeUnit.MILLISECONDS) //
|
||||||
.observeOn(AndroidSchedulers.mainThread()) //
|
.observeOn(Schedulers.io()) //
|
||||||
.doOnComplete(() -> {
|
.doOnComplete(() -> {
|
||||||
synchronized (bolusDataLock) {
|
synchronized (bolusDataLock) {
|
||||||
for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) {
|
for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) {
|
||||||
|
@ -220,7 +220,7 @@ public class OmnipodManager {
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (isLoggingEnabled()) {
|
if (isLoggingEnabled()) {
|
||||||
LOG.debug("Ignoring exception in bolus completion verfication", ex);
|
LOG.debug("Ignoring exception in bolus completion verification", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,10 +77,24 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState, OmnipodPumpStatus _pumpStatus) {
|
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState, OmnipodPumpStatus _pumpStatus) {
|
||||||
delegate = new OmnipodManager(communicationService, podState, podSessionState -> {
|
delegate = new OmnipodManager(communicationService, podState, podSessionState -> {
|
||||||
// Handle pod state changes
|
// Handle pod state changes
|
||||||
|
|
||||||
OmnipodUtil.setPodSessionState(podSessionState);
|
OmnipodUtil.setPodSessionState(podSessionState);
|
||||||
|
updatePumpStatus(podSessionState);
|
||||||
|
});
|
||||||
|
this.pumpStatus = _pumpStatus;
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePumpStatus(PodSessionState podSessionState) {
|
||||||
if (pumpStatus != null) {
|
if (pumpStatus != null) {
|
||||||
|
if (podSessionState == null) {
|
||||||
|
pumpStatus.ackAlertsText = null;
|
||||||
|
pumpStatus.ackAlertsAvailable = false;
|
||||||
|
pumpStatus.lastBolusTime = null;
|
||||||
|
pumpStatus.lastBolusAmount = null;
|
||||||
|
pumpStatus.reservoirRemainingUnits = 0.0;
|
||||||
|
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
|
||||||
|
sendEvent(new EventOmnipodPumpValuesChanged());
|
||||||
|
} else {
|
||||||
// Update active alerts
|
// Update active alerts
|
||||||
if (podSessionState.hasActiveAlerts()) {
|
if (podSessionState.hasActiveAlerts()) {
|
||||||
List<String> alerts = translateActiveAlerts(podSessionState);
|
List<String> alerts = translateActiveAlerts(podSessionState);
|
||||||
|
@ -110,9 +124,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
sendEvent(new EventOmnipodPumpValuesChanged());
|
sendEvent(new EventOmnipodPumpValuesChanged());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
this.pumpStatus = _pumpStatus;
|
|
||||||
instance = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
|
private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
|
||||||
|
@ -300,6 +312,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
public void setPumpStatus(OmnipodPumpStatus pumpStatus) {
|
public void setPumpStatus(OmnipodPumpStatus pumpStatus) {
|
||||||
this.pumpStatus = pumpStatus;
|
this.pumpStatus = pumpStatus;
|
||||||
this.getCommunicationService().setPumpStatus(pumpStatus);
|
this.getCommunicationService().setPumpStatus(pumpStatus);
|
||||||
|
updatePumpStatus(delegate.getPodState());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||||
|
|
Loading…
Reference in a new issue