From 8bba8c4d5ad14c998b34d622ed585b2b1773755b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 9 Dec 2017 16:21:40 +0100 Subject: [PATCH] SetTbrCommand: handle edge case where TBR expires while a new one is being programmed. --- .../jotomo/ruffyscripter/RuffyScripter.java | 2 + .../ruffyscripter/commands/SetTbrCommand.java | 48 +++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 63d095f5da..c8d7d20bf9 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -520,6 +520,8 @@ public class RuffyScripter implements RuffyCommands { return state; } + /** Precondition: a warning/error must be displayed */ + @Nullable public WarningOrErrorCode readWarningOrErrorCode() { verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR); Integer warningCode = (Integer) getCurrentMenu().getAttribute(MenuAttribute.WARNING); diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 117af2d302..66e8654df5 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; import de.jotomo.ruffy.spi.PumpWarningCodes; +import de.jotomo.ruffy.spi.WarningOrErrorCode; public class SetTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class); @@ -60,25 +61,42 @@ public class SetTbrCommand extends BaseCommand { public void execute() { boolean cancellingTbr = percentage == 100; - enterTbrMenu(); - boolean increasingPercentage = inputTbrPercentage(); - verifyDisplayedTbrPercentage(increasingPercentage); + try { + enterTbrMenu(); + boolean increasingPercentage = inputTbrPercentage(); + verifyDisplayedTbrPercentage(increasingPercentage); - if (cancellingTbr) { - cancelTbrAndConfirmCancellationWarning(); - } else { - // switch to TBR_DURATION menu by pressing menu key - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - scripter.pressMenuKey(); - scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION); + if (cancellingTbr) { + cancelTbrAndConfirmCancellationWarning(); + } else { + // switch to TBR_DURATION menu by pressing menu key + scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); + scripter.pressMenuKey(); + scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION); - boolean increasingDuration = inputTbrDuration(); - verifyDisplayedTbrDuration(increasingDuration); + boolean increasingDuration = inputTbrDuration(); + verifyDisplayedTbrDuration(increasingDuration); - // confirm TBR - scripter.pressCheckKey(); - scripter.waitForMenuToBeLeft(MenuType.TBR_DURATION); + // confirm TBR + scripter.pressCheckKey(); + 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; }