diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 4fcc81e3db..7189db52bf 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -214,9 +214,11 @@ public class RuffyScripter { } return; } - log.debug("Cmd execution: connection ready, executing cmd " + cmd); + log.debug("Connection ready to execute cmd " + cmd); + PumpState pumpState = readPumpState(); + log.debug("Pump state before running command: " + pumpState); long cmdStartTime = System.currentTimeMillis(); - returnable.cmdResult = cmd.execute(scripter); + returnable.cmdResult = cmd.execute(scripter, pumpState); long cmdEndTime = System.currentTimeMillis(); log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms"); } catch (CommandException e) { diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java index d417cf958c..7e51aadbda 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.RuffyScripter; public class BolusCommand implements Command { @@ -34,7 +35,7 @@ public class BolusCommand implements Command { } @Override - public CommandResult execute(RuffyScripter scripter) { + public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { try { enterBolusMenu(scripter); 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 7d5acfa806..af04a72beb 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java @@ -1,6 +1,5 @@ package de.jotomo.ruffyscripter.commands; -import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,12 +22,10 @@ public class CancelTbrCommand implements Command { } @Override - public CommandResult execute(RuffyScripter scripter) { + public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { try { 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) { + if (!initialPumpState.tbrActive) { // 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. @@ -42,11 +39,12 @@ public class CancelTbrCommand implements Command { .message("No TBR active"); */ } - log.debug("Cancelling active TBR of " + tbrPercentage + "% with " + runtimeDisplayed + "min remaining"); + log.debug("Cancelling active TBR of " + initialPumpState.tbrPercent + + "% with " + initialPumpState.tbrRemainingDuration + " min remaining"); + return new SetTbrCommand(100, 0).execute(scripter, initialPumpState); } catch (CommandException e) { return e.toCommandResult(); } - return new SetTbrCommand(100, 0).execute(scripter); } @Override diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java index 0061060814..c18ce48c07 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java @@ -2,9 +2,10 @@ package de.jotomo.ruffyscripter.commands; import java.util.List; +import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.RuffyScripter; public interface Command { - CommandResult execute(RuffyScripter ruffyScripter); + CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState); List validateArguments(); } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java index ddac5c65d3..58e52b0a4f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java @@ -3,11 +3,12 @@ package de.jotomo.ruffyscripter.commands; import java.util.Collections; import java.util.List; +import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.RuffyScripter; public class ReadPumpStateCommand implements Command { @Override - public CommandResult execute(RuffyScripter ruffyScripter) { + public CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState) { return new CommandResult().success(true).enacted(false).message("Returning pump state only"); } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 7e5c1bf244..5f2bf7d83f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.RuffyScripter; public class SetTbrCommand implements Command { @@ -53,7 +54,7 @@ public class SetTbrCommand implements Command { } @Override - public CommandResult execute(RuffyScripter scripter) { + public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { try { enterTbrMenu(scripter);