Merge pull request #39 from AAPS-Omnipod/omnipod_eros_dev_automatically_ack_pod_alerts

Add option to automatically acknowledge Pod alerts
This commit is contained in:
bartsopers 2020-11-12 20:11:26 +01:00 committed by GitHub
commit 863f14f60f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 1 deletions

View file

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

View file

@ -9,6 +9,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.SystemClock;
import android.text.TextUtils;
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.definition.ActivationProgress;
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.manager.PodStateManager;
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.EventOmnipodTbrChanged;
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.CommandUpdateAlertConfiguration;
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.util.AapsOmnipodUtil;
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.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
@ -241,6 +245,22 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
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();
loopHandler.postDelayed(this, STATUS_CHECK_INTERVAL_MILLIS);
@ -294,7 +314,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_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_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();
} else if (event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_enabled) ||
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_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 AUTOMATICALLY_ACKNOWLEDGE_ALERTS_ENABLED = R.string.key_omnipod_automatically_acknowledge_alerts_enabled;
}
public static class Statistics {

View file

@ -113,6 +113,7 @@ public class AapsOmnipodManager {
private boolean notificationUncertainTbrSoundEnabled;
private boolean notificationUncertainSmbSoundEnabled;
private boolean notificationUncertainBolusSoundEnabled;
private boolean automaticallyAcknowledgeAlertsEnabled;
@Inject
public AapsOmnipodManager(OmnipodRileyLinkCommunicationManager communicationService,
@ -158,6 +159,7 @@ public class AapsOmnipodManager {
notificationUncertainTbrSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_TBR_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);
automaticallyAcknowledgeAlertsEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.AUTOMATICALLY_ACKNOWLEDGE_ALERTS_ENABLED, false);
}
public PumpEnactResult initializePod() {
@ -627,6 +629,10 @@ public class AapsOmnipodManager {
return notificationUncertainBolusSoundEnabled;
}
public boolean isAutomaticallyAcknowledgeAlertsEnabled() {
return automaticallyAcknowledgeAlertsEnabled;
}
public void addBolusToHistory(DetailedBolusInfo originalDetailedBolusInfo) {
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_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_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_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>
@ -88,6 +89,7 @@
<string name="omnipod_warning">Warning</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_pod_pod_alert">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_crc_mismatch">Communication failed: message integrity verification failed</string>
@ -253,6 +255,7 @@
<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_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">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
@ -265,5 +268,9 @@
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item>
</plurals>
<plurals name="omnipod_pod_alerts">
<item quantity="one">Pod alert: %1$s</item>
<item quantity="other">Pod alerts: %1$s</item>
</plurals>
</resources>

View file

@ -72,6 +72,11 @@
validate:minNumber="5"
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 android:title="@string/omnipod_preference_category_notifications">