Disable instead of remove 'Enable pump unreachable' preference for pumps that have a fixed unreachable warning; make pump unreachable threshold configurable for pumps that have a fixed unreachable warning

This commit is contained in:
Bart Sopers 2020-01-19 22:27:00 +01:00
parent db2c95af46
commit bc06b6b24a
5 changed files with 19 additions and 18 deletions

View file

@ -10,6 +10,7 @@ import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -208,12 +209,14 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (activePump != null && localAlertsPreferenceScreen != null && activePump.getPumpDescription().hasFixedUnreachableAlert) { if (activePump != null && localAlertsPreferenceScreen != null && activePump.getPumpDescription().hasFixedUnreachableAlert) {
Preference pumpUnreachableEnabledPreference = findPreference(MainApp.gs(R.string.key_enable_pump_unreachable_alert)); Preference pumpUnreachableEnabledPreference = findPreference(MainApp.gs(R.string.key_enable_pump_unreachable_alert));
if (pumpUnreachableEnabledPreference != null) { if (pumpUnreachableEnabledPreference != null) {
localAlertsPreferenceScreen.removePreference(pumpUnreachableEnabledPreference); ((SwitchPreference) pumpUnreachableEnabledPreference).setChecked(true);
pumpUnreachableEnabledPreference.setEnabled(false);
pumpUnreachableEnabledPreference.setShouldDisableView(true);
} }
Preference pumpUnreachableThresholdPreference = findPreference(MainApp.gs(R.string.key_pump_unreachable_threshold)); Preference pumpUnreachableThresholdPreference = findPreference(MainApp.gs(R.string.key_pump_unreachable_threshold));
if (pumpUnreachableThresholdPreference != null) { if (pumpUnreachableThresholdPreference != null) {
localAlertsPreferenceScreen.removePreference(pumpUnreachableThresholdPreference); pumpUnreachableThresholdPreference.setDependency(null);
} }
} }
} }

View file

@ -100,7 +100,7 @@ public interface PumpInterface {
void timeDateOrTimeZoneChanged(); void timeDateOrTimeZoneChanged();
/* Only used for pump types where hasFixedUnreachableAlert=true */ /* Only used for pump types where hasFixedUnreachableAlert=true */
default boolean isFixedUnreachableAlertTimeoutExceeded() { default boolean isFixedUnreachableAlertTimeoutExceeded(long alertTimeoutMilliseconds) {
return false; return false;
} }

View file

@ -70,7 +70,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.T;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -108,7 +107,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
boolean omnipodServiceRunning = false; boolean omnipodServiceRunning = false;
private long nextPodCheck = 0L; private long nextPodCheck = 0L;
private static long UNREACHABLE_ALERT_THRESHOLD_MILLIS = T.mins(30).msecs();
private OmnipodPumpPlugin() { private OmnipodPumpPlugin() {
@ -942,11 +940,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public boolean isFixedUnreachableAlertTimeoutExceeded() { public boolean isFixedUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) {
getPodPumpStatusObject(); getPodPumpStatusObject();
if (pumpStatusLocal.lastConnection != 0 || pumpStatusLocal.lastErrorConnection != 0) { if (pumpStatusLocal.lastConnection != 0 || pumpStatusLocal.lastErrorConnection != 0) {
if (pumpStatusLocal.lastConnection + UNREACHABLE_ALERT_THRESHOLD_MILLIS < System.currentTimeMillis()) { if (pumpStatusLocal.lastConnection + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
if (pumpStatusLocal.lastErrorConnection > pumpStatusLocal.lastConnection) { if (pumpStatusLocal.lastErrorConnection > pumpStatusLocal.lastConnection) {
// We exceeded the alert threshold, and our last connection failed // We exceeded the alert threshold, and our last connection failed
// We should show an alert // We should show an alert
@ -960,8 +958,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
// If we have no last connection and error data, don't show any alert
// FIXME is this appropriate?
return false; return false;
} }
} }

View file

@ -48,10 +48,12 @@ public class LocalAlertUtils {
return; return;
} }
if(pump.isFixedUnreachableAlertTimeoutExceeded()) { long pumpUnreachableThresholdMilliseconds = pumpUnreachableThreshold();
if (pump.isFixedUnreachableAlertTimeoutExceeded(pumpUnreachableThresholdMilliseconds)) {
log.debug("Generating static pump unreachable alarm."); log.debug("Generating static pump unreachable alarm.");
showUnreachableNotification(T.mins(30).msecs()); showUnreachableNotification(pumpUnreachableThresholdMilliseconds);
} else { } else {
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PUMP_UNREACHABLE)); RxBus.INSTANCE.send(new EventDismissNotification(Notification.PUMP_UNREACHABLE));
} }
@ -85,10 +87,10 @@ public class LocalAlertUtils {
* Call only at startup! * Call only at startup!
*/ */
public static void presnoozeAlarms() { public static void presnoozeAlarms() {
if (SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) { if (SP.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) {
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000); SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
} }
if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis()) { if (SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis()) {
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + 5 * 60 * 1000); SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
} }
} }
@ -112,7 +114,7 @@ public class LocalAlertUtils {
if (pump != null && profile != null) { if (pump != null && profile != null) {
long lastConnection = pump.lastDataTime(); long lastConnection = pump.lastDataTime();
long earliestAlarmTime = lastConnection + pumpUnreachableThreshold(); long earliestAlarmTime = lastConnection + pumpUnreachableThreshold();
if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < earliestAlarmTime) { if (SP.getLong("nextPumpDisconnectedAlarm", 0L) < earliestAlarmTime) {
SP.putLong("nextPumpDisconnectedAlarm", earliestAlarmTime); SP.putLong("nextPumpDisconnectedAlarm", earliestAlarmTime);
} }
} }
@ -122,7 +124,7 @@ public class LocalAlertUtils {
BgReading bgReading = DatabaseHelper.lastBg(); BgReading bgReading = DatabaseHelper.lastBg();
if (SP.getBoolean(MainApp.gs(R.string.key_enable_missed_bg_readings_alert), false) if (SP.getBoolean(MainApp.gs(R.string.key_enable_missed_bg_readings_alert), false)
&& bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis() && bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis()
&& SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) { && SP.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) {
Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.gs(R.string.missed_bg_readings), Notification.URGENT); Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.gs(R.string.missed_bg_readings), Notification.URGENT);
n.soundId = R.raw.alarm; n.soundId = R.raw.alarm;
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()); SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold());

View file

@ -89,7 +89,7 @@
android:title="@string/enable_pump_unreachable_alert" /> android:title="@string/enable_pump_unreachable_alert" />
<com.andreabaccega.widget.ValidatingEditTextPreference <com.andreabaccega.widget.ValidatingEditTextPreference
validate:testType="numericRange" validate:testType="numericRange"
validate:minNumber="30" validate:minNumber="20"
validate:maxNumber="300" validate:maxNumber="300"
android:defaultValue="30" android:defaultValue="30"
android:dependency="@string/key_enable_pump_unreachable_alert" android:dependency="@string/key_enable_pump_unreachable_alert"