From c730d3244f4e57e4f05ff5da58cdd2c0a4005461 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Mon, 4 Feb 2019 23:56:24 +0100 Subject: [PATCH 01/15] Log app error codes --- .../PumpInsightLocal/LocalInsightPlugin.java | 62 +++++++++++++++++-- .../AppLayerErrorException.java | 4 ++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index a928d56504..2deb398350 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -115,6 +115,7 @@ import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.Operating import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.PumpTime; import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.TotalDailyDose; import info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions.InsightException; +import info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions.app_layer_errors.AppLayerErrorException; import info.nightscout.androidaps.plugins.PumpInsightLocal.exceptions.app_layer_errors.NoActiveTBRToCanceLException; import info.nightscout.androidaps.plugins.PumpInsightLocal.utils.ExceptionTranslator; import info.nightscout.androidaps.plugins.PumpInsightLocal.utils.ParameterBlockUtil; @@ -310,6 +311,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con fetchLimitations(); updatePumpTimeIfNeeded(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception while fetching status: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception while fetching status: " + e.getClass().getCanonicalName()); } catch (Exception e) { @@ -450,6 +453,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con fetchStatus(); } catch (Exception ignored) { } + } catch (AppLayerErrorException e) { + log.info("Exception while setting profile: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while setting profile: " + e.getClass().getCanonicalName()); Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); @@ -548,6 +556,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con MainApp.bus().post(bolusingEvent); readHistory(); fetchStatus(); + } catch (AppLayerErrorException e) { + log.info("Exception while delivering bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while delivering bolus: " + e.getClass().getCanonicalName()); result.comment = ExceptionTranslator.getString(e); @@ -573,6 +584,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con cancelBolusMessage.setBolusID(bolusID); connectionService.requestMessage(cancelBolusMessage).await(); confirmAlert(AlertType.WARNING_38); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); } catch (Exception e) { @@ -621,6 +634,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con try { fetchStatus(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception after setting TBR: " + e.getClass().getCanonicalName()); } catch (Exception e) { @@ -655,6 +670,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con result.comment = MainApp.gs(R.string.virtualpump_resultok); readHistory(); fetchStatus(); + } catch (AppLayerErrorException e) { + log.info("Exception while setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while setting TBR: " + e.getClass().getCanonicalName()); result.comment = ExceptionTranslator.getString(e); @@ -671,6 +689,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con try { fetchStatus(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName()); } catch (Exception e) { @@ -703,6 +723,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con result.success = true; result.enacted = true; result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (AppLayerErrorException e) { + log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName()); result.comment = ExceptionTranslator.getString(e); @@ -725,6 +748,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con try { fetchStatus(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName()); } catch (Exception e) { @@ -747,6 +772,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } catch (NoActiveTBRToCanceLException e) { result.success = true; result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while canceling TBR: " + e.getClass().getCanonicalName()); result.comment = ExceptionTranslator.getString(e); @@ -763,10 +791,12 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con try { fetchStatus(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception after canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { - log.info("Exception after canceling bolus: " + e.getClass().getCanonicalName()); + log.info("Exception after canceling extended bolus: " + e.getClass().getCanonicalName()); } catch (Exception e) { - log.error("Exception after canceling bolus", e); + log.error("Exception after canceling extended bolus", e); } return result; } @@ -805,11 +835,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } result.success = true; result.comment = MainApp.gs(R.string.virtualpump_resultok); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { - log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); + log.info("Exception while canceling extended bolus: " + e.getClass().getCanonicalName()); result.comment = ExceptionTranslator.getString(e); } catch (Exception e) { - log.error("Exception while canceling bolus", e); + log.error("Exception while canceling extended bolus", e); result.comment = ExceptionTranslator.getString(e); } return result; @@ -828,6 +861,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } else break; } } + } catch (AppLayerErrorException e) { + log.info("Exception while confirming alert: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception while confirming alert: " + e.getClass().getCanonicalName()); } catch (Exception e) { @@ -899,6 +934,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con result.enacted = true; fetchStatus(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception while stopping pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while stopping pump: " + e.getClass().getCanonicalName()); result.comment = ExceptionTranslator.getString(e); @@ -919,8 +957,12 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con result.enacted = true; fetchStatus(); readHistory(); + } catch (AppLayerErrorException e) { + log.info("Exception while starting pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while starting pump: " + e.getClass().getCanonicalName()); + result.comment = ExceptionTranslator.getString(e); } catch (Exception e) { log.error("Exception while starting pump", e); result.comment = ExceptionTranslator.getString(e); @@ -936,6 +978,10 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con ParameterBlockUtil.writeConfigurationBlock(connectionService, tbrOverNotificationBlock); result.success = true; result.enacted = true; + } catch (AppLayerErrorException e) { + tbrOverNotificationBlock.setEnabled(valueBefore); + log.info("Exception while updating TBR notification block: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { tbrOverNotificationBlock.setEnabled(valueBefore); log.info("Exception while updating TBR notification block: " + e.getClass().getSimpleName()); @@ -1023,16 +1069,20 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } } processHistoryEvents(pumpSerial, historyEvents); + } catch (AppLayerErrorException e) { + log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { - log.info("Error while reading history: " + e.getClass().getSimpleName()); + log.info("Exception while reading history: " + e.getClass().getSimpleName()); } catch (Exception e) { - log.error("Error while reading history", e); + log.error("Exception while reading history", e); } finally { try { connectionService.requestMessage(new StopReadingHistoryMessage()).await(); } catch (Exception ignored) { } } + } catch (AppLayerErrorException e) { + log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { log.info("Exception while reading history: " + e.getClass().getSimpleName()); } catch (Exception e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/exceptions/app_layer_errors/AppLayerErrorException.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/exceptions/app_layer_errors/AppLayerErrorException.java index 25ba383983..6148fd86b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/exceptions/app_layer_errors/AppLayerErrorException.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/exceptions/app_layer_errors/AppLayerErrorException.java @@ -14,4 +14,8 @@ public abstract class AppLayerErrorException extends AppLayerException { public String getMessage() { return "Error code: " + errorCode; } + + public int getErrorCode() { + return errorCode; + } } From 6cb3b5fcac294133dcde7cb35382bd3d9e60e626 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:01:11 +0100 Subject: [PATCH 02/15] Change Insight driver strings --- app/src/main/res/values/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ed1380c79f..60da39318b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -868,7 +868,7 @@ Delivering the bolus and verifying the pump\'s history failed, please check the pump. If a bolus was delivered, it will be added to treatments during the next connection to the pump. Not enough insulin for bolus left in reservoir Extended bolus delivery error - Insight + Sight Insight Pump Status Changed @@ -1261,8 +1261,8 @@ Extended bolus Multiwave bolus %1$.2f / %2$.2f U for %3$d min - Enable TBR over notification - Disable TBR over notification + Enable notification of TBR end\n(pump setting) + Disable notification of TBR end\n(pump setting) Refresh Pump integration for Accu-Chek Insight pumps Not inserted From c5241b6cadd34da50c11824e9c0013ead26c0c0f Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:04:09 +0100 Subject: [PATCH 03/15] Remove unneeded variable --- .../androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 2deb398350..5043d98cda 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -154,7 +154,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con }; private final Object $bolusLock = new Object[0]; - private boolean bolusInProgress; private int bolusID = -1; private List profileBlocks; private boolean limitsFetched; From e4fd293027d7b001d74bfe614105747cda9a1ba2 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:08:49 +0100 Subject: [PATCH 04/15] Stop fetching bolus progress when pump has switched operating mode (e.g. because of an empty cartridge) --- .../PumpInsightLocal/LocalInsightPlugin.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 5043d98cda..53fb720132 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -535,10 +535,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con detailedBolusInfo.pumpId = insightBolusID.id; TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); while (true) { - List activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses(); + fetchStatus(); + if (operatingMode != OperatingMode.STARTED) break; ActiveBolus activeBolus = null; for (ActiveBolus bolus : activeBoluses) { - if (bolus.getBolusID() == bolusID) activeBolus = bolus; + if (bolus.getBolusID() == bolusID) { + activeBolus = bolus; + break; + } } if (activeBolus != null) { trials = -1; @@ -547,12 +551,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()); if (percentBefore != bolusingEvent.percent) MainApp.bus().post(bolusingEvent); - } else if (trials == -1 || trials++ >= 5) break; + } else if (trials == -1 || trials++ >= 5) { + bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin); + bolusingEvent.percent = 100; + MainApp.bus().post(bolusingEvent); + break; + } Thread.sleep(200); } - bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin); - bolusingEvent.percent = 100; - MainApp.bus().post(bolusingEvent); readHistory(); fetchStatus(); } catch (AppLayerErrorException e) { From baac836d648a5107001377205822a6a94a1750b6 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:14:10 +0100 Subject: [PATCH 05/15] Don't read past history events when pump is newly paired. --- .../PumpInsightLocal/LocalInsightPlugin.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 53fb720132..5fc3ac3f0b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -1057,11 +1057,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con startMessage.setDirection(HistoryReadingDirection.BACKWARD); startMessage.setOffset(0xFFFFFFFF); connectionService.requestMessage(startMessage).await(); - for (int i = 0; i < 50; i++) { - List newEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents(); - if (newEvents.size() == 0) break; - historyEvents.addAll(newEvents); - } + historyEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents(); } else { StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage(); startMessage.setDirection(HistoryReadingDirection.FORWARD); @@ -1073,7 +1069,15 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con historyEvents.addAll(newEvents); } } - processHistoryEvents(pumpSerial, historyEvents); + Collections.sort(historyEvents); + Collections.reverse(historyEvents); + if (historyOffset != null) processHistoryEvents(pumpSerial, historyEvents); + if (historyEvents.size() > 0) { + historyOffset = new InsightHistoryOffset(); + historyOffset.pumpSerial = pumpSerial; + historyOffset.offset = historyEvents.get(0).getEventPosition(); + MainApp.getDbHelper().createOrUpdate(historyOffset); + } } catch (AppLayerErrorException e) { log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); } catch (InsightException e) { @@ -1097,8 +1101,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } private void processHistoryEvents(String serial, List historyEvents) { - Collections.sort(historyEvents); - Collections.reverse(historyEvents); List temporaryBasals = new ArrayList<>(); List pumpStartedEvents = new ArrayList<>(); for (HistoryEvent historyEvent : historyEvents) @@ -1121,12 +1123,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con Collections.sort(temporaryBasals, (o1, o2) -> (int) (o1.date - o2.date)); for (TemporaryBasal temporaryBasal : temporaryBasals) TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); - if (historyEvents.size() > 0) { - InsightHistoryOffset historyOffset = new InsightHistoryOffset(); - historyOffset.pumpSerial = serial; - historyOffset.offset = historyEvents.get(0).getEventPosition(); - MainApp.getDbHelper().createOrUpdate(historyOffset); - } } private boolean processHistoryEvent(String serial, List temporaryBasals, List pumpStartedEvents, HistoryEvent event) { From 317f171286017de52e86425f8dfcb7095f86792e Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:25:07 +0100 Subject: [PATCH 06/15] Fetch pump status after pairing --- .../plugins/PumpInsightLocal/InsightAlertService.java | 4 ++-- .../plugins/PumpInsightLocal/LocalInsightPlugin.java | 8 +++++++- .../activities/InsightPairingActivity.java | 5 ++--- .../connection_service/InsightConnectionService.java | 9 ++++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/InsightAlertService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/InsightAlertService.java index 9122132de8..dbedf83867 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/InsightAlertService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/InsightAlertService.java @@ -48,7 +48,7 @@ public class InsightAlertService extends Service implements InsightConnectionSer public void onServiceConnected(ComponentName name, IBinder binder) { connectionService = ((InsightConnectionService.LocalBinder) binder).getService(); connectionService.registerStateCallback(InsightAlertService.this); - stateChanged(connectionService.getState()); + onStateChanged(connectionService.getState()); } @Override @@ -114,7 +114,7 @@ public class InsightAlertService extends Service implements InsightConnectionSer } @Override - public void stateChanged(InsightState state) { + public void onStateChanged(InsightState state) { if (state == InsightState.CONNECTED) { thread = new Thread(this::queryActiveAlert); thread.start(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 5fc3ac3f0b..e13894ecd3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; @@ -1510,7 +1511,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } @Override - public void stateChanged(InsightState state) { + public void onStateChanged(InsightState state) { if (state == InsightState.CONNECTED) statusLoaded = false; else if (state == InsightState.NOT_PAIRED) { connectionService.withdrawConnectionRequest(this); @@ -1527,4 +1528,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventLocalInsightUpdateGUI())); } + + @Override + public void onPumpPaired() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Pump paired", null); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/activities/InsightPairingActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/activities/InsightPairingActivity.java index 390e9a233e..f97a74e94a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/activities/InsightPairingActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/activities/InsightPairingActivity.java @@ -21,7 +21,6 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; import java.util.ArrayList; import java.util.List; @@ -56,7 +55,7 @@ public class InsightPairingActivity extends AppCompatActivity implements Insight service.requestConnection(InsightPairingActivity.this); service.registerStateCallback(InsightPairingActivity.this); service.registerExceptionCallback(InsightPairingActivity.this); - stateChanged(service.getState()); + onStateChanged(service.getState()); } } @@ -116,7 +115,7 @@ public class InsightPairingActivity extends AppCompatActivity implements Insight } @Override - public void stateChanged(InsightState state) { + public void onStateChanged(InsightState state) { runOnUiThread(() -> { switch (state) { case NOT_PAIRED: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java index b4ee726a6b..bb086a541e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.AppLayerMessage; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.ReadParameterBlockMessage; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.configuration.CloseConfigurationWriteSessionMessage; @@ -245,7 +244,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab wakeLock.release(); else if (!wakeLock.isHeld()) wakeLock.acquire(); this.state = state; - for (StateCallback stateCallback : stateCallbacks) stateCallback.stateChanged(state); + for (StateCallback stateCallback : stateCallbacks) stateCallback.onStateChanged(state); log.info("Insight state changed: " + state.name()); } @@ -704,6 +703,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab pairingDataStorage.setPaired(true); log.info("Pairing completed YEE-HAW ♪ ┏(・o・)┛ ♪ ┗( ・o・)┓ ♪"); setState(InsightState.CONNECTED); + for (StateCallback stateCallback : stateCallbacks) stateCallback.onPumpPaired(); } } else processGenericAppLayerMessage(message); } @@ -771,7 +771,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab } public interface StateCallback { - void stateChanged(InsightState state); + void onStateChanged(InsightState state); + default void onPumpPaired() { + + } } public interface ExceptionCallback { From 7a7bebc5feb93218c79c85436f88b9f47d239cd0 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:30:41 +0100 Subject: [PATCH 07/15] Return false in isConnected and isConnecting when connection lock is not held. --- .../plugins/PumpInsightLocal/LocalInsightPlugin.java | 8 +++++--- .../connection_service/InsightConnectionService.java | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index e13894ecd3..8db8d112e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -261,13 +261,15 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public boolean isConnected() { - if (connectionService == null || alertService == null) return false; - return connectionService.getState() == InsightState.CONNECTED; + return connectionService != null + && alertService != null + && connectionService.hasRequestedConnection(this) + && connectionService.getState() == InsightState.CONNECTED; } @Override public boolean isConnecting() { - if (connectionService == null || alertService == null) return false; + if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false; InsightState state = connectionService.getState(); return state == InsightState.CONNECTING || state == InsightState.APP_CONNECT_MESSAGE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java index bb086a541e..ce046420a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/connection_service/InsightConnectionService.java @@ -277,6 +277,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab } } + public synchronized boolean hasRequestedConnection(Object lock) { + return connectionRequests.contains(lock); + } + private void cleanup() { messageQueue.completeActiveRequest(new ConnectionLostException()); messageQueue.completePendingRequests(new ConnectionLostException()); From 2ad4670f07f5c0ceb16e39c5c266a130cbff18da Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:43:05 +0100 Subject: [PATCH 08/15] Refresh overview when pump is unpaired --- .../androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 8db8d112e1..80eaeb9aff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -1527,6 +1527,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con activeTBR = null; activeBoluses = null; tbrOverNotificationBlock = null; + new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventRefreshOverview("LocalInsightPlugin::onStateChanged"))); } new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventLocalInsightUpdateGUI())); } From 7035b9a5f299eb48e1ceb32a1228d39a594ca682 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:47:45 +0100 Subject: [PATCH 09/15] Fix Quick Wizard for Insight pump --- .../androidaps/plugins/Overview/OverviewFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index a414d38310..b93d2f4b9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -808,7 +808,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return; } accepted = true; - if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { + if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || finalCarbsAfterConstraints > 0) { if (wizard.superBolus) { final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); if (loopPlugin.isEnabled(PluginType.LOOP)) { From f5d65e044c1bf0c8ae2a3c9a21d7ff02f67a47bc Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 22:49:38 +0100 Subject: [PATCH 10/15] Fix wear bolus for Insight --- .../nightscout/androidaps/plugins/Wear/ActionStringHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 5245921922..88c26023c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -232,7 +232,7 @@ public class ActionStringHandler { 0d, percentage, useBolusIOB, useBasalIOB, false, useTrend); Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolusWizard.calculatedTotalInsulin)).value(); - if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { + if (Math.abs(insulinAfterConstraints - bolusWizard.calculatedTotalInsulin) >= 0.01) { sendError("Insulin contraint violation!" + "\nCannot deliver " + format.format(bolusWizard.calculatedTotalInsulin) + "!"); return; From 0b1e181662091b88784ddd728e6118a66eb72f11 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 23:06:11 +0100 Subject: [PATCH 11/15] Quick wizard fix 2 --- .../androidaps/plugins/Overview/OverviewFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index b93d2f4b9f..b2e11b9497 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -784,7 +784,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, confirmMessage += "\n" + MainApp.gs(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U"; confirmMessage += "\n" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (!insulinAfterConstraints.equals(wizard.calculatedTotalInsulin) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) { + if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror)); builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput)); From a8a182dc9d0708cee305cac6f816d40b925319f2 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 23:12:36 +0100 Subject: [PATCH 12/15] Change way of checking operating mode during bolus delivery --- .../plugins/PumpInsightLocal/LocalInsightPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 80eaeb9aff..cf35e954b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -538,8 +538,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con detailedBolusInfo.pumpId = insightBolusID.id; TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); while (true) { - fetchStatus(); + OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); if (operatingMode != OperatingMode.STARTED) break; + List activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses(); ActiveBolus activeBolus = null; for (ActiveBolus bolus : activeBoluses) { if (bolus.getBolusID() == bolusID) { From 4146c8a770466ec5183fc948ad46fff958c420f7 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 23:14:57 +0100 Subject: [PATCH 13/15] Don't send final bolus event after bolus cancel --- .../plugins/PumpInsightLocal/LocalInsightPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index cf35e954b3..4d9d66663c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -538,6 +538,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con detailedBolusInfo.pumpId = insightBolusID.id; TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); while (true) { + synchronized ($bolusLock) { + if (bolusID == -1) break; + } OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); if (operatingMode != OperatingMode.STARTED) break; List activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses(); @@ -592,6 +595,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); cancelBolusMessage.setBolusID(bolusID); connectionService.requestMessage(cancelBolusMessage).await(); + bolusID = -1; confirmAlert(AlertType.WARNING_38); } catch (AppLayerErrorException e) { log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); From 7a4d721c295d7cd31cc5af34d9f1e7a93db59e99 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 9 Feb 2019 23:50:12 +0100 Subject: [PATCH 14/15] Fix bolus progress dialog with bolus cancel --- .../PumpInsightLocal/LocalInsightPlugin.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 4d9d66663c..cf833fac40 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -69,12 +69,7 @@ import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.his import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent; -import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.ActiveBRProfileBlock; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block; -import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile2Block; -import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile3Block; -import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile4Block; -import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile5Block; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock; @@ -155,7 +150,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con }; private final Object $bolusLock = new Object[0]; - private int bolusID = -1; + private int bolusID; + private boolean bolusCancelled; private List profileBlocks; private boolean limitsFetched; private double maximumBolusAmount; @@ -269,7 +265,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public boolean isConnecting() { - if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false; + if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) + return false; InsightState state = connectionService.getState(); return state == InsightState.CONNECTING || state == InsightState.APP_CONNECT_MESSAGE @@ -517,6 +514,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con bolusMessage.setExtendedAmount(0); bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); + bolusCancelled = false; } result.success = true; result.enacted = true; @@ -539,7 +537,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); while (true) { synchronized ($bolusLock) { - if (bolusID == -1) break; + if (bolusCancelled) break; } OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); if (operatingMode != OperatingMode.STARTED) break; @@ -558,11 +556,17 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()); if (percentBefore != bolusingEvent.percent) MainApp.bus().post(bolusingEvent); - } else if (trials == -1 || trials++ >= 5) { - bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin); - bolusingEvent.percent = 100; - MainApp.bus().post(bolusingEvent); - break; + } else { + synchronized ($bolusLock) { + if (bolusCancelled || trials == -1 || trials++ >= 5) { + if (!bolusCancelled) { + bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin); + bolusingEvent.percent = 100; + MainApp.bus().post(bolusingEvent); + } + break; + } + } } Thread.sleep(200); } @@ -589,21 +593,21 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public void stopBolusDelivering() { new Thread(() -> { - synchronized ($bolusLock) { - try { + try { + synchronized ($bolusLock) { alertService.ignore(AlertType.WARNING_38); CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); cancelBolusMessage.setBolusID(bolusID); connectionService.requestMessage(cancelBolusMessage).await(); - bolusID = -1; - confirmAlert(AlertType.WARNING_38); - } catch (AppLayerErrorException e) { - log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); - } catch (InsightException e) { - log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); - } catch (Exception e) { - log.error("Exception while canceling bolus", e); + bolusCancelled = true; } + confirmAlert(AlertType.WARNING_38); + } catch (AppLayerErrorException e) { + log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); + } catch (InsightException e) { + log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception while canceling bolus", e); } }).start(); } From 4a11723a6146e76f7a63d991cacd986c9229587f Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sun, 10 Feb 2019 00:03:59 +0100 Subject: [PATCH 15/15] Fix zero-temp for pump stopped periods --- .../nightscout/androidaps/db/DatabaseHelper.java | 2 +- .../PumpInsightLocal/LocalInsightPlugin.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index f9011bc271..c75de5115a 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -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) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index cf833fac40..aeb795afcf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -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 temporaryBasals, StartOfTBREvent event) {