Clean up pump init.

This commit is contained in:
Johannes Mockenhaupt 2017-10-27 19:40:44 +02:00
parent a1d6834bce
commit a8061b410c
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -45,6 +45,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
private boolean fragmentEnabled = false; private boolean fragmentEnabled = false;
private boolean fragmentVisible = false; private boolean fragmentVisible = false;
private boolean initialized = false;
private PumpDescription pumpDescription = new PumpDescription(); private PumpDescription pumpDescription = new PumpDescription();
@NonNull @NonNull
@ -178,7 +180,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return pump.lastCmdResult != null; return initialized;
} }
@Override @Override
@ -213,21 +215,26 @@ public class ComboPlugin implements PluginBase, PumpInterface {
public synchronized void refreshDataFromPump(String reason) { public synchronized void refreshDataFromPump(String reason) {
log.debug("RefreshDataFromPump called"); log.debug("RefreshDataFromPump called");
boolean firstRun = pump.lastCmdResult == null; if (!initialized) {
runCommand(MainApp.sResources.getString(R.string.connecting), new CommandExecution() {
runCommand("Refreshing", new CommandExecution() { @Override
@Override public CommandResult execute() {
public CommandResult execute() { return ruffyScripter.readPumpState();
return ruffyScripter.readHistory(new PumpHistoryRequest().reservoirLevel(true).bolusHistory(PumpHistoryRequest.LAST)); }
} });
}); checkPumpHistory();
initialized = true;
if (firstRun) { } else {
initializePump(); runCommand(MainApp.sResources.getString(R.string.combo_action_refreshing), new CommandExecution() {
@Override
public CommandResult execute() {
return ruffyScripter.readHistory(new PumpHistoryRequest().reservoirLevel(true).bolusHistory(PumpHistoryRequest.LAST));
}
});
} }
} }
private void initializePump() { private void checkPumpHistory() {
CommandResult commandResult = runCommand("Checking pump history", false, new CommandExecution() { CommandResult commandResult = runCommand("Checking pump history", false, new CommandExecution() {
@Override @Override
public CommandResult execute() { public CommandResult execute() {