Add optional to automatically acknowledge Pod alerts and show a notification instead

This commit is contained in:
Bart Sopers 2020-11-12 18:56:32 +01:00
parent 642a7c8e3b
commit 003d507cf8
6 changed files with 46 additions and 3 deletions

View file

@ -73,6 +73,7 @@ public class Notification {
public static final int CARBS_REQUIRED = 60; public static final int CARBS_REQUIRED = 60;
public static final int OMNIPOD_POD_SUSPENDED = 61; public static final int OMNIPOD_POD_SUSPENDED = 61;
public static final int OMNIPOD_POD_ALERTS_UPDATED = 62; public static final int OMNIPOD_POD_ALERTS_UPDATED = 62;
public static final int OMNIPOD_POD_ALERTS = 63;
public static final int IMPORTANCE_HIGH = 2; public static final int IMPORTANCE_HIGH = 2;

View file

@ -9,6 +9,7 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -74,12 +75,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.acti
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoRecentPulseLog;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertConfiguration;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil; import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandAcknowledgeAlerts;
import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandHandleTimeChange; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandHandleTimeChange;
import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandUpdateAlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandUpdateAlertConfiguration;
import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.OmnipodCustomCommand; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.OmnipodCustomCommand;
@ -88,6 +91,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.service.RileyLi
import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodOverviewFragment; import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodOverviewFragment;
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodAlertUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodAlertUtil;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.CustomCommand; import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DecimalFormatter;
@ -241,11 +245,29 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null); getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null);
} }
AlertSet activeAlerts = podStateManager.getActiveAlerts();
if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && activeAlerts.size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
String alerts = TextUtils.join(", ", aapsOmnipodUtil.getTranslatedActiveAlerts(podStateManager));
getCommandQueue().customCommand(new CommandAcknowledgeAlerts(), new Callback() {
@Override public void run() {
if (result != null) {
aapsLogger.debug(LTag.PUMP, "Acknowledge alerts result: {} ({})", result.success, result.comment);
if (result.success) {
Notification notification = new Notification(Notification.OMNIPOD_POD_ALERTS, resourceHelper.gq(R.plurals.omnipod_pod_alerts, activeAlerts.size(), alerts), Notification.URGENT);
rxBus.send(new EventNewNotification(notification));
}
}
}
});
}
doPodCheck(); doPodCheck();
loopHandler.postDelayed(this, STATUS_CHECK_INTERVAL_MILLIS); loopHandler.postDelayed(this, STATUS_CHECK_INTERVAL_MILLIS);
} }
}; }
;
} }
@Override @Override
@ -294,7 +316,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
event.isChanged(getResourceHelper(), R.string.key_omnipod_time_change_event_enabled) || event.isChanged(getResourceHelper(), R.string.key_omnipod_time_change_event_enabled) ||
event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_tbr_sound_enabled) || event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_tbr_sound_enabled) ||
event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_smb_sound_enabled) || event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_smb_sound_enabled) ||
event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_bolus_sound_enabled)) { event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_bolus_sound_enabled) ||
event.isChanged(getResourceHelper(), R.string.key_omnipod_automatically_acknowledge_alerts_enabled)) {
aapsOmnipodManager.reloadSettings(); aapsOmnipodManager.reloadSettings();
} else if (event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_enabled) || } else if (event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_enabled) ||
event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_hours_before_shutdown) || event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_hours_before_shutdown) ||

View file

@ -20,6 +20,7 @@ public class OmnipodStorageKeys {
public static final int NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED = R.string.key_omnipod_notification_uncertain_tbr_sound_enabled; public static final int NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED = R.string.key_omnipod_notification_uncertain_tbr_sound_enabled;
public static final int NOTIFICATION_UNCERTAIN_SMB_SOUND_ENABLED = R.string.key_omnipod_notification_uncertain_smb_sound_enabled; public static final int NOTIFICATION_UNCERTAIN_SMB_SOUND_ENABLED = R.string.key_omnipod_notification_uncertain_smb_sound_enabled;
public static final int NOTIFICATION_UNCERTAIN_BOLUS_SOUND_ENABLED = R.string.key_omnipod_notification_uncertain_bolus_sound_enabled; public static final int NOTIFICATION_UNCERTAIN_BOLUS_SOUND_ENABLED = R.string.key_omnipod_notification_uncertain_bolus_sound_enabled;
public static final int AUTOMATICALLY_ACKNOWLEDGE_ALERTS_ENABLED = R.string.key_omnipod_automatically_acknowledge_alerts_enabled;
} }
public static class Statistics { public static class Statistics {

View file

@ -113,6 +113,7 @@ public class AapsOmnipodManager {
private boolean notificationUncertainTbrSoundEnabled; private boolean notificationUncertainTbrSoundEnabled;
private boolean notificationUncertainSmbSoundEnabled; private boolean notificationUncertainSmbSoundEnabled;
private boolean notificationUncertainBolusSoundEnabled; private boolean notificationUncertainBolusSoundEnabled;
private boolean automaticallyAcknowledgeAlertsEnabled;
@Inject @Inject
public AapsOmnipodManager(OmnipodRileyLinkCommunicationManager communicationService, public AapsOmnipodManager(OmnipodRileyLinkCommunicationManager communicationService,
@ -158,6 +159,7 @@ public class AapsOmnipodManager {
notificationUncertainTbrSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED, true); notificationUncertainTbrSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED, true);
notificationUncertainSmbSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_SMB_SOUND_ENABLED, true); notificationUncertainSmbSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_SMB_SOUND_ENABLED, true);
notificationUncertainBolusSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_BOLUS_SOUND_ENABLED, true); notificationUncertainBolusSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_BOLUS_SOUND_ENABLED, true);
automaticallyAcknowledgeAlertsEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.AUTOMATICALLY_ACKNOWLEDGE_ALERTS_ENABLED, false);
} }
public PumpEnactResult initializePod() { public PumpEnactResult initializePod() {
@ -627,6 +629,10 @@ public class AapsOmnipodManager {
return notificationUncertainBolusSoundEnabled; return notificationUncertainBolusSoundEnabled;
} }
public boolean isAutomaticallyAcknowledgeAlertsEnabled() {
return automaticallyAcknowledgeAlertsEnabled;
}
public void addBolusToHistory(DetailedBolusInfo originalDetailedBolusInfo) { public void addBolusToHistory(DetailedBolusInfo originalDetailedBolusInfo) {
DetailedBolusInfo detailedBolusInfo = originalDetailedBolusInfo.copy(); DetailedBolusInfo detailedBolusInfo = originalDetailedBolusInfo.copy();

View file

@ -15,6 +15,7 @@
<string name="key_omnipod_expiration_reminder_hours_before_shutdown" translatable="false">AAPS.Omnipod.expiration_reminder_hours_before_shutdown</string> <string name="key_omnipod_expiration_reminder_hours_before_shutdown" translatable="false">AAPS.Omnipod.expiration_reminder_hours_before_shutdown</string>
<string name="key_omnipod_low_reservoir_alert_enabled" translatable="false">AAPS.Omnipod.low_reservoir_alert_enabled</string> <string name="key_omnipod_low_reservoir_alert_enabled" translatable="false">AAPS.Omnipod.low_reservoir_alert_enabled</string>
<string name="key_omnipod_low_reservoir_alert_units" translatable="false">AAPS.Omnipod.low_reservoir_alert_units</string> <string name="key_omnipod_low_reservoir_alert_units" translatable="false">AAPS.Omnipod.low_reservoir_alert_units</string>
<string name="key_omnipod_automatically_acknowledge_alerts_enabled" translatable="false">AAPS.Omnipod.automatically_acknowledge_alerts_enabled</string>
<string name="key_omnipod_notification_uncertain_tbr_sound_enabled" translatable="false">AAPS.Omnipod.notification_uncertain_tbr_sound_enabled</string> <string name="key_omnipod_notification_uncertain_tbr_sound_enabled" translatable="false">AAPS.Omnipod.notification_uncertain_tbr_sound_enabled</string>
<string name="key_omnipod_notification_uncertain_smb_sound_enabled" translatable="false">AAPS.Omnipod.notification_uncertain_smb_sound_enabled</string> <string name="key_omnipod_notification_uncertain_smb_sound_enabled" translatable="false">AAPS.Omnipod.notification_uncertain_smb_sound_enabled</string>
<string name="key_omnipod_notification_uncertain_bolus_sound_enabled" translatable="false">AAPS.Omnipod.notification_uncertain_bolus_sound_enabled</string> <string name="key_omnipod_notification_uncertain_bolus_sound_enabled" translatable="false">AAPS.Omnipod.notification_uncertain_bolus_sound_enabled</string>
@ -88,6 +89,7 @@
<string name="omnipod_warning">Warning</string> <string name="omnipod_warning">Warning</string>
<string name="omnipod_error_rileylink_address_invalid">RileyLink address invalid.</string> <string name="omnipod_error_rileylink_address_invalid">RileyLink address invalid.</string>
<string name="omnipod_error_operation_not_possible_no_configuration">Operation is not possible.\n\nYou need to configure Omnipod first, before you can use this operation.</string> <string name="omnipod_error_operation_not_possible_no_configuration">Operation is not possible.\n\nYou need to configure Omnipod first, before you can use this operation.</string>
<string name="omnipod_error_pod_pod_alert">No active Pod</string>
<string name="omnipod_error_pod_not_attached">No active Pod</string> <string name="omnipod_error_pod_not_attached">No active Pod</string>
<string name="omnipod_error_unexpected_exception">An unexpected error occurred. Please report! (%1$s: %2$s).</string> <string name="omnipod_error_unexpected_exception">An unexpected error occurred. Please report! (%1$s: %2$s).</string>
<string name="omnipod_error_crc_mismatch">Communication failed: message integrity verification failed</string> <string name="omnipod_error_crc_mismatch">Communication failed: message integrity verification failed</string>
@ -154,7 +156,7 @@
<string name="omnipod_cmd_set_basal_schedule">Set basal schedule</string> <string name="omnipod_cmd_set_basal_schedule">Set basal schedule</string>
<string name="omnipod_cmd_get_pod_status">Get Pod status</string> <string name="omnipod_cmd_get_pod_status">Get Pod status</string>
<string name="omnipod_cmd_get_pod_info">Get Pod info</string> <string name="omnipod_cmd_get_pod_info">Get Pod info</string>
<string name="omnipod_cmd_set_time">Set time</string> <string name="omnipod_cmd_set_time">Se\t time</string>
<string name="omnipod_cmd_configure_alerts">Configure alerts</string> <string name="omnipod_cmd_configure_alerts">Configure alerts</string>
<string name="omnipod_cmd_acknowledge_alerts">Acknowledge alerts</string> <string name="omnipod_cmd_acknowledge_alerts">Acknowledge alerts</string>
<string name="omnipod_cmd_suspend_delivery">Suspend delivery</string> <string name="omnipod_cmd_suspend_delivery">Suspend delivery</string>
@ -253,6 +255,7 @@
<string name="omnipod_less_than_a_minute_ago">Less than a minute ago</string> <string name="omnipod_less_than_a_minute_ago">Less than a minute ago</string>
<string name="omnipod_composite_time">%1$s and %2$s</string> <string name="omnipod_composite_time">%1$s and %2$s</string>
<string name="omnipod_time_ago">%1$s ago</string> <string name="omnipod_time_ago">%1$s ago</string>
<string name="omnipod_config_automatically_acknowledge_alerts">Automatically acknowledge Pod alerts (uses notifications to show alerts)</string>
<plurals name="omnipod_minutes"> <plurals name="omnipod_minutes">
<item quantity="one">%1$d minute</item> <item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item> <item quantity="other">%1$d minutes</item>
@ -265,5 +268,9 @@
<item quantity="one">%1$d day</item> <item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item> <item quantity="other">%1$d days</item>
</plurals> </plurals>
<plurals name="omnipod_pod_alerts">
<item quantity="one">Pod alert: %1$</item>
<item quantity="other">Pod alerts: %1$s</item>
</plurals>
</resources> </resources>

View file

@ -72,6 +72,11 @@
validate:minNumber="5" validate:minNumber="5"
validate:testType="numericRange" /> validate:testType="numericRange" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_omnipod_automatically_acknowledge_alerts_enabled"
android:title="@string/omnipod_config_automatically_acknowledge_alerts" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/omnipod_preference_category_notifications"> <PreferenceCategory android:title="@string/omnipod_preference_category_notifications">