Improve Pod fault notifications

This commit is contained in:
Bart Sopers 2020-01-26 18:21:31 +01:00
parent 36128c4007
commit e87c568253
2 changed files with 23 additions and 11 deletions

View file

@ -33,7 +33,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
@ -305,16 +304,25 @@ public class OmnipodManager {
.observeOn(Schedulers.io()) //
.doOnComplete(() -> {
synchronized (bolusDataMutex) {
StatusResponse statusResponse = null;
double unitsNotDelivered = 0.0d;
for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) {
try {
// Retrieve a status response in order to update the pod state
statusResponse = getPodStatus();
StatusResponse statusResponse = getPodStatus();
if (statusResponse.getDeliveryStatus().isBolusing()) {
throw new IllegalDeliveryStatusException(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
} else {
break;
}
} catch (PodFaultException ex) {
// Substract units not delivered in case of a Pod failure
unitsNotDelivered = ex.getFaultEvent().getInsulinNotDelivered();
if (isLoggingEnabled()) {
LOG.debug("Caught PodFaultException in bolus completion verification", ex);
}
break;
} catch (Exception ex) {
if (isLoggingEnabled()) {
LOG.debug("Ignoring exception in bolus completion verification", ex);
@ -322,9 +330,6 @@ public class OmnipodManager {
}
}
// Substract units not delivered in case of a Pod failure
double unitsNotDelivered = statusResponse != null && PodProgressStatus.FAULT_EVENT_OCCURRED.equals(statusResponse.getPodProgressStatus()) ? statusResponse.getInsulinNotDelivered() : 0.0D;
if (hasActiveBolus()) {
activeBolusData.bolusCompletionSubject.onSuccess(new BolusDeliveryResult(units - unitsNotDelivered));
activeBolusData = null;

View file

@ -326,6 +326,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (delegate.getPodState().hasFaultEvent()) {
showPodFaultErrorDialog(delegate.getPodState().getFaultEvent().getFaultEventType(), R.raw.urgentalarm);
}
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered);
}
@ -339,7 +343,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult().success(true).enacted(true);
} catch (PodFaultException ex) {
showErrorDialog(createPodFaultErrorMessage(ex.getFaultEvent().getFaultEventType()), null);
showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventType(), null);
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) {
@ -359,9 +363,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
delegate.setTemporaryBasal(PumpType.Insulet_Omnipod.determineCorrectBasalSize(tempBasalPair.getInsulinRate()), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), beepsEnabled, beepsEnabled);
time = System.currentTimeMillis();
} catch (Exception ex) {
if (ex instanceof PodFaultException) {
showErrorDialog(createPodFaultErrorMessage(((PodFaultException) ex).getFaultEvent().getFaultEventType()), R.raw.urgentalarm);
} else if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
addToHistory(time, PodHistoryEntryType.SetTemporaryBasal, "Uncertain failure", false);
return new PumpEnactResult().success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_set_temp_basal_failed_uncertain));
}
@ -617,6 +619,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
comment = getStringResource(R.string.omnipod_driver_error_not_enough_data);
} else if (ex instanceof PodFaultException) {
FaultEventType faultEventType = ((PodFaultException) ex).getFaultEvent().getFaultEventType();
showPodFaultErrorDialog(faultEventType, R.raw.urgentalarm);
comment = createPodFaultErrorMessage(faultEventType);
} else if (ex instanceof PodReturnedErrorResponseException) {
comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response);
@ -648,6 +651,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
RxBus.INSTANCE.send(event);
}
private void showPodFaultErrorDialog(FaultEventType faultEventType, Integer sound) {
showErrorDialog(createPodFaultErrorMessage(faultEventType), sound);
}
private void showErrorDialog(String message, Integer sound) {
Intent intent = new Intent(MainApp.instance(), ErrorHelperActivity.class);
intent.putExtra("soundid", sound == null ? 0 : sound);