Combo: when suspended, create 0% TBR record, suppress checks.

Fixes #774
This commit is contained in:
Johannes Mockenhaupt 2018-03-19 00:03:22 +01:00
parent 94d862fb81
commit 213fc7ccb4
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -177,18 +177,19 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
String getStateSummary() { String getStateSummary() {
PumpState ps = pump.state; PumpState ps = pump.state;
if (!pump.initialized) { if (ps.activeAlert != null) {
return MainApp.gs(R.string.combo_pump_state_initializing);
} else if (!validBasalRateProfileSelectedOnPump) {
return MainApp.gs(R.string.loopdisabled);
} else if (ps.activeAlert != null) {
return ps.activeAlert.errorCode != null return ps.activeAlert.errorCode != null
? "E" + ps.activeAlert.errorCode + ": " + ps.activeAlert.message ? "E" + ps.activeAlert.errorCode + ": " + ps.activeAlert.message
: "W" + ps.activeAlert.warningCode + ": " + ps.activeAlert.message; : "W" + ps.activeAlert.warningCode + ": " + ps.activeAlert.message;
} else if (ps.suspended && (ps.batteryState == PumpState.EMPTY || ps.insulinState == PumpState.EMPTY)) } else if (ps.suspended && (ps.batteryState == PumpState.EMPTY || ps.insulinState == PumpState.EMPTY)) {
return MainApp.gs(R.string.combo_pump_state_suspended_due_to_error); return MainApp.gs(R.string.combo_pump_state_suspended_due_to_error);
else if (ps.suspended) } else if (ps.suspended) {
return MainApp.gs(R.string.combo_pump_state_suspended_by_user); return MainApp.gs(R.string.combo_pump_state_suspended_by_user);
} else if (!pump.initialized) {
return MainApp.gs(R.string.combo_pump_state_initializing);
} else if (!validBasalRateProfileSelectedOnPump) {
return MainApp.gs(R.string.loopdisabled);
}
return MainApp.gs(R.string.combo_pump_state_running); return MainApp.gs(R.string.combo_pump_state_running);
} }
@ -949,7 +950,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
* an error condition. Returns null otherwise. * an error condition. Returns null otherwise.
*/ */
private CommandResult runOnConnectChecks() { private CommandResult runOnConnectChecks() {
// connect, get status and check if an alarm is active
CommandResult preCheckResult = ruffyScripter.readPumpState(); CommandResult preCheckResult = ruffyScripter.readPumpState();
if (!preCheckResult.success) { if (!preCheckResult.success) {
return preCheckResult; return preCheckResult;
@ -977,6 +977,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
} }
if (!preCheckResult.state.suspended) {
checkForUnsafeUsage(preCheckResult); checkForUnsafeUsage(preCheckResult);
checkAndResolveTbrMismatch(preCheckResult.state); checkAndResolveTbrMismatch(preCheckResult.state);
checkPumpTime(preCheckResult.state); checkPumpTime(preCheckResult.state);
@ -985,6 +986,20 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (historyCheckError != null) { if (historyCheckError != null) {
return historyCheckError; return historyCheckError;
} }
} else {
long now = System.currentTimeMillis();
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (aapsTbr == null || aapsTbr.percentRate != 0) {
log.debug("Creating 15m zero temp since pump is suspended");
TemporaryBasal newTempBasal = new TemporaryBasal();
newTempBasal.date = now;
newTempBasal.percentRate = 0;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = 15;
newTempBasal.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
}
}
return null; return null;
} }