2017-07-13 19:50:11 +02:00
|
|
|
package de.jotomo.ruffyscripter.commands;
|
|
|
|
|
|
|
|
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
|
|
|
|
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
|
2017-07-15 11:16:06 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2017-07-13 19:50:11 +02:00
|
|
|
|
|
|
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
|
|
|
|
|
|
|
// TODO robustness: can a TBR run out, whilst we're trying to cancel it?
|
|
|
|
public class CancelTbrCommand implements Command {
|
2017-07-15 11:16:06 +02:00
|
|
|
private static final Logger log = LoggerFactory.getLogger(CancelTbrCommand.class);
|
|
|
|
|
2017-07-13 19:50:11 +02:00
|
|
|
@Override
|
|
|
|
public CommandResult execute(RuffyScripter scripter) {
|
|
|
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
|
|
|
Double tbrPercentage = (Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR);
|
|
|
|
boolean runtimeDisplayed = scripter.currentMenu.attributes().contains(MenuAttribute.RUNTIME);
|
|
|
|
if (tbrPercentage == 100 && !runtimeDisplayed) {
|
2017-07-14 23:00:15 +02:00
|
|
|
return new CommandResult()
|
|
|
|
.success(true)
|
|
|
|
.enacted(true) // technically, nothing was enacted, but AAPS needs this to recover
|
|
|
|
// when there was an issue and AAPS thinks a TBR is still active
|
|
|
|
.message("No TBR active");
|
2017-07-13 19:50:11 +02:00
|
|
|
}
|
2017-07-15 11:16:06 +02:00
|
|
|
log.debug("Cancelling active TBR of " + tbrPercentage + "% with " + runtimeDisplayed + "min remaining");
|
2017-07-13 19:50:11 +02:00
|
|
|
return new SetTbrCommand(100, 0).execute(scripter);
|
|
|
|
}
|
2017-07-14 15:01:20 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "CancelTbrCommand{}";
|
|
|
|
}
|
2017-07-13 19:50:11 +02:00
|
|
|
}
|