Rename ReadReservoirLevelAndLastBolus to ReadQuickInfoCommand.
This commit is contained in:
parent
739e52dc47
commit
5fbd9097d8
5 changed files with 21 additions and 18 deletions
|
@ -345,7 +345,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
if (!pump.initialized) {
|
if (!pump.initialized) {
|
||||||
initializePump();
|
initializePump();
|
||||||
} else {
|
} 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
|
// note that since the history is checked upon every connect, the above already updated
|
||||||
// the DB with any changed history records
|
// the DB with any changed history records
|
||||||
}
|
}
|
||||||
|
@ -395,9 +395,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
|
|
||||||
// ComboFragment updates state fully only after the pump has initialized, so read full state here
|
// 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) {
|
private void updateLocalData(CommandResult result) {
|
||||||
if (result.reservoirLevel != PumpState.UNKNOWN) {
|
if (result.reservoirLevel != PumpState.UNKNOWN) {
|
||||||
pump.reservoirLevel = result.reservoirLevel;
|
pump.reservoirLevel = result.reservoirLevel;
|
||||||
|
@ -492,7 +493,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
|
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
|
||||||
|
|
||||||
// check pump is ready and all pump bolus records are known
|
// 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) {
|
if (!stateResult.success) {
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered));
|
.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
|
// a connection problem, ruffyscripter tried to recover and we can just check the
|
||||||
// history below to see what was actually delivered
|
// 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) {
|
if (!postBolusStateResult.success) {
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
||||||
|
|
|
@ -32,7 +32,7 @@ public interface RuffyCommands {
|
||||||
CommandResult readPumpState();
|
CommandResult readPumpState();
|
||||||
|
|
||||||
/** Read reservoir level and last bolus via Quick Info */
|
/** 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
|
/** Reads pump history via the My Data menu. The {@link PumpHistoryRequest} specifies
|
||||||
* what types of data and how far back data is returned. */
|
* what types of data and how far back data is returned. */
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
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.history.PumpHistoryRequest;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CancelTbrCommand;
|
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.ReadBasalProfileCommand;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadHistoryCommand;
|
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.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.SetBasalProfileCommand;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
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
|
* operations and are cleanly separated from the thread management, connection management etc
|
||||||
*/
|
*/
|
||||||
public class RuffyScripter implements RuffyCommands {
|
public class RuffyScripter implements RuffyCommands {
|
||||||
private final boolean readQuickInfoMenu = true;
|
private final boolean readQuickInfo = true;
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
||||||
|
|
||||||
|
@ -217,10 +217,10 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult readReservoirLevelAndLastBolus() {
|
public CommandResult readQuickInfo() {
|
||||||
if (readQuickInfoMenu) {
|
if (readQuickInfo) {
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd"));
|
Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd"));
|
||||||
return runCommand(new ReadReservoirLevelAndLastBolus());
|
return runCommand(new ReadQuickInfoCommand());
|
||||||
}
|
}
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd"));
|
Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd"));
|
||||||
return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
|
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.PumpWarningCodes;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
|
||||||
|
@ -185,17 +186,18 @@ public class BolusCommand extends BaseCommand {
|
||||||
|
|
||||||
if (cancelInProgress) {
|
if (cancelInProgress) {
|
||||||
log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery");
|
log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery");
|
||||||
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
|
ReadQuickInfoCommand readQuickInfoCommand = new ReadQuickInfoCommand();
|
||||||
readReservoirLevelAndLastBolus.setScripter(scripter);
|
readQuickInfoCommand.setScripter(scripter);
|
||||||
readReservoirLevelAndLastBolus.execute();
|
readQuickInfoCommand.execute();
|
||||||
Bolus lastBolus = readReservoirLevelAndLastBolus.result.history != null && !readReservoirLevelAndLastBolus.result.history.bolusHistory.isEmpty()
|
CommandResult quickInfoResult = readQuickInfoCommand.result;
|
||||||
? readReservoirLevelAndLastBolus.result.history.bolusHistory.get(0)
|
Bolus lastBolus = quickInfoResult.history != null && !quickInfoResult.history.bolusHistory.isEmpty()
|
||||||
|
? quickInfoResult.history.bolusHistory.get(0)
|
||||||
: null;
|
: null;
|
||||||
if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) {
|
if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) {
|
||||||
throw new CommandException("Unable to determine last bolus");
|
throw new CommandException("Unable to determine last bolus");
|
||||||
}
|
}
|
||||||
log.debug("Stage 4: " + lastBolus.amount + " U delivered before cancellation according to history");
|
log.debug("Stage 4: " + lastBolus.amount + " U delivered before cancellation according to history");
|
||||||
result.delivered = lastBolus.amount;
|
this.result.delivered = lastBolus.amount;
|
||||||
} else {
|
} else {
|
||||||
log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered");
|
log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered");
|
||||||
result.delivered = bolus;
|
result.delivered = bolus;
|
||||||
|
|
|
@ -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.Bolus;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
|
||||||
|
|
||||||
public class ReadReservoirLevelAndLastBolus extends BaseCommand {
|
public class ReadQuickInfoCommand extends BaseCommand {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
scripter.verifyRootMenuIsDisplayed();
|
scripter.verifyRootMenuIsDisplayed();
|
||||||
|
@ -62,6 +62,6 @@ public class ReadReservoirLevelAndLastBolus extends BaseCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ReadReservoirLevelAndLastBolus{}";
|
return "ReadQuickInfoCommand{}";
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue