Extend ReadQuickInfoCommand to read more history records.
Also remove switch to forego quick info, which really isn't the cause of the infamous bug, but is now required with the updated history check logic against timestamp dups. (cherry picked from commit 18aa827)
This commit is contained in:
parent
ec4280bc2e
commit
72e4cd29c4
|
@ -404,7 +404,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
// ComboFragment updates state fully only after the pump has initialized,
|
||||
// so force an update after initialization completed
|
||||
updateLocalData(runCommand(null, 1, ruffyScripter::readQuickInfo));
|
||||
updateLocalData(runCommand(null, 1, () -> ruffyScripter.readQuickInfo(1)));
|
||||
}
|
||||
|
||||
/** Updates local cache with state (reservoir level, last bolus ...) returned from the pump */
|
||||
|
@ -542,7 +542,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
// history below to see what was actually delivered
|
||||
|
||||
// get last bolus from pump history for verification
|
||||
CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readQuickInfo);
|
||||
CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(1));
|
||||
if (!postBolusStateResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
||||
|
|
|
@ -32,7 +32,7 @@ public interface RuffyCommands {
|
|||
CommandResult readPumpState();
|
||||
|
||||
/** Read reservoir level and last bolus via Quick Info */
|
||||
CommandResult readQuickInfo();
|
||||
CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve);
|
||||
|
||||
/** Reads pump history via the My Data menu. The {@link PumpHistoryRequest} specifies
|
||||
* what types of data and how far back data is returned. */
|
||||
|
|
|
@ -48,8 +48,6 @@ 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 readQuickInfo = true;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
||||
|
||||
private IRuffyService ruffyService;
|
||||
|
@ -225,17 +223,11 @@ public class RuffyScripter implements RuffyCommands {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommandResult readQuickInfo() {
|
||||
if (readQuickInfo) {
|
||||
public CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve) {
|
||||
Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")
|
||||
.putCustomAttribute("buildversion", BuildConfig.BUILDVERSION)
|
||||
.putCustomAttribute("version", BuildConfig.VERSION));
|
||||
return runCommand(new ReadQuickInfoCommand());
|
||||
}
|
||||
Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")
|
||||
.putCustomAttribute("buildversion", BuildConfig.BUILDVERSION)
|
||||
.putCustomAttribute("version", BuildConfig.VERSION));
|
||||
return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
||||
return runCommand(new ReadQuickInfoCommand(numberOfBolusRecordsToRetrieve));
|
||||
}
|
||||
|
||||
public void returnToRootMenu() {
|
||||
|
|
|
@ -2,26 +2,58 @@ package info.nightscout.androidaps.plugins.PumpCombo.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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
|
||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
|
||||
|
||||
public class ReadQuickInfoCommand extends BaseCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReadQuickInfoCommand.class);
|
||||
|
||||
private final int numberOfBolusRecordsToRetrieve;
|
||||
|
||||
public ReadQuickInfoCommand(int numberOfBolusRecordsToRetrieve) {
|
||||
this.numberOfBolusRecordsToRetrieve = numberOfBolusRecordsToRetrieve;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
scripter.verifyRootMenuIsDisplayed();
|
||||
// navigate to reservoir menu
|
||||
scripter.pressCheckKey();
|
||||
scripter.waitForMenuToBeLeft(MenuType.MAIN_MENU);
|
||||
scripter.waitForMenuToBeLeft(MenuType.STOP);
|
||||
scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO);
|
||||
result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue();
|
||||
if (numberOfBolusRecordsToRetrieve > 0) {
|
||||
// navigate to bolus data menu
|
||||
scripter.pressCheckKey();
|
||||
List<Bolus> bolusHistory = new ArrayList<>(1);
|
||||
bolusHistory.add(readBolusRecord());
|
||||
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA);
|
||||
List<Bolus> bolusHistory = new ArrayList<>(numberOfBolusRecordsToRetrieve);
|
||||
result.history = new PumpHistory().bolusHistory(bolusHistory);
|
||||
for(int recordsLeftToRead = numberOfBolusRecordsToRetrieve; recordsLeftToRead > 0; recordsLeftToRead--) {
|
||||
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA);
|
||||
bolusHistory.add(readBolusRecord());
|
||||
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
|
||||
scripter.pressDownKey();
|
||||
while (record == (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD)) {
|
||||
scripter.waitForScreenUpdate();
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
if (!result.history.bolusHistory.isEmpty()) {
|
||||
log.debug("Read bolus history (" + result.history.bolusHistory.size() + "):");
|
||||
for (Bolus bolus : result.history.bolusHistory) {
|
||||
log.debug(new Date(bolus.timestamp) + ": " + bolus.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scripter.returnToRootMenu();
|
||||
result.success = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue