Fix #12: properly update TBR from pump on mismatch.

This commit is contained in:
Johannes Mockenhaupt 2017-12-10 14:11:07 +01:00
parent 6c5d5fa71e
commit a5ea94de7d
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -771,11 +771,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
* Checks the main screen to determine if TBR on pump matches app state.
*/
private void checkAndResolveTbrMismatch(PumpState state) {
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
long now = System.currentTimeMillis();
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {
log.debug("Creating temp basal from pump TBR");
TemporaryBasal newTempBasal = new TemporaryBasal();
newTempBasal.date = System.currentTimeMillis();
newTempBasal.date = now;
newTempBasal.percentRate = state.tbrPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
@ -784,22 +785,22 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) {
log.debug("Ending AAPS-TBR since pump has no TBR active");
TemporaryBasal tempStop = new TemporaryBasal();
tempStop.date = aapsTbr.date;
tempStop.date = now;
tempStop.durationInMinutes = 0;
tempStop.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
} else if (aapsTbr != null && state.tbrActive
&& (aapsTbr.percentRate != state.tbrPercent ||
Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration) > 2)) {
log.debug("AAPSs and pump-TBR differ; Ending AAPS-TBR and creating new TBR based on pump TBR");
log.debug("AAPSs and pump-TBR differ; ending AAPS-TBR and creating new TBR based on pump TBR");
TemporaryBasal tempStop = new TemporaryBasal();
tempStop.date = aapsTbr.date;
tempStop.date = now - 1000;
tempStop.durationInMinutes = 0;
tempStop.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
TemporaryBasal newTempBasal = new TemporaryBasal();
newTempBasal.date = System.currentTimeMillis();
newTempBasal.date = now;
newTempBasal.percentRate = state.tbrPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = state.tbrRemainingDuration;