From fe7f8314290de9d1bc1e0d1b6764f7b0370acab0 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 23 Aug 2017 12:10:50 +0200 Subject: [PATCH] Inject scripter into commands. --- app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java | 3 ++- .../java/de/jotomo/ruffyscripter/commands/BaseCommand.java | 2 +- .../java/de/jotomo/ruffyscripter/commands/BolusCommand.java | 2 +- .../de/jotomo/ruffyscripter/commands/CancelTbrCommand.java | 5 ++--- .../main/java/de/jotomo/ruffyscripter/commands/Command.java | 3 ++- .../ruffyscripter/commands/DetermineCapabilitiesCommand.java | 5 +---- .../de/jotomo/ruffyscripter/commands/GetBasalCommand.java | 2 +- .../jotomo/ruffyscripter/commands/ReadPumpStateCommand.java | 3 +-- .../java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java | 2 +- .../de/jotomo/ruffyscripter/commands/SetTbrCommandAlt.java | 2 +- 10 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 3f8a99f665..3d11cf68d7 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -304,7 +304,8 @@ public class RuffyScripter { PumpState pumpState = readPumpState(); log.debug("Pump state before running command: " + pumpState); long cmdStartTime = System.currentTimeMillis(); - returnable.cmdResult = cmd.execute(scripter, pumpState); + cmd.setScripter(scripter); + returnable.cmdResult = cmd.execute(pumpState); long cmdEndTime = System.currentTimeMillis(); returnable.cmdResult.completionTime = cmdEndTime; log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms"); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java index 5f138637f3..ab951c9185 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java @@ -5,7 +5,7 @@ import de.jotomo.ruffyscripter.RuffyScripter; public abstract class BaseCommand implements Command { // RS will inject itself here protected RuffyScripter scripter; - public void setScripter(RuffyScripter scripter) { this.scripter = scripter; } + @Override public void setScripter(RuffyScripter scripter) { this.scripter = scripter; } // TODO upcoming protected volatile boolean cancelRequested = false; 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 aa0e16b7e7..3eb0b1ba26 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -35,7 +35,7 @@ public class BolusCommand extends BaseCommand { } @Override - public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { + public CommandResult execute(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 761c8fcd47..047ac56376 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java @@ -8,7 +8,6 @@ import java.util.Collections; import java.util.List; import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.RuffyScripter; import info.nightscout.androidaps.MainApp; // TODO robustness: can a TBR run out, whilst we're trying to cancel it? @@ -23,7 +22,7 @@ public class CancelTbrCommand extends BaseCommand { } @Override - public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { + public CommandResult execute(PumpState initialPumpState) { try { scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); if (!initialPumpState.tbrActive) { @@ -49,7 +48,7 @@ public class CancelTbrCommand extends BaseCommand { } log.debug("Cancelling active TBR of " + initialPumpState.tbrPercent + "% with " + initialPumpState.tbrRemainingDuration + " min remaining"); - return new SetTbrCommand(100, 0).execute(scripter, initialPumpState); + return new SetTbrCommand(100, 0).execute(initialPumpState); } catch (CommandException e) { return e.toCommandResult(); } 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 33d10fc223..6848a2c3f2 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java @@ -13,6 +13,7 @@ import de.jotomo.ruffyscripter.RuffyScripter; * sequence, letting the methods take care of waits. */ public interface Command { - CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState); + CommandResult execute(PumpState initialPumpState); List validateArguments(); + void setScripter(RuffyScripter scripter); } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java index 2f33287507..8eef298154 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java @@ -2,8 +2,6 @@ package de.jotomo.ruffyscripter.commands; import android.os.SystemClock; -import com.j256.ormlite.stmt.query.In; - 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.menu.MenuTime; @@ -12,7 +10,6 @@ import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.List; -import java.util.Locale; import de.jotomo.ruffyscripter.PumpCapabilities; import de.jotomo.ruffyscripter.PumpState; @@ -30,7 +27,7 @@ public class DetermineCapabilitiesCommand extends BaseCommand { } @Override - public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { + public CommandResult execute(PumpState initialPumpState) { try { //read main menu 100% or TBR? Read remaining duration. diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java index a37e4c2be4..b8b451b901 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java @@ -102,7 +102,7 @@ public class GetBasalCommand extends BaseCommand { // } // } @Override - public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { + public CommandResult execute(PumpState initialPumpState) { try { Map rate = new HashMap<>(); 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 4b4d164133..c346661c74 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java @@ -4,11 +4,10 @@ import java.util.Collections; import java.util.List; import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.RuffyScripter; public class ReadPumpStateCommand extends BaseCommand { @Override - public CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState) { + public CommandResult execute(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 4edbf39e33..38164cc116 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -60,7 +60,7 @@ public class SetTbrCommand extends BaseCommand { } @Override - public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { + public CommandResult execute(PumpState initialPumpState) { try { log.debug("1. going from " + scripter.currentMenu + " to TBR_MENU"); int retries = 5; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommandAlt.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommandAlt.java index 5cc4094403..45f589c173 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommandAlt.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommandAlt.java @@ -54,7 +54,7 @@ public class SetTbrCommandAlt extends BaseCommand { } @Override - public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { + public CommandResult execute(PumpState initialPumpState) { try { enterTbrMenu(scripter); inputTbrPercentage(scripter);