Pass pre-cmd pump state to command, log it.
This commit is contained in:
parent
a7c77bc177
commit
467cf1e6ed
6 changed files with 17 additions and 13 deletions
|
@ -214,9 +214,11 @@ public class RuffyScripter {
|
||||||
}
|
}
|
||||||
return;
|
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();
|
long cmdStartTime = System.currentTimeMillis();
|
||||||
returnable.cmdResult = cmd.execute(scripter);
|
returnable.cmdResult = cmd.execute(scripter, pumpState);
|
||||||
long cmdEndTime = System.currentTimeMillis();
|
long cmdEndTime = System.currentTimeMillis();
|
||||||
log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms");
|
log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms");
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import de.jotomo.ruffyscripter.PumpState;
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
|
||||||
public class BolusCommand implements Command {
|
public class BolusCommand implements Command {
|
||||||
|
@ -34,7 +35,7 @@ public class BolusCommand implements Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(RuffyScripter scripter) {
|
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) {
|
||||||
try {
|
try {
|
||||||
enterBolusMenu(scripter);
|
enterBolusMenu(scripter);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package de.jotomo.ruffyscripter.commands;
|
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.monkey.d.ruffy.ruffy.driver.display.MenuType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -23,12 +22,10 @@ public class CancelTbrCommand implements Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(RuffyScripter scripter) {
|
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) {
|
||||||
try {
|
try {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||||
Double tbrPercentage = (Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR);
|
if (!initialPumpState.tbrActive) {
|
||||||
boolean runtimeDisplayed = scripter.currentMenu.attributes().contains(MenuAttribute.RUNTIME);
|
|
||||||
if (tbrPercentage == 100 && !runtimeDisplayed) {
|
|
||||||
// this is likely a relatively harmless error like AAPS trying to cancel a TBR
|
// 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
|
// 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.
|
// to make sure we can inspect this situation.
|
||||||
|
@ -42,11 +39,12 @@ public class CancelTbrCommand implements Command {
|
||||||
.message("No TBR active");
|
.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) {
|
} catch (CommandException e) {
|
||||||
return e.toCommandResult();
|
return e.toCommandResult();
|
||||||
}
|
}
|
||||||
return new SetTbrCommand(100, 0).execute(scripter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,9 +2,10 @@ package de.jotomo.ruffyscripter.commands;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.jotomo.ruffyscripter.PumpState;
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
|
||||||
public interface Command {
|
public interface Command {
|
||||||
CommandResult execute(RuffyScripter ruffyScripter);
|
CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState);
|
||||||
List<String> validateArguments();
|
List<String> validateArguments();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ package de.jotomo.ruffyscripter.commands;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.jotomo.ruffyscripter.PumpState;
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
|
||||||
public class ReadPumpStateCommand implements Command {
|
public class ReadPumpStateCommand implements Command {
|
||||||
@Override
|
@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");
|
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.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import de.jotomo.ruffyscripter.PumpState;
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
|
||||||
public class SetTbrCommand implements Command {
|
public class SetTbrCommand implements Command {
|
||||||
|
@ -53,7 +54,7 @@ public class SetTbrCommand implements Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(RuffyScripter scripter) {
|
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) {
|
||||||
try {
|
try {
|
||||||
enterTbrMenu(scripter);
|
enterTbrMenu(scripter);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue