Read quick info first when checking history.

This commit is contained in:
Johannes Mockenhaupt 2018-01-31 00:06:04 +01:00
parent ecd16c26b8
commit c7cccf3220
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -8,21 +8,10 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter;
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.PumpHistory;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -44,6 +33,18 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter;
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.PumpHistory;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
/** /**
@ -350,9 +351,8 @@ 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::readQuickInfo); // trigger a connect, which will update state and check history
// note that since the history is checked upon every connect, the above already updated runCommand(null, 3, ruffyScripter::readPumpState);
// the DB with any changed history records
} }
} }
@ -367,7 +367,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
} }
CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing),1, ruffyScripter::readQuickInfo); // trigger a connect, which will update state and check history
CommandResult stateResult = runCommand(null,1, ruffyScripter::readPumpState);
if (!stateResult.success) { if (!stateResult.success) {
return; return;
} }
@ -1060,8 +1061,18 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
ruffyScripter.disconnect(); ruffyScripter.disconnect();
} }
private void checkHistory() { /**
long start = System.currentTimeMillis(); * Reads QuickInfo to update reservoir level and determine if new boluses exist on the pump
* and if so, queries the history for all new records.
*
* @return null on success or the failed command result
*/
private CommandResult checkHistory() {
CommandResult quickInfoResult = runCommand(MainApp.gs(R.string.combo_activity_checking_for_history_changes), 3, ruffyScripter::readQuickInfo);
if (quickInfoResult.history != null && !quickInfoResult.history.bolusHistory.isEmpty()
&& quickInfoResult.history.bolusHistory.get(0).timestamp == timestampOfLastKnownPumpBolusRecord) {
return null;
}
// TODO maybe optimize for the default case where no new records exists by checking quick info; // TODO maybe optimize for the default case where no new records exists by checking quick info;
// and only read My Data history when quick info shows a new record // and only read My Data history when quick info shows a new record