Move readDuration method to SetTbrCommand.
This commit is contained in:
parent
99c2f797ea
commit
bf9369babc
|
@ -676,9 +676,4 @@ public class RuffyScripter {
|
||||||
}
|
}
|
||||||
return (T) value;
|
return (T) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long readDisplayedDuration() {
|
|
||||||
MenuTime duration = readBlinkingValue(MenuTime.class, MenuAttribute.RUNTIME);
|
|
||||||
return duration.getHour() * 60 + duration.getMinute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import de.jotomo.ruffyscripter.PumpState;
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -174,7 +172,7 @@ public class SetTbrCommand extends BaseCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
private long calculateDurationSteps() {
|
private long calculateDurationSteps() {
|
||||||
long currentDuration = scripter.readDisplayedDuration();
|
long currentDuration = readDisplayedDuration();
|
||||||
log.debug("Initial TBR duration: " + currentDuration);
|
log.debug("Initial TBR duration: " + currentDuration);
|
||||||
|
|
||||||
long difference = duration - currentDuration;
|
long difference = duration - currentDuration;
|
||||||
|
@ -190,7 +188,7 @@ public class SetTbrCommand extends BaseCommand {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION);
|
scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION);
|
||||||
|
|
||||||
// wait up to 5s for any scrolling to finish
|
// wait up to 5s for any scrolling to finish
|
||||||
long displayedDuration = scripter.readDisplayedDuration();
|
long displayedDuration = readDisplayedDuration();
|
||||||
long timeout = System.currentTimeMillis() + 10 * 1000;
|
long timeout = System.currentTimeMillis() + 10 * 1000;
|
||||||
while (timeout > System.currentTimeMillis()
|
while (timeout > System.currentTimeMillis()
|
||||||
&& ((increasingPercentage && displayedDuration < duration)
|
&& ((increasingPercentage && displayedDuration < duration)
|
||||||
|
@ -198,7 +196,7 @@ public class SetTbrCommand extends BaseCommand {
|
||||||
log.debug("Waiting for pump to process scrolling input for duration, current: "
|
log.debug("Waiting for pump to process scrolling input for duration, current: "
|
||||||
+ displayedDuration + ", desired: " + duration + ", scrolling up: " + increasingPercentage);
|
+ displayedDuration + ", desired: " + duration + ", scrolling up: " + increasingPercentage);
|
||||||
SystemClock.sleep(50);
|
SystemClock.sleep(50);
|
||||||
displayedDuration = scripter.readDisplayedDuration();
|
displayedDuration = readDisplayedDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Final displayed TBR duration: " + displayedDuration);
|
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
|
// check again to ensure the displayed value hasn't change due to due scrolling taking extremely long
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION);
|
scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION);
|
||||||
long refreshedDisplayedTbrDuration = scripter.readDisplayedDuration();
|
long refreshedDisplayedTbrDuration = readDisplayedDuration();
|
||||||
if (displayedDuration != refreshedDisplayedTbrDuration) {
|
if (displayedDuration != refreshedDisplayedTbrDuration) {
|
||||||
throw new CommandException().message("Failed to set TBR duration: " +
|
throw new CommandException().message("Failed to set TBR duration: " +
|
||||||
"duration changed after input stopped from "
|
"duration changed after input stopped from "
|
||||||
|
@ -217,8 +215,6 @@ public class SetTbrCommand extends BaseCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void cancelTbrAndConfirmCancellationWarning() {
|
private void cancelTbrAndConfirmCancellationWarning() {
|
||||||
// confirm entered TBR
|
// confirm entered TBR
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
|
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
|
// A wait till the error code can be read results in the code hanging, despite
|
||||||
// menu updates coming in, so just check the message.
|
// menu updates coming in, so just check the message.
|
||||||
// TODO v2 this only works when the pump's language is English
|
// TODO v2 this only works when the pump's language is English
|
||||||
|
// TODO extract confirmAlert method
|
||||||
String errorMsg = (String) scripter.getCurrentMenu().getAttribute(MenuAttribute.MESSAGE);
|
String errorMsg = (String) scripter.getCurrentMenu().getAttribute(MenuAttribute.MESSAGE);
|
||||||
if (!errorMsg.equals("TBR CANCELLED")) {
|
if (!errorMsg.equals("TBR CANCELLED")) {
|
||||||
throw new CommandException().success(false).enacted(false)
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SetTbrCommand{" +
|
return "SetTbrCommand{" +
|
||||||
|
|
Loading…
Reference in a new issue