Pod alert improvements: always show notification and always upload to NS

This commit is contained in:
Bart Sopers 2020-11-13 13:16:19 +01:00
parent a6f5bcdfa6
commit f5fac5862d
6 changed files with 98 additions and 18 deletions

View file

@ -53,6 +53,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
@ -79,6 +80,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSe
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.EventOmnipodActiveAlertsChanged;
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;
@ -139,6 +141,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private final List<CustomAction> customActions = Collections.singletonList(new CustomAction(
R.string.omnipod_custom_action_reset_rileylink, OmnipodCustomActionType.RESET_RILEY_LINK_CONFIGURATION, true));
private final CompositeDisposable disposables = new CompositeDisposable();
private final NSUpload nsUpload;
// variables for handling statuses and history
private boolean firstRun = true;
@ -173,7 +176,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
AapsOmnipodUtil aapsOmnipodUtil,
RileyLinkUtil rileyLinkUtil,
OmnipodAlertUtil omnipodAlertUtil,
ProfileFunction profileFunction
ProfileFunction profileFunction,
NSUpload nsUpload
) {
super(new PluginDescription() //
.mainType(PluginType.PUMP) //
@ -199,6 +203,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
this.rileyLinkUtil = rileyLinkUtil;
this.omnipodAlertUtil = omnipodAlertUtil;
this.profileFunction = profileFunction;
this.nsUpload = nsUpload;
pumpDescription = new PumpDescription(pumpType);
@ -245,23 +250,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null);
}
if (podStateManager.hasPodState()) {
if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead()) {
AlertSet activeAlerts = podStateManager.getActiveAlerts();
if (activeAlerts != null) {
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));
}
}
}
});
}
if (activeAlerts != null && activeAlerts.size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
queueAcknowledgeAlertsCommand();
}
}
@ -305,6 +298,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
.observeOn(Schedulers.io())
.subscribe(event -> updateAapsTbr(), fabricPrivacy::logException)
);
disposables.add(rxBus
.toObservable(EventOmnipodActiveAlertsChanged.class)
.observeOn(Schedulers.io())
.subscribe(event -> handleActivePodAlerts(), fabricPrivacy::logException)
);
disposables.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
@ -372,6 +370,23 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
}
private void handleActivePodAlerts() {
if (podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead()) {
AlertSet activeAlerts = podStateManager.getActiveAlerts();
if (activeAlerts != null && activeAlerts.size() > 0) {
String alerts = TextUtils.join(", ", aapsOmnipodUtil.getTranslatedActiveAlerts(podStateManager));
String notificationText = resourceHelper.gq(R.plurals.omnipod_pod_alerts, activeAlerts.size(), alerts);
Notification notification = new Notification(Notification.OMNIPOD_POD_ALERTS, notificationText, Notification.URGENT);
rxBus.send(new EventNewNotification(notification));
nsUpload.uploadError(notificationText);
if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
queueAcknowledgeAlertsCommand();
}
}
}
}
@Override
protected void onStop() {
super.onStop();
@ -384,6 +399,16 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
disposables.clear();
}
private void queueAcknowledgeAlertsCommand() {
getCommandQueue().customCommand(new CommandAcknowledgeAlerts(), new Callback() {
@Override public void run() {
if (result != null) {
aapsLogger.debug(LTag.PUMP, "Acknowledge alerts result: {} ({})", result.success, result.comment);
}
}
});
}
private void doPodCheck() {
if (System.currentTimeMillis() > this.nextPodCheck) {
if (!podStateManager.isPodRunning()) {

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.definition;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class AlertSet {
private final List<AlertSlot> alertSlots;
@ -39,6 +40,17 @@ public class AlertSet {
return value;
}
@Override public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AlertSet alertSet = (AlertSet) o;
return alertSlots.equals(alertSet.alertSlots);
}
@Override public int hashCode() {
return Objects.hash(alertSlots);
}
@Override
public String toString() {
return "AlertSet{" +

View file

@ -537,7 +537,10 @@ public abstract class PodStateManager {
podState.setActivatedAt(activatedAtCalculated);
}
podState.setSuspended(status.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
podState.setActiveAlerts(status.getUnacknowledgedAlerts());
if (!Objects.equals(status.getUnacknowledgedAlerts(), podState.getActiveAlerts())) {
podState.setActiveAlerts(status.getUnacknowledgedAlerts());
onActiveAlertsChanged();
}
podState.setLastDeliveryStatus(status.getDeliveryStatus());
podState.setReservoirLevel(status.getReservoirLevel());
podState.setTotalTicksDelivered(status.getTicksDelivered());
@ -567,6 +570,11 @@ public abstract class PodStateManager {
// Can be overridden in subclasses
}
protected void onActiveAlertsChanged() {
// Deliberately left empty
// Can be overridden in subclasses
}
private void setAndStore(Runnable runnable) {
setSafe(runnable);
storePodState();

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.plugins.pump.omnipod.event
import info.nightscout.androidaps.events.Event
/**
* Created by andy on 04.06.2018.
*/
class EventOmnipodActiveAlertsChanged : Event()

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStorageKeys;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodActiveAlertsChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -35,4 +36,8 @@ public class AapsPodStateManager extends PodStateManager {
@Override protected void onTbrChanged() {
rxBus.send(new EventOmnipodTbrChanged());
}
@Override protected void onActiveAlertsChanged() {
rxBus.send(new EventOmnipodActiveAlertsChanged());
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.definition;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class AlertSetTest {
@Test
public void testEquality() {
AlertSet set1 = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT1));
AlertSet set2 = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT1));
AlertSet set3 = new AlertSet(Collections.singletonList(AlertSlot.SLOT1));
assertEquals(set1, set2);
assertNotEquals(set1, set3);
assertNotEquals(set2, set3);
}
}