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
|
@ -370,7 +370,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger a connect, which will update state and check history
|
// 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) {
|
if (!stateResult.success) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
|
|
||||||
// ComboFragment updates state fully only after the pump has initialized,
|
// ComboFragment updates state fully only after the pump has initialized,
|
||||||
// so force an update after initialization completed
|
// 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 */
|
/** 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
|
// history below to see what was actually delivered
|
||||||
|
|
||||||
// get last bolus from pump history for verification
|
// 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) {
|
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));
|
||||||
|
@ -552,7 +552,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// no bolus delivered?
|
// no bolus delivered?
|
||||||
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus) ) {
|
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
|
||||||
if (cancelBolus) {
|
if (cancelBolus) {
|
||||||
return new PumpEnactResult().success(true).enacted(false);
|
return new PumpEnactResult().success(true).enacted(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -855,7 +855,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
// turn benign warnings into notifications
|
// turn benign warnings into notifications
|
||||||
notifyAboutPumpWarning(activeAlert);
|
notifyAboutPumpWarning(activeAlert);
|
||||||
ruffyScripter.confirmAlert(activeAlert.warningCode);
|
ruffyScripter.confirmAlert(activeAlert.warningCode);
|
||||||
} else if (activeAlert.errorCode != null){
|
} else if (activeAlert.errorCode != null) {
|
||||||
Notification notification = new Notification();
|
Notification notification = new Notification();
|
||||||
notification.date = new Date();
|
notification.date = new Date();
|
||||||
notification.id = Notification.COMBO_PUMP_ALARM;
|
notification.id = Notification.COMBO_PUMP_ALARM;
|
||||||
|
|
|
@ -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 readQuickInfo();
|
CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve);
|
||||||
|
|
||||||
/** 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. */
|
||||||
|
|
|
@ -48,8 +48,6 @@ 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 readQuickInfo = true;
|
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
||||||
|
|
||||||
private IRuffyService ruffyService;
|
private IRuffyService ruffyService;
|
||||||
|
@ -225,17 +223,11 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult readQuickInfo() {
|
public CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve) {
|
||||||
if (readQuickInfo) {
|
Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")
|
||||||
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("buildversion", BuildConfig.BUILDVERSION)
|
||||||
.putCustomAttribute("version", BuildConfig.VERSION));
|
.putCustomAttribute("version", BuildConfig.VERSION));
|
||||||
return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
return runCommand(new ReadQuickInfoCommand(numberOfBolusRecordsToRetrieve));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnToRootMenu() {
|
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.MenuAttribute;
|
||||||
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
|
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
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 ReadQuickInfoCommand extends BaseCommand {
|
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
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
scripter.verifyRootMenuIsDisplayed();
|
scripter.verifyRootMenuIsDisplayed();
|
||||||
|
// navigate to reservoir menu
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
scripter.waitForMenuToBeLeft(MenuType.MAIN_MENU);
|
scripter.waitForMenuToBeLeft(MenuType.MAIN_MENU);
|
||||||
scripter.waitForMenuToBeLeft(MenuType.STOP);
|
scripter.waitForMenuToBeLeft(MenuType.STOP);
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO);
|
scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO);
|
||||||
result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue();
|
result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue();
|
||||||
scripter.pressCheckKey();
|
if (numberOfBolusRecordsToRetrieve > 0) {
|
||||||
List<Bolus> bolusHistory = new ArrayList<>(1);
|
// navigate to bolus data menu
|
||||||
bolusHistory.add(readBolusRecord());
|
scripter.pressCheckKey();
|
||||||
result.history = new PumpHistory().bolusHistory(bolusHistory);
|
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();
|
scripter.returnToRootMenu();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue