From 5fbd9097d83d79e822d57968d2c8c2aa94328503 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 14:51:39 +0100 Subject: [PATCH] Rename ReadReservoirLevelAndLastBolus to ReadQuickInfoCommand. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 9 +++++---- .../PumpCombo/ruffyscripter/RuffyCommands.java | 2 +- .../PumpCombo/ruffyscripter/RuffyScripter.java | 10 +++++----- .../ruffyscripter/commands/BolusCommand.java | 14 ++++++++------ ...AndLastBolus.java => ReadQuickInfoCommand.java} | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-) rename app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/{ReadReservoirLevelAndLastBolus.java => ReadQuickInfoCommand.java} (95%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 56b5184602..4cb2778adc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -345,7 +345,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!pump.initialized) { initializePump(); } else { - runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readReservoirLevelAndLastBolus); + runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readQuickInfo); // note that since the history is checked upon every connect, the above already updated // the DB with any changed history records } @@ -395,9 +395,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf MainApp.bus().post(new EventInitializationChanged()); // ComboFragment updates state fully only after the pump has initialized, so read full state here - updateLocalData(runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus)); + updateLocalData(runCommand(null, 1, ruffyScripter::readQuickInfo)); } + /** Updates local cache with state (reservoir level, last bolus ...) returned from the pump */ private void updateLocalData(CommandResult result) { if (result.reservoirLevel != PumpState.UNKNOWN) { pump.reservoirLevel = result.reservoirLevel; @@ -492,7 +493,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true); // check pump is ready and all pump bolus records are known - CommandResult stateResult = runCommand(null, 2, ruffyScripter::readReservoirLevelAndLastBolus); + CommandResult stateResult = runCommand(null, 2, ruffyScripter::readQuickInfo); if (!stateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered)); @@ -531,7 +532,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // a connection problem, ruffyscripter tried to recover and we can just check the // history below to see what was actually delivered - CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus); + CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readQuickInfo); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java index 344b63d8f9..b6266ba829 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java @@ -32,7 +32,7 @@ public interface RuffyCommands { CommandResult readPumpState(); /** Read reservoir level and last bolus via Quick Info */ - CommandResult readReservoirLevelAndLastBolus(); + CommandResult readQuickInfo(); /** Reads pump history via the My Data menu. The {@link PumpHistoryRequest} specifies * what types of data and how far back data is returned. */ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 26b5400285..609c8195a9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -28,6 +28,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadQuickInfoCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CancelTbrCommand; @@ -37,7 +38,6 @@ import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.Confi import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadBasalProfileCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadHistoryCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadPumpStateCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadReservoirLevelAndLastBolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetBasalProfileCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand; import info.nightscout.androidaps.BuildConfig; @@ -48,7 +48,7 @@ import info.nightscout.androidaps.BuildConfig; * operations and are cleanly separated from the thread management, connection management etc */ public class RuffyScripter implements RuffyCommands { - private final boolean readQuickInfoMenu = true; + private final boolean readQuickInfo = true; private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class); @@ -217,10 +217,10 @@ public class RuffyScripter implements RuffyCommands { } @Override - public CommandResult readReservoirLevelAndLastBolus() { - if (readQuickInfoMenu) { + public CommandResult readQuickInfo() { + if (readQuickInfo) { Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")); - return runCommand(new ReadReservoirLevelAndLastBolus()); + return runCommand(new ReadQuickInfoCommand()); } Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")); return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java index 5c232211ea..134d4e0622 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Objects; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; @@ -185,17 +186,18 @@ public class BolusCommand extends BaseCommand { if (cancelInProgress) { log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery"); - ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus(); - readReservoirLevelAndLastBolus.setScripter(scripter); - readReservoirLevelAndLastBolus.execute(); - Bolus lastBolus = readReservoirLevelAndLastBolus.result.history != null && !readReservoirLevelAndLastBolus.result.history.bolusHistory.isEmpty() - ? readReservoirLevelAndLastBolus.result.history.bolusHistory.get(0) + ReadQuickInfoCommand readQuickInfoCommand = new ReadQuickInfoCommand(); + readQuickInfoCommand.setScripter(scripter); + readQuickInfoCommand.execute(); + CommandResult quickInfoResult = readQuickInfoCommand.result; + Bolus lastBolus = quickInfoResult.history != null && !quickInfoResult.history.bolusHistory.isEmpty() + ? quickInfoResult.history.bolusHistory.get(0) : null; if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) { throw new CommandException("Unable to determine last bolus"); } log.debug("Stage 4: " + lastBolus.amount + " U delivered before cancellation according to history"); - result.delivered = lastBolus.amount; + this.result.delivered = lastBolus.amount; } else { log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered"); result.delivered = bolus; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java index 66017c6fb7..5e84878f70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java @@ -15,7 +15,7 @@ import java.util.List; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; -public class ReadReservoirLevelAndLastBolus extends BaseCommand { +public class ReadQuickInfoCommand extends BaseCommand { @Override public void execute() { scripter.verifyRootMenuIsDisplayed(); @@ -62,6 +62,6 @@ public class ReadReservoirLevelAndLastBolus extends BaseCommand { @Override public String toString() { - return "ReadReservoirLevelAndLastBolus{}"; + return "ReadQuickInfoCommand{}"; } }