From 9927ab49890dda398186f53aaefc35f5ef14042d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 18 Jul 2017 21:14:08 +0200 Subject: [PATCH] Raise an error upon attempting to cancel a TBR when none is active. --- .../ruffyscripter/commands/CancelTbrCommand.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java index 27110c7893..dfd1f93f4e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.List; +import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.RuffyScripter; // TODO robustness: can a TBR run out, whilst we're trying to cancel it? @@ -28,11 +29,19 @@ public class CancelTbrCommand implements Command { Double tbrPercentage = (Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR); boolean runtimeDisplayed = scripter.currentMenu.attributes().contains(MenuAttribute.RUNTIME); if (tbrPercentage == 100 && !runtimeDisplayed) { - return new CommandResult() + // this is likely a relatively harmless error like AAPS trying to cancel a TBR + // that has run out in the last minute or so, but for debugging lets raise an error + // to make sure we can inspect this situation. + // Set enacted=true, so I record is created and AAPS stops thinking a TBR still + // running and trying again to cancel it. + return new CommandResult().success(false).enacted(true) + .state(new PumpState().errorMsg("NO TBR active")); + /* .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"); + */ } log.debug("Cancelling active TBR of " + tbrPercentage + "% with " + runtimeDisplayed + "min remaining"); } catch (CommandException e) {