Extract method checkAndWaitIfExistingTbrIsAboutToEnd.
This commit is contained in:
parent
7ed64c5a7d
commit
5b31d39f28
|
@ -64,25 +64,9 @@ public class SetTbrCommand extends BaseCommand {
|
||||||
boolean cancellingTbr = percentage == 100;
|
boolean cancellingTbr = percentage == 100;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// When programming a new TBR while an existing TBR runs out, a TBR CANCELLED
|
if (checkAndWaitIfExistingTbrIsAboutToEnd(cancellingTbr)) {
|
||||||
// alert is raised (failing the command, requiring a reconnect and confirming alert
|
|
||||||
// and all). To avoid this, wait until the active TBR runs out if the active TBR
|
|
||||||
// is about to end
|
|
||||||
long timeout = System.currentTimeMillis() + 65 * 1000;
|
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
|
||||||
PumpState state = scripter.readPumpStateInternal();
|
|
||||||
if (state.tbrRemainingDuration == 1) {
|
|
||||||
while (state.tbrActive && System.currentTimeMillis() < timeout) {
|
|
||||||
log.debug("Waiting for existing TBR to run out to avoid alert while setting TBR");
|
|
||||||
scripter.waitForScreenUpdate();
|
|
||||||
state = scripter.readPumpStateInternal();
|
|
||||||
}
|
|
||||||
// if we waited above and a cancellation was requested, we already completed the request
|
|
||||||
if (!state.tbrActive && cancellingTbr) {
|
|
||||||
result.success = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
enterTbrMenu();
|
enterTbrMenu();
|
||||||
boolean increasingPercentage = inputTbrPercentage();
|
boolean increasingPercentage = inputTbrPercentage();
|
||||||
|
@ -121,6 +105,33 @@ public class SetTbrCommand extends BaseCommand {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When programming a new TBR while an existing TBR runs out, a TBR CANCELLED
|
||||||
|
* alert is raised (failing the command, requiring a reconnect and confirming alert
|
||||||
|
* and all). To avoid this, wait until the active TBR runs out if the active TBR
|
||||||
|
* is about to end.
|
||||||
|
*
|
||||||
|
* @return If we waited till the TBR ended an cancellation was request so all work is done.
|
||||||
|
*/
|
||||||
|
private boolean checkAndWaitIfExistingTbrIsAboutToEnd(boolean cancellingTbr) {
|
||||||
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||||
|
long timeout = System.currentTimeMillis() + 65 * 1000;
|
||||||
|
PumpState state = scripter.readPumpStateInternal();
|
||||||
|
if (state.tbrRemainingDuration == 1) {
|
||||||
|
while (state.tbrActive && System.currentTimeMillis() < timeout) {
|
||||||
|
log.debug("Waiting for existing TBR to run out to avoid alert while setting TBR");
|
||||||
|
scripter.waitForScreenUpdate();
|
||||||
|
state = scripter.readPumpStateInternal();
|
||||||
|
}
|
||||||
|
// if we waited above and a cancellation was requested, we already completed the request
|
||||||
|
if (!state.tbrActive && cancellingTbr) {
|
||||||
|
result.success = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void enterTbrMenu() {
|
private void enterTbrMenu() {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||||
scripter.navigateToMenu(MenuType.TBR_MENU);
|
scripter.navigateToMenu(MenuType.TBR_MENU);
|
||||||
|
|
Loading…
Reference in a new issue