Rework checkAndResolveTbrMismatch to update from pump to AAPS only.

This commit is contained in:
Johannes Mockenhaupt 2017-12-04 20:07:05 +01:00
parent 141c116db6
commit 1735842e57
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -772,9 +772,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
} }
// check if TBR was cancelled or set by user checkAndResolveTbrMismatch(preCheckResult.state);
boolean mismatch = checkForTbrMismatch(preCheckResult.state);
if (mismatch) checkPumpHistory();
// raise notification if clock is off (setting clock is not supported by ruffy) // raise notification if clock is off (setting clock is not supported by ruffy)
if (preCheckResult.state.pumpTimeMinutesOfDay != 0) { if (preCheckResult.state.pumpTimeMinutesOfDay != 0) {
@ -834,45 +832,42 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
/** /**
* Checks the main screen to determine if TBR on pump matches app state. * Checks the main screen to determine if TBR on pump matches app state.
*/ */
private boolean checkForTbrMismatch(PumpState state) { private void checkAndResolveTbrMismatch(PumpState state) {
// TODO
if (1==1) return false;
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
boolean sync = false;
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) { if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {
// TODO add AAPS record for the active TBR with whatever time is remaining on it log.debug("Creating temp basal from pump TBR");
log.debug("Pump runs TBR AAPS is unaware of, cancelling TBR so it can be read from history properly"); TemporaryBasal newTempBasal = new TemporaryBasal();
runCommand(null, 0, ruffyScripter::cancelTbr); newTempBasal.date = System.currentTimeMillis();
sync = true; newTempBasal.percentRate = state.tbrPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
newTempBasal.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
} else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) { } else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) {
// TODO create end record for the TBR active in AAPS log.debug("Ending AAPS-TBR since pump has no TBR active");
log.debug("AAPS shows a TBR but pump isn't running a TBR; deleting TBR in AAPS and reading pump history"); TemporaryBasal tempStop = new TemporaryBasal();
MainApp.getDbHelper().delete(aapsTbr); tempStop.date = aapsTbr.date;
sync = true; tempStop.durationInMinutes = 0;
} else if (aapsTbr != null && state.tbrActive) { tempStop.source = Source.USER;
// both AAPS and pump have an active TBR ... MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
if (aapsTbr.percentRate != state.tbrPercent) { } else if (aapsTbr != null && state.tbrActive
// ... but they have different percentages && (aapsTbr.percentRate != state.tbrPercent ||
// TODO end AAPS TBR, start new TBR based on pump TBR Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration) > 2)) {
log.debug("TBR percentage differs between AAPS and pump; deleting TBR in AAPS and reading pump history"); log.debug("AAPSs and pump-TBR differ; Ending AAPS-TBR and creating new TBR based on pump TBR");
MainApp.getDbHelper().delete(aapsTbr); TemporaryBasal tempStop = new TemporaryBasal();
sync = true; tempStop.date = aapsTbr.date;
} tempStop.durationInMinutes = 0;
int durationDiff = Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration); tempStop.source = Source.USER;
if (durationDiff > 2) { MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
// TODO end AAPS TBR, start new TBR based on pump TBR
// ... but they have different runtimes
log.debug("TBR duration differs between AAPS and pump; deleting TBR in AAPS and reading pump history");
MainApp.getDbHelper().delete(aapsTbr);
sync = true;
}
}
if (sync) { TemporaryBasal newTempBasal = new TemporaryBasal();
log.debug("Sync requested from checkTbrMismatch"); newTempBasal.date = System.currentTimeMillis();
newTempBasal.percentRate = state.tbrPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
newTempBasal.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
} }
return sync;
} }
/** /**