Extract method checkAndWaitIfExistingTbrIsAboutToEnd.

This commit is contained in:
Johannes Mockenhaupt 2017-12-13 14:26:41 +01:00
parent 7ed64c5a7d
commit 5b31d39f28
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -64,24 +64,8 @@ public class SetTbrCommand extends BaseCommand {
boolean cancellingTbr = percentage == 100;
try {
// 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
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;
}
if (checkAndWaitIfExistingTbrIsAboutToEnd(cancellingTbr)) {
return;
}
enterTbrMenu();
@ -121,6 +105,33 @@ public class SetTbrCommand extends BaseCommand {
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() {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
scripter.navigateToMenu(MenuType.TBR_MENU);