Merge remote-tracking branch 'refs/remotes/origin/trim-to-max-tbr' into HEAD

This commit is contained in:
Sandra Keßler 2017-07-30 16:21:10 +02:00
commit afda4f9254

View file

@ -480,20 +480,27 @@ public class ComboPlugin implements PluginBase, PumpInterface {
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min"); log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min");
if (percent % 10 != 0) {
int rounded = percent; int adjustedPercent = percent;
while (rounded % 10 != 0) rounded = rounded - 1;
log.debug("Rounded requested percentage from " + percent + " to " + rounded); if (adjustedPercent > pumpDescription.maxTempPercent) {
percent = rounded; log.debug("Reducing requested TBR to the maximum support by the pump: " + percent + " -> " + pumpDescription.maxTempPercent);
adjustedPercent = pumpDescription.maxTempPercent;
} }
CommandResult commandResult = runCommand(new SetTbrCommand(percent, durationInMinutes)); if (adjustedPercent % 10 != 0) {
Long rounded = Math.round(adjustedPercent / 10d) * 10;
log.debug("Rounded requested percentage:" + adjustedPercent + " -> " + rounded);
adjustedPercent = rounded.intValue();
}
CommandResult commandResult = runCommand(new SetTbrCommand(adjustedPercent, durationInMinutes));
if (commandResult.enacted) { if (commandResult.enacted) {
TemporaryBasal tempStart = new TemporaryBasal(commandResult.completionTime); TemporaryBasal tempStart = new TemporaryBasal(commandResult.completionTime);
// TODO commandResult.state.tbrRemainingDuration might already display 29 if 30 was set, since 29:59 is shown as 29 ... // TODO commandResult.state.tbrRemainingDuration might already display 29 if 30 was set, since 29:59 is shown as 29 ...
// we should check this, but really ... something must be really screwed up if that number was anything different // we should check this, but really ... something must be really screwed up if that number was anything different
tempStart.durationInMinutes = durationInMinutes; tempStart.durationInMinutes = durationInMinutes;
tempStart.percentRate = percent; tempStart.percentRate = adjustedPercent;
tempStart.isAbsolute = false; tempStart.isAbsolute = false;
tempStart.source = Source.USER; tempStart.source = Source.USER;
ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder(); ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder();
@ -507,7 +514,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
pumpEnactResult.isPercent = true; pumpEnactResult.isPercent = true;
// Combo would have bailed if this wasn't set properly. Maybe we should // Combo would have bailed if this wasn't set properly. Maybe we should
// have the command return this anyways ... // have the command return this anyways ...
pumpEnactResult.percent = percent; pumpEnactResult.percent = adjustedPercent;
pumpEnactResult.duration = durationInMinutes; pumpEnactResult.duration = durationInMinutes;
return pumpEnactResult; return pumpEnactResult;
} }