From f6a82e01d70a95364316a40702753ddca792726f Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sat, 14 Nov 2020 10:58:02 +0100 Subject: [PATCH] Always create NS announcements for Pod faults & some cleanup --- .../pump/omnipod/OmnipodPumpPlugin.java | 40 +++++++++++-------- .../driver/manager/PodStateManager.java | 19 +++++---- .../event/EventOmnipodFaultEventChanged.kt | 8 ++++ .../omnipod/manager/AapsPodStateManager.java | 5 +++ .../omnipod/ui/OmnipodOverviewFragment.kt | 2 +- omnipod/src/main/res/values/strings.xml | 2 +- 6 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodFaultEventChanged.kt diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 45730ab776..06b7c963a5 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -79,6 +79,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSe 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.EventOmnipodFaultEventChanged; 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; @@ -248,12 +249,9 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null); } - if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead()) { - AlertSet activeAlerts = podStateManager.getActiveAlerts(); - - if (activeAlerts != null && activeAlerts.size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) { - queueAcknowledgeAlertsCommand(); - } + if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead() && + podStateManager.getActiveAlerts().size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) { + queueAcknowledgeAlertsCommand(); } doPodCheck(); @@ -294,6 +292,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, .observeOn(Schedulers.io()) .subscribe(event -> handleActivePodAlerts(), fabricPrivacy::logException) ); + disposables.add(rxBus + .toObservable(EventOmnipodFaultEventChanged.class) + .observeOn(Schedulers.io()) + .subscribe(event -> handlePodFaultEvent(), fabricPrivacy::logException) + ); disposables.add(rxBus .toObservable(EventPreferenceChange.class) .observeOn(Schedulers.io()) @@ -364,7 +367,7 @@ 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) { + if (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); @@ -378,6 +381,13 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, } } + private void handlePodFaultEvent() { + if (podStateManager.isPodFaulted()) { + String notificationText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, podStateManager.getFaultEventCode().getValue(), podStateManager.getFaultEventCode().name()); + nsUpload.uploadError(notificationText); + } + } + @Override protected void onStop() { super.onStop(); @@ -586,6 +596,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, // if enforceNew is true, current temp basal is cancelled and new TBR set (duration is prolonged), // if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed @Override + @NonNull public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes); @@ -621,6 +632,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, } @Override + @NonNull public PumpEnactResult cancelTempBasal(boolean enforceNew) { TemporaryBasal tbrCurrent = readTBR(); @@ -689,7 +701,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return pump; } - @Override public ManufacturerType manufacturer() { + @Override @NonNull public ManufacturerType manufacturer() { return pumpType.getManufacturer(); } @@ -747,14 +759,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, public void executeCustomAction(CustomActionType customActionType) { OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType; - switch (mcat) { - case RESET_RILEY_LINK_CONFIGURATION: - serviceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector())); - break; - - default: - aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + mcat); - break; + if (mcat == OmnipodCustomActionType.RESET_RILEY_LINK_CONFIGURATION) { + serviceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector())); + } else { + aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + mcat); } } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java index 4d20a87695..b482cc3a23 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java @@ -238,15 +238,6 @@ public abstract class PodStateManager { return getSafe(() -> podState.getLastUpdatedFromResponse()); } - /** - * @return true if the Pod State contains a fault event. Is the Pod state does not contain - * a fault event, this does NOT necessarily mean that the Pod is not faulted. For a reliable - * indication on whether or not the pod is faulted, see {@link #isPodFaulted() isPodFaulted()} - */ - public final boolean isFaulted() { - return podState != null && podState.getFaultEventCode() != null; - } - public final FaultEventCode getFaultEventCode() { return getSafe(() -> podState.getFaultEventCode()); } @@ -559,7 +550,10 @@ public abstract class PodStateManager { if (status instanceof PodInfoDetailedStatus) { PodInfoDetailedStatus detailedStatus = (PodInfoDetailedStatus) status; if (detailedStatus.isFaulted()) { - podState.setFaultEventCode(detailedStatus.getFaultEventCode()); + if (!Objects.equals(podState.getFaultEventCode(), detailedStatus.getFaultEventCode())) { + podState.setFaultEventCode(detailedStatus.getFaultEventCode()); + onFaultEventChanged(); + } } } }); @@ -575,6 +569,11 @@ public abstract class PodStateManager { // Can be overridden in subclasses } + protected void onFaultEventChanged() { + // Deliberately left empty + // Can be overridden in subclasses + } + private void setAndStore(Runnable runnable) { setSafe(runnable); storePodState(); diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodFaultEventChanged.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodFaultEventChanged.kt new file mode 100644 index 0000000000..d9d2b1e11d --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodFaultEventChanged.kt @@ -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 EventOmnipodFaultEventChanged : Event() \ No newline at end of file diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsPodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsPodStateManager.java index a325f909af..551206190f 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsPodStateManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsPodStateManager.java @@ -8,6 +8,7 @@ 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.EventOmnipodFaultEventChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged; import info.nightscout.androidaps.utils.sharedPreferences.SP; @@ -40,4 +41,8 @@ public class AapsPodStateManager extends PodStateManager { @Override protected void onActiveAlertsChanged() { rxBus.send(new EventOmnipodActiveAlertsChanged()); } + + @Override protected void onFaultEventChanged() { + rxBus.send(new EventOmnipodFaultEventChanged()); + } } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt index b66c56a880..3fd3b27472 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt @@ -275,7 +275,7 @@ class OmnipodOverviewFragment : DaggerFragment() { }) } - if (podStateManager.isFaulted) { + if (podStateManager.isPodFaulted) { val faultEventCode = podStateManager.faultEventCode errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) } diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index f76a360d67..6cfea07b2b 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -65,7 +65,7 @@ Pod fault Activation time exceeded Inactive - Pod fault: %1$s %2$s + Pod fault: %1$03d %2$s Finish pairing reminder