From bf9369babc0e0da417ee7eb5b53a5a4dc1511f3c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 29 Aug 2017 01:10:56 +0200 Subject: [PATCH] Move readDuration method to SetTbrCommand. --- .../de/jotomo/ruffyscripter/RuffyScripter.java | 5 ----- .../ruffyscripter/commands/SetTbrCommand.java | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index ae3269dcae..953ade2414 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -676,9 +676,4 @@ public class RuffyScripter { } return (T) value; } - - public long readDisplayedDuration() { - MenuTime duration = readBlinkingValue(MenuTime.class, MenuAttribute.RUNTIME); - return duration.getHour() * 60 + duration.getMinute(); - } } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 206e27ba9e..0bf0deeed6 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -12,8 +12,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import de.jotomo.ruffyscripter.PumpState; - public class SetTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class); @@ -174,7 +172,7 @@ public class SetTbrCommand extends BaseCommand { } private long calculateDurationSteps() { - long currentDuration = scripter.readDisplayedDuration(); + long currentDuration = readDisplayedDuration(); log.debug("Initial TBR duration: " + currentDuration); long difference = duration - currentDuration; @@ -190,7 +188,7 @@ public class SetTbrCommand extends BaseCommand { scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION); // wait up to 5s for any scrolling to finish - long displayedDuration = scripter.readDisplayedDuration(); + long displayedDuration = readDisplayedDuration(); long timeout = System.currentTimeMillis() + 10 * 1000; while (timeout > System.currentTimeMillis() && ((increasingPercentage && displayedDuration < duration) @@ -198,7 +196,7 @@ public class SetTbrCommand extends BaseCommand { log.debug("Waiting for pump to process scrolling input for duration, current: " + displayedDuration + ", desired: " + duration + ", scrolling up: " + increasingPercentage); SystemClock.sleep(50); - displayedDuration = scripter.readDisplayedDuration(); + displayedDuration = readDisplayedDuration(); } log.debug("Final displayed TBR duration: " + displayedDuration); @@ -209,7 +207,7 @@ public class SetTbrCommand extends BaseCommand { // check again to ensure the displayed value hasn't change due to due scrolling taking extremely long SystemClock.sleep(1000); scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION); - long refreshedDisplayedTbrDuration = scripter.readDisplayedDuration(); + long refreshedDisplayedTbrDuration = readDisplayedDuration(); if (displayedDuration != refreshedDisplayedTbrDuration) { throw new CommandException().message("Failed to set TBR duration: " + "duration changed after input stopped from " @@ -217,8 +215,6 @@ public class SetTbrCommand extends BaseCommand { } } - - private void cancelTbrAndConfirmCancellationWarning() { // confirm entered TBR scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); @@ -239,6 +235,7 @@ public class SetTbrCommand extends BaseCommand { // A wait till the error code can be read results in the code hanging, despite // menu updates coming in, so just check the message. // TODO v2 this only works when the pump's language is English + // TODO extract confirmAlert method String errorMsg = (String) scripter.getCurrentMenu().getAttribute(MenuAttribute.MESSAGE); if (!errorMsg.equals("TBR CANCELLED")) { throw new CommandException().success(false).enacted(false) @@ -285,6 +282,11 @@ public class SetTbrCommand extends BaseCommand { } } + private long readDisplayedDuration() { + MenuTime duration = scripter.readBlinkingValue(MenuTime.class, MenuAttribute.RUNTIME); + return duration.getHour() * 60 + duration.getMinute(); + } + @Override public String toString() { return "SetTbrCommand{" +