Pass pre-cmd pump state to command, log it.
This commit is contained in:
parent
a7c77bc177
commit
467cf1e6ed
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String> validateArguments();
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue