Fix zero-temp for pump stopped periods

This commit is contained in:
TebbeUbben 2019-02-10 00:03:59 +01:00
parent 7a4d721c29
commit 4a11723a61
2 changed files with 8 additions and 8 deletions

View file

@ -1739,7 +1739,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return getDaoInsightPumpID().queryBuilder()
.orderBy("timestamp", false)
.where().eq("pumpSerial", pumpSerial)
.and().eq("eventType", "PumpStopped")
.and().in("eventType", "PumpStopped", "PumpPaused")
.and().lt("timestamp", before)
.queryForFirst();
} catch (SQLException e) {

View file

@ -305,11 +305,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
public void getPumpStatus() {
try {
tbrOverNotificationBlock = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, TBROverNotificationBlock.class);
fetchStatus();
readHistory();
fetchBasalProfile();
fetchLimitations();
updatePumpTimeIfNeeded();
readHistory();
fetchStatus();
} catch (AppLayerErrorException e) {
log.info("Exception while fetching status: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
} catch (InsightException e) {
@ -1121,7 +1121,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
Collections.reverse(temporaryBasals);
for (InsightPumpID pumpID : pumpStartedEvents) {
InsightPumpID stoppedEvent = MainApp.getDbHelper().getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp);
if (stoppedEvent == null) continue;
if (stoppedEvent == null || stoppedEvent.eventType.equals("PumpPaused")) continue;
long tbrStart = stoppedEvent.timestamp + 10000;
TemporaryBasal temporaryBasal = new TemporaryBasal();
temporaryBasal.durationInMinutes = (int) ((pumpID.timestamp - tbrStart) / 60000);
@ -1221,22 +1221,22 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
switch (event.getNewValue()) {
case STARTED:
pumpID.eventType = "PumpStarted";
MainApp.getDbHelper().createOrUpdate(pumpID);
pumpStartedEvents.add(pumpID);
if (SP.getBoolean("insight_log_operating_mode_changes", false))
logNote(timestamp, MainApp.gs(R.string.pump_started));
break;
case STOPPED:
pumpID.eventType = "PumpStopped";
if (SP.getBoolean("insight_log_operating_mode_changes", false))
pumpID.eventType = "PumpStopped";
MainApp.getDbHelper().createOrUpdate(pumpID);
logNote(timestamp, MainApp.gs(R.string.pump_stopped));
logNote(timestamp, MainApp.gs(R.string.pump_stopped));
break;
case PAUSED:
pumpID.eventType = "PumpPaused";
if (SP.getBoolean("insight_log_operating_mode_changes", false))
logNote(timestamp, MainApp.gs(R.string.pump_paused));
break;
}
MainApp.getDbHelper().createOrUpdate(pumpID);
}
private void processStartOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, StartOfTBREvent event) {