Always create NS announcements for Pod faults & some cleanup

This commit is contained in:
Bart Sopers 2020-11-14 10:58:02 +01:00
parent 7e8b395ca7
commit f6a82e01d7
6 changed files with 48 additions and 28 deletions

View file

@ -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.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.EventOmnipodActiveAlertsChanged; 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.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;
@ -248,13 +249,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null); getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null);
} }
if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead()) { if (aapsOmnipodManager.isAutomaticallyAcknowledgeAlertsEnabled() && podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead() &&
AlertSet activeAlerts = podStateManager.getActiveAlerts(); podStateManager.getActiveAlerts().size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
if (activeAlerts != null && activeAlerts.size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
queueAcknowledgeAlertsCommand(); queueAcknowledgeAlertsCommand();
} }
}
doPodCheck(); doPodCheck();
@ -294,6 +292,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe(event -> handleActivePodAlerts(), fabricPrivacy::logException) .subscribe(event -> handleActivePodAlerts(), fabricPrivacy::logException)
); );
disposables.add(rxBus
.toObservable(EventOmnipodFaultEventChanged.class)
.observeOn(Schedulers.io())
.subscribe(event -> handlePodFaultEvent(), fabricPrivacy::logException)
);
disposables.add(rxBus disposables.add(rxBus
.toObservable(EventPreferenceChange.class) .toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
@ -364,7 +367,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private void handleActivePodAlerts() { private void handleActivePodAlerts() {
if (podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead()) { if (podStateManager.isPodActivationCompleted() && !podStateManager.isPodDead()) {
AlertSet activeAlerts = podStateManager.getActiveAlerts(); AlertSet activeAlerts = podStateManager.getActiveAlerts();
if (activeAlerts != null && activeAlerts.size() > 0) { if (activeAlerts.size() > 0) {
String alerts = TextUtils.join(", ", aapsOmnipodUtil.getTranslatedActiveAlerts(podStateManager)); String alerts = TextUtils.join(", ", aapsOmnipodUtil.getTranslatedActiveAlerts(podStateManager));
String notificationText = resourceHelper.gq(R.plurals.omnipod_pod_alerts, activeAlerts.size(), alerts); String notificationText = resourceHelper.gq(R.plurals.omnipod_pod_alerts, activeAlerts.size(), alerts);
Notification notification = new Notification(Notification.OMNIPOD_POD_ALERTS, notificationText, Notification.URGENT); 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 @Override
protected void onStop() { protected void onStop() {
super.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 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 // if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@Override @Override
@NonNull
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer
durationInMinutes, Profile profile, boolean enforceNew) { durationInMinutes, Profile profile, boolean enforceNew) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes); aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
@ -621,6 +632,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
} }
@Override @Override
@NonNull
public PumpEnactResult cancelTempBasal(boolean enforceNew) { public PumpEnactResult cancelTempBasal(boolean enforceNew) {
TemporaryBasal tbrCurrent = readTBR(); TemporaryBasal tbrCurrent = readTBR();
@ -689,7 +701,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return pump; return pump;
} }
@Override public ManufacturerType manufacturer() { @Override @NonNull public ManufacturerType manufacturer() {
return pumpType.getManufacturer(); return pumpType.getManufacturer();
} }
@ -747,14 +759,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
public void executeCustomAction(CustomActionType customActionType) { public void executeCustomAction(CustomActionType customActionType) {
OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType; OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType;
switch (mcat) { if (mcat == OmnipodCustomActionType.RESET_RILEY_LINK_CONFIGURATION) {
case RESET_RILEY_LINK_CONFIGURATION:
serviceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector())); serviceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector()));
break; } else {
default:
aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + mcat); aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + mcat);
break;
} }
} }

View file

@ -238,15 +238,6 @@ public abstract class PodStateManager {
return getSafe(() -> podState.getLastUpdatedFromResponse()); 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() { public final FaultEventCode getFaultEventCode() {
return getSafe(() -> podState.getFaultEventCode()); return getSafe(() -> podState.getFaultEventCode());
} }
@ -559,7 +550,10 @@ public abstract class PodStateManager {
if (status instanceof PodInfoDetailedStatus) { if (status instanceof PodInfoDetailedStatus) {
PodInfoDetailedStatus detailedStatus = (PodInfoDetailedStatus) status; PodInfoDetailedStatus detailedStatus = (PodInfoDetailedStatus) status;
if (detailedStatus.isFaulted()) { if (detailedStatus.isFaulted()) {
if (!Objects.equals(podState.getFaultEventCode(), detailedStatus.getFaultEventCode())) {
podState.setFaultEventCode(detailedStatus.getFaultEventCode()); podState.setFaultEventCode(detailedStatus.getFaultEventCode());
onFaultEventChanged();
}
} }
} }
}); });
@ -575,6 +569,11 @@ public abstract class PodStateManager {
// Can be overridden in subclasses // Can be overridden in subclasses
} }
protected void onFaultEventChanged() {
// Deliberately left empty
// Can be overridden in subclasses
}
private void setAndStore(Runnable runnable) { private void setAndStore(Runnable runnable) {
setSafe(runnable); setSafe(runnable);
storePodState(); 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 EventOmnipodFaultEventChanged : Event()

View file

@ -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.definition.OmnipodStorageKeys;
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.event.EventOmnipodActiveAlertsChanged; 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.plugins.pump.omnipod.event.EventOmnipodTbrChanged;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -40,4 +41,8 @@ public class AapsPodStateManager extends PodStateManager {
@Override protected void onActiveAlertsChanged() { @Override protected void onActiveAlertsChanged() {
rxBus.send(new EventOmnipodActiveAlertsChanged()); rxBus.send(new EventOmnipodActiveAlertsChanged());
} }
@Override protected void onFaultEventChanged() {
rxBus.send(new EventOmnipodFaultEventChanged());
}
} }

View file

@ -275,7 +275,7 @@ class OmnipodOverviewFragment : DaggerFragment() {
}) })
} }
if (podStateManager.isFaulted) { if (podStateManager.isPodFaulted) {
val faultEventCode = podStateManager.faultEventCode val faultEventCode = podStateManager.faultEventCode
errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
} }

View file

@ -65,7 +65,7 @@
<string name="omnipod_pod_status_pod_fault">Pod fault</string> <string name="omnipod_pod_status_pod_fault">Pod fault</string>
<string name="omnipod_pod_status_activation_time_exceeded">Activation time exceeded</string> <string name="omnipod_pod_status_activation_time_exceeded">Activation time exceeded</string>
<string name="omnipod_pod_status_inactive">Inactive</string> <string name="omnipod_pod_status_inactive">Inactive</string>
<string name="omnipod_pod_status_pod_fault_description">Pod fault: %1$s %2$s</string> <string name="omnipod_pod_status_pod_fault_description">Pod fault: %1$03d %2$s</string>
<!-- Omnipod - Alerts --> <!-- Omnipod - Alerts -->
<string name="omnipod_alert_finish_pairing_reminder">Finish pairing reminder</string> <string name="omnipod_alert_finish_pairing_reminder">Finish pairing reminder</string>