SetTbrCommand: handle edge case where TBR expires while a new one is being programmed.

This commit is contained in:
Johannes Mockenhaupt 2017-12-09 16:21:40 +01:00
parent 6db58a4e93
commit 8bba8c4d5a
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 35 additions and 15 deletions

View file

@ -520,6 +520,8 @@ public class RuffyScripter implements RuffyCommands {
return state; return state;
} }
/** Precondition: a warning/error must be displayed */
@Nullable
public WarningOrErrorCode readWarningOrErrorCode() { public WarningOrErrorCode readWarningOrErrorCode() {
verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR); verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR);
Integer warningCode = (Integer) getCurrentMenu().getAttribute(MenuAttribute.WARNING); Integer warningCode = (Integer) getCurrentMenu().getAttribute(MenuAttribute.WARNING);

View file

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.jotomo.ruffy.spi.PumpWarningCodes; import de.jotomo.ruffy.spi.PumpWarningCodes;
import de.jotomo.ruffy.spi.WarningOrErrorCode;
public class SetTbrCommand extends BaseCommand { public class SetTbrCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class); private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class);
@ -60,6 +61,7 @@ public class SetTbrCommand extends BaseCommand {
public void execute() { public void execute() {
boolean cancellingTbr = percentage == 100; boolean cancellingTbr = percentage == 100;
try {
enterTbrMenu(); enterTbrMenu();
boolean increasingPercentage = inputTbrPercentage(); boolean increasingPercentage = inputTbrPercentage();
verifyDisplayedTbrPercentage(increasingPercentage); verifyDisplayedTbrPercentage(increasingPercentage);
@ -79,6 +81,22 @@ public class SetTbrCommand extends BaseCommand {
scripter.pressCheckKey(); scripter.pressCheckKey();
scripter.waitForMenuToBeLeft(MenuType.TBR_DURATION); scripter.waitForMenuToBeLeft(MenuType.TBR_DURATION);
} }
} catch (CommandException e) {
if (scripter.getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
// The pump raises a TBR CANCELLED warning when a running TBR finishes while we're
// programming a new one (TBR remaining time was last displayed as 0:01, the pump
// rounds seconds up to full minutes). In that case confirm the alert since we know
// we caused it (in a way), but still fail the command so the usual cleanups of returning
// to main menu etc are performed, after which this command can simply be retried.
WarningOrErrorCode warningOrErrorCode = scripter.readWarningOrErrorCode();
if (warningOrErrorCode.warningCode != null
&& warningOrErrorCode.warningCode == PumpWarningCodes.TBR_CANCELLED) {
scripter.confirmAlert(PumpWarningCodes.TBR_CANCELLED);
}
}
throw e;
}
result.success = true; result.success = true;
} }