Use real TBR cancels and dismiss their alerts

This commit is contained in:
TebbeUbben 2018-06-03 10:56:29 +02:00
parent f151cbb0bf
commit a86c654f8d
7 changed files with 69 additions and 78 deletions

View file

@ -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.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusSilentlyTaskRunner; 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.Connector;
import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner; import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner;
import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner; 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 { private void realTBRCancel() throws Exception {
fauxTBRcancel = !SP.getBoolean("insight_real_tbr_cancel", false); if (fetchTaskRunner(new CancelTBRSilentlyTaskRunner(connector.getServiceConnector()), Boolean.class) && TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
if (fauxTBRcancel) fetchTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), 100, 1));
else fetchSingleMessage(new CancelTBRMessage());
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER); TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
} }

View file

@ -47,13 +47,13 @@ public class CancelBolusSilentlyTaskRunner extends TaskRunner {
} else if (message instanceof ActiveAlertMessage) { } else if (message instanceof ActiveAlertMessage) {
ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message; ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) message;
if (activeAlertMessage.getAlert() == null) { if (activeAlertMessage.getAlert() == null) {
if (System.currentTimeMillis() - cancelledAt >= 10000) finish(null); if (System.currentTimeMillis() - cancelledAt >= 10000) finish(bolusId);
else { else {
ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage(); ActiveAlertMessage activeAlertMessage2 = new ActiveAlertMessage();
activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER); activeAlertMessage2.setMessagePriority(MessagePriority.HIGHER);
return activeAlertMessage2; return activeAlertMessage2;
} }
} else if (!(activeAlertMessage.getAlert() instanceof Warning38BolusCancelled)) finish(null); } else if (!(activeAlertMessage.getAlert() instanceof Warning38BolusCancelled)) finish(bolusId);
else { else {
DismissAlertMessage dismissAlertMessage = new DismissAlertMessage(); DismissAlertMessage dismissAlertMessage = new DismissAlertMessage();
dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID()); dismissAlertMessage.setAlertID(activeAlertMessage.getAlertID());

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -25,25 +25,15 @@ public class SetTBRTaskRunner extends TaskRunner {
if (message == null) return new CurrentTBRMessage(); if (message == null) return new CurrentTBRMessage();
else if (message instanceof CurrentTBRMessage) { else if (message instanceof CurrentTBRMessage) {
if (((CurrentTBRMessage) message).getPercentage() == 100) { if (((CurrentTBRMessage) message).getPercentage() == 100) {
if (amount == 100) finish(amount); SetTBRMessage setTBRMessage = new SetTBRMessage();
else { setTBRMessage.setDuration(duration);
SetTBRMessage setTBRMessage = new SetTBRMessage(); setTBRMessage.setAmount(amount);
setTBRMessage.setDuration(duration); return setTBRMessage;
setTBRMessage.setAmount(amount);
return setTBRMessage;
}
} else { } else {
if (amount == 100) { ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage(); changeTBRMessage.setDuration(duration);
changeTBRMessage.setDuration(1); changeTBRMessage.setAmount(amount);
changeTBRMessage.setAmount(90); return changeTBRMessage;
return changeTBRMessage;
} else {
ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage();
changeTBRMessage.setDuration(duration);
changeTBRMessage.setAmount(amount);
return changeTBRMessage;
}
} }
} else if (message instanceof SetTBRMessage) finish(amount); } else if (message instanceof SetTBRMessage) finish(amount);
return null; return null;

View file

@ -58,13 +58,8 @@ class HistoryIntentAdapter {
final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id); final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id);
// other sanity checks log("Creating TBR record: " + pump_tbr_percent + "% " + pump_tbr_duration + "m" + " id:" + record_unique_id);
if ((pump_tbr_percent == 90) && (pump_tbr_duration <= 1)) { logAdapter.createTBRrecord(start_time, pump_tbr_percent, pump_tbr_duration, record_unique_id);
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);
}
} }
void processDeliveredBolusIntent(Intent intent) { void processDeliveredBolusIntent(Intent intent) {
@ -160,8 +155,10 @@ class HistoryIntentAdapter {
if (SP.getBoolean("insight_automatic_careportal_events", false)) { if (SP.getBoolean("insight_automatic_careportal_events", false)) {
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME); Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE); String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE);
int alertText = getAlertText(alertType);
if (alertText == 0) return;
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) 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("Warning32BatteryLow")) return R.string.alert_w32;
if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33; if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33;
if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34; if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34;
if (type.equals("Warning36TBRCancelled")) return R.string.alert_w36; if (type.equals("Warning36TBRCancelled")) return 0;
if (type.equals("Warning38BolusCancelled")) return R.string.alert_w38; if (type.equals("Warning38BolusCancelled")) return 0;
if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39; if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39;
return 0; return 0;
} }

View file

@ -16,12 +16,6 @@
android:summary="@string/automatically_connect_when" android:summary="@string/automatically_connect_when"
android:title="@string/connect_preemptively" /> android:title="@string/connect_preemptively" />
<SwitchPreference
android:defaultValue="false"
android:key="insight_real_tbr_cancel"
android:summary="@string/insight_actually_cancel_tbr_summary"
android:title="@string/insight_use_real_tbr_cancels" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="insight_automatic_careportal_events" android:key="insight_automatic_careportal_events"