diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java
index 2329fbc8a9..b99b8ec908 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java
@@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusSilentlyTaskRunner;
+import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelTBRSilentlyTaskRunner;
import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector;
import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner;
import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner;
@@ -553,10 +554,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
}
private void realTBRCancel() throws Exception {
- fauxTBRcancel = !SP.getBoolean("insight_real_tbr_cancel", false);
- if (fauxTBRcancel) fetchTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), 100, 1));
- else fetchSingleMessage(new CancelTBRMessage());
- if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
+ if (fetchTaskRunner(new CancelTBRSilentlyTaskRunner(connector.getServiceConnector()), Boolean.class) && TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java
index fe2fb944f4..7b3108602e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusSilentlyTaskRunner.java
@@ -47,13 +47,13 @@ public class CancelBolusSilentlyTaskRunner extends TaskRunner {
} else if (message instanceof ActiveAlertMessage) {
ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message;
if (activeAlertMessage.getAlert() == null) {
- if (System.currentTimeMillis() - cancelledAt >= 10000) finish(null);
+ if (System.currentTimeMillis() - cancelledAt >= 10000) finish(bolusId);
else {
ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage();
activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER);
return activeAlertMessage2;
}
- } else if (!(activeAlertMessage.getAlert() instanceof Warning38BolusCancelled)) finish(null);
+ } else if (!(activeAlertMessage.getAlert() instanceof Warning38BolusCancelled)) finish(bolusId);
else {
DismissAlertMessage dismissAlertMessage = new DismissAlertMessage();
dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID());
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusTaskRunner.java
deleted file mode 100644
index f350b80851..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelBolusTaskRunner.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package info.nightscout.androidaps.plugins.PumpInsight.connector;
-
-import sugar.free.sightparser.applayer.messages.AppLayerMessage;
-import sugar.free.sightparser.applayer.descriptors.ActiveBolusType;
-import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage;
-import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage;
-import sugar.free.sightparser.handling.SightServiceConnector;
-import sugar.free.sightparser.handling.TaskRunner;
-
-// by Tebbe Ubben
-
-public class CancelBolusTaskRunner extends TaskRunner {
-
- private ActiveBolusType bolusType;
-
- public CancelBolusTaskRunner(SightServiceConnector serviceConnector, ActiveBolusType bolusType) {
- super(serviceConnector);
- this.bolusType = bolusType;
- }
-
- @Override
- protected AppLayerMessage run(AppLayerMessage message) throws Exception {
- if (message == null) return new ActiveBolusesMessage();
- else if (message instanceof ActiveBolusesMessage) {
- ActiveBolusesMessage bolusesMessage = (ActiveBolusesMessage) message;
- CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
- if (bolusesMessage.getBolus1().getBolusType() == bolusType)
- cancelBolusMessage.setBolusId(bolusesMessage.getBolus1().getBolusID());
- else if (bolusesMessage.getBolus2().getBolusType() == bolusType)
- cancelBolusMessage.setBolusId(bolusesMessage.getBolus2().getBolusID());
- else if (bolusesMessage.getBolus3().getBolusType() == bolusType)
- cancelBolusMessage.setBolusId(bolusesMessage.getBolus3().getBolusID());
- else finish(null);
- return cancelBolusMessage;
- } else if (message instanceof CancelBolusMessage) finish(null);
- return null;
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java
new file mode 100644
index 0000000000..9a3068aef9
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/CancelTBRSilentlyTaskRunner.java
@@ -0,0 +1,50 @@
+package info.nightscout.androidaps.plugins.PumpInsight.connector;
+
+import sugar.free.sightparser.applayer.descriptors.MessagePriority;
+import sugar.free.sightparser.applayer.descriptors.alerts.Warning36TBRCancelled;
+import sugar.free.sightparser.applayer.messages.AppLayerMessage;
+import sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage;
+import sugar.free.sightparser.applayer.messages.remote_control.DismissAlertMessage;
+import sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage;
+import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage;
+import sugar.free.sightparser.handling.SightServiceConnector;
+import sugar.free.sightparser.handling.TaskRunner;
+
+public class CancelTBRSilentlyTaskRunner extends TaskRunner {
+
+ private long cancelledAt;
+
+ public CancelTBRSilentlyTaskRunner(SightServiceConnector serviceConnector) {
+ super(serviceConnector);
+ }
+
+ @Override
+ protected AppLayerMessage run(AppLayerMessage message) throws Exception {
+ if (message == null) return new CurrentTBRMessage();
+ else if (message instanceof CurrentTBRMessage) {
+ if (((CurrentTBRMessage) message).getPercentage() == 100) finish(false);
+ else return new CancelTBRMessage();
+ } else if (message instanceof CancelTBRMessage) {
+ ActiveAlertMessage activeAlertMessage = new ActiveAlertMessage();
+ activeAlertMessage.setMessagePriority(MessagePriority.HIGHER);
+ return activeAlertMessage;
+ } else if (message instanceof ActiveAlertMessage) {
+ ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message;
+ if (activeAlertMessage.getAlert() == null) {
+ if (System.currentTimeMillis() - cancelledAt >= 10000) finish(true);
+ else {
+ ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage();
+ activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER);
+ return activeAlertMessage2;
+ }
+ } else if (!(activeAlertMessage.getAlert() instanceof Warning36TBRCancelled)) finish(true);
+ else {
+ DismissAlertMessage dismissAlertMessage = new DismissAlertMessage();
+ dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID());
+ dismissAlertMessage.setMessagePriority(MessagePriority.HIGHER);
+ return dismissAlertMessage;
+ }
+ } else if (message instanceof DismissAlertMessage) finish(true);
+ return null;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java
index 1506ecb4a9..f18bb0d487 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java
@@ -25,25 +25,15 @@ public class SetTBRTaskRunner extends TaskRunner {
if (message == null) return new CurrentTBRMessage();
else if (message instanceof CurrentTBRMessage) {
if (((CurrentTBRMessage) message).getPercentage() == 100) {
- if (amount == 100) finish(amount);
- else {
- SetTBRMessage setTBRMessage = new SetTBRMessage();
- setTBRMessage.setDuration(duration);
- setTBRMessage.setAmount(amount);
- return setTBRMessage;
- }
+ SetTBRMessage setTBRMessage = new SetTBRMessage();
+ setTBRMessage.setDuration(duration);
+ setTBRMessage.setAmount(amount);
+ return setTBRMessage;
} else {
- if (amount == 100) {
- ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
- changeTBRMessage.setDuration(1);
- changeTBRMessage.setAmount(90);
- return changeTBRMessage;
- } else {
- ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
- changeTBRMessage.setDuration(duration);
- changeTBRMessage.setAmount(amount);
- return changeTBRMessage;
- }
+ ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
+ changeTBRMessage.setDuration(duration);
+ changeTBRMessage.setAmount(amount);
+ return changeTBRMessage;
}
} else if (message instanceof SetTBRMessage) finish(amount);
return null;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java
index e7784287b7..2c2235bf47 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java
@@ -58,13 +58,8 @@ class HistoryIntentAdapter {
final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id);
- // other sanity checks
- if ((pump_tbr_percent == 90) && (pump_tbr_duration <= 1)) {
- log("Not creating TBR record for faux cancel");
- } else {
- log("Creating TBR record: " + pump_tbr_percent + "% " + pump_tbr_duration + "m" + " id:" + record_unique_id);
- logAdapter.createTBRrecord(start_time, pump_tbr_percent, pump_tbr_duration, record_unique_id);
- }
+ log("Creating TBR record: " + pump_tbr_percent + "% " + pump_tbr_duration + "m" + " id:" + record_unique_id);
+ logAdapter.createTBRrecord(start_time, pump_tbr_percent, pump_tbr_duration, record_unique_id);
}
void processDeliveredBolusIntent(Intent intent) {
@@ -160,8 +155,10 @@ class HistoryIntentAdapter {
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE);
+ int alertText = getAlertText(alertType);
+ if (alertText == 0) return;
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) return;
- logNote(date, MainApp.gs(getAlertText(alertType)));
+ logNote(date, MainApp.gs(alertText));
}
}
@@ -231,8 +228,8 @@ class HistoryIntentAdapter {
if (type.equals("Warning32BatteryLow")) return R.string.alert_w32;
if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33;
if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34;
- if (type.equals("Warning36TBRCancelled")) return R.string.alert_w36;
- if (type.equals("Warning38BolusCancelled")) return R.string.alert_w38;
+ if (type.equals("Warning36TBRCancelled")) return 0;
+ if (type.equals("Warning38BolusCancelled")) return 0;
if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39;
return 0;
}
diff --git a/app/src/main/res/xml/pref_insightpump.xml b/app/src/main/res/xml/pref_insightpump.xml
index ead03ec31f..cb0eef8c16 100644
--- a/app/src/main/res/xml/pref_insightpump.xml
+++ b/app/src/main/res/xml/pref_insightpump.xml
@@ -16,12 +16,6 @@
android:summary="@string/automatically_connect_when"
android:title="@string/connect_preemptively" />
-
-