Reject requents to enact TBRs if one was already started within this minute.

(cherry picked from commit 3805413)
This commit is contained in:
Johannes Mockenhaupt 2017-11-25 13:13:51 +01:00
parent 32112597bc
commit 1e9d0d08c3
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -589,6 +589,15 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return cancelTempBasal(false); return cancelTempBasal(false);
} }
long thisMinute = System.currentTimeMillis() / (60 * 1000) * (60 * 1000);
TemporaryBasal activeTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(thisMinute);
if (activeTbr != null && activeTbr.date == thisMinute) {
// setting multiple TBRs within a single minute (with the first TBR having a runtime
// of 0) is not supported. Attempting to do so sets a new TBR on the pump but adding
// the record to the DB fails as there already is a record with that date.
return new PumpEnactResult().success(false).enacted(false);
}
int finalAdjustedPercent = adjustedPercent; int finalAdjustedPercent = adjustedPercent;
CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_setting_tbr, percent, durationInMinutes), CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_setting_tbr, percent, durationInMinutes),
3, () -> ruffyScripter.setTbr(finalAdjustedPercent, durationInMinutes)); 3, () -> ruffyScripter.setTbr(finalAdjustedPercent, durationInMinutes));