WIP Cleaning up ComboPlugin/Ruffyscripter.cancelTbr
This commit is contained in:
parent
598fbe40cc
commit
6ba57ff1f7
|
@ -524,6 +524,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
return OPERATION_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
// TODO clean this method up:
|
||||
// check PumpState to verify TBR has been cancelled.
|
||||
// enacted field.
|
||||
@Override
|
||||
public PumpEnactResult cancelTempBasal(boolean userRequested) {
|
||||
log.debug("cancelTempBasal called");
|
||||
|
@ -560,7 +563,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
// on whether the TBR we're cancelling is above or below 100%.
|
||||
final int percentage = (activeTemp.percentRate > 100) ? 110 : 90;
|
||||
log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins.");
|
||||
commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_setting_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15));
|
||||
commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15));
|
||||
|
||||
if (commandResult.enacted) {
|
||||
tempBasal = new TemporaryBasal(System.currentTimeMillis());
|
||||
|
@ -571,6 +574,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
}
|
||||
|
||||
// TODO properly check pumpstate to confirm cancellation
|
||||
|
||||
|
||||
if (tempBasal != null) {
|
||||
ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder();
|
||||
treatmentsInterface.addToHistoryTempBasal(tempBasal);
|
||||
|
|
|
@ -80,19 +80,6 @@ public class SetTbrCommand extends BaseCommand {
|
|||
scripter.pressCheckKey();
|
||||
scripter.waitForMenuToBeLeft(MenuType.TBR_DURATION);
|
||||
}
|
||||
|
||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
|
||||
"Pump did not return to MAIN_MEU after setting TBR. " +
|
||||
"Check pump manually, the TBR might not have been set/cancelled.");
|
||||
|
||||
// check main menu shows the same values we just set
|
||||
if (cancellingTbr) {
|
||||
verifyMainMenuShowsNoActiveTbr();
|
||||
result.success(true).enacted(true);
|
||||
} else {
|
||||
verifyMainMenuShowsExpectedTbrActive();
|
||||
result.success(true).enacted(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void enterTbrMenu() {
|
||||
|
@ -230,33 +217,6 @@ public class SetTbrCommand extends BaseCommand {
|
|||
scripter.confirmAlert(PumpWarningCodes.TBR_CANCELLED, 2000);
|
||||
}
|
||||
|
||||
private void verifyMainMenuShowsNoActiveTbr() {
|
||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||
Double tbrPercentage = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR);
|
||||
boolean runtimeDisplayed = scripter.getCurrentMenu().attributes().contains(MenuAttribute.RUNTIME);
|
||||
if (tbrPercentage != 100 || runtimeDisplayed) {
|
||||
throw new CommandException("Cancelling TBR failed, TBR is still set according to MAIN_MENU");
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyMainMenuShowsExpectedTbrActive() {
|
||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||
// new TBR set; percentage and duration must be displayed ...
|
||||
if (!scripter.getCurrentMenu().attributes().contains(MenuAttribute.TBR) ||
|
||||
!scripter.getCurrentMenu().attributes().contains(MenuAttribute.RUNTIME)) {
|
||||
throw new CommandException("Setting TBR failed, according to MAIN_MENU no TBR is active");
|
||||
}
|
||||
Double mmTbrPercentage = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR);
|
||||
MenuTime mmTbrDuration = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.RUNTIME);
|
||||
// ... and be the same as what we set
|
||||
// note that displayed duration might have already counted down, e.g. from 30 minutes to
|
||||
// 29 minutes and 59 seconds, so that 29 minutes are displayed
|
||||
int mmTbrDurationInMinutes = mmTbrDuration.getHour() * 60 + mmTbrDuration.getMinute();
|
||||
if (mmTbrPercentage != percentage || (mmTbrDurationInMinutes != duration && mmTbrDurationInMinutes + 1 != duration)) {
|
||||
throw new CommandException("Setting TBR failed, TBR in MAIN_MENU differs from expected");
|
||||
}
|
||||
}
|
||||
|
||||
private long readDisplayedDuration() {
|
||||
MenuTime duration = scripter.readBlinkingValue(MenuTime.class, MenuAttribute.RUNTIME);
|
||||
return duration.getHour() * 60 + duration.getMinute();
|
||||
|
|
Loading…
Reference in a new issue