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:
Johannes Mockenhaupt 2018-02-03 18:01:15 +01:00
parent ec4280bc2e
commit 72e4cd29c4
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 45 additions and 21 deletions

View file

@ -370,7 +370,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
// trigger a connect, which will update state and check history
CommandResult stateResult = runCommand(null,1, ruffyScripter::readPumpState);
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
if (!stateResult.success) {
return;
}
@ -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));
@ -552,7 +552,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
: null;
// no bolus delivered?
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus) ) {
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
if (cancelBolus) {
return new PumpEnactResult().success(true).enacted(false);
} else {
@ -855,7 +855,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// turn benign warnings into notifications
notifyAboutPumpWarning(activeAlert);
ruffyScripter.confirmAlert(activeAlert.warningCode);
} else if (activeAlert.errorCode != null){
} else if (activeAlert.errorCode != null) {
Notification notification = new Notification();
notification.date = new Date();
notification.id = Notification.COMBO_PUMP_ALARM;

View file

@ -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. */

View file

@ -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) {
Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")
.putCustomAttribute("buildversion", BuildConfig.BUILDVERSION)
.putCustomAttribute("version", BuildConfig.VERSION));
return runCommand(new ReadQuickInfoCommand());
}
Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")
public CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve) {
Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")
.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() {

View file

@ -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();
scripter.pressCheckKey();
List<Bolus> bolusHistory = new ArrayList<>(1);
bolusHistory.add(readBolusRecord());
result.history = new PumpHistory().bolusHistory(bolusHistory);
if (numberOfBolusRecordsToRetrieve > 0) {
// navigate to bolus data menu
scripter.pressCheckKey();
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;
}