Use real TBR cancels and dismiss their alerts
This commit is contained in:
parent
f151cbb0bf
commit
a86c654f8d
7 changed files with 69 additions and 78 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -25,26 +25,16 @@ 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;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
} else if (message instanceof SetTBRMessage) finish(amount);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -58,14 +58,9 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -16,12 +16,6 @@
|
|||
android:summary="@string/automatically_connect_when"
|
||||
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
|
||||
android:defaultValue="false"
|
||||
android:key="insight_automatic_careportal_events"
|
||||
|
|
Loading…
Reference in a new issue