Improve uncertain TBR detection

This commit is contained in:
Bart Sopers 2020-09-09 19:09:31 +02:00
parent 0b75bbf85f
commit bb7eed1045
4 changed files with 37 additions and 6 deletions

View file

@ -270,10 +270,14 @@ public class OmnipodManager {
throw ex;
}
// verifyDeliveryStatus will throw an exception if verification fails
if (!verifyDeliveryStatus(DeliveryStatus.NORMAL, ex)) {
ex.setCertainFailure(true);
throw ex;
try {
if (!verifyDeliveryStatus(DeliveryStatus.NORMAL, ex)) {
ex.setCertainFailure(true);
throw ex;
}
} catch (DeliveryStatusVerificationFailedException ex2) {
podStateManager.setTempBasalCertain(false);
throw ex2;
}
}
}
@ -321,7 +325,23 @@ public class OmnipodManager {
}
public synchronized void cancelTemporaryBasal(boolean acknowledgementBeep) {
cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep);
try {
cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep);
} catch (OmnipodException ex) {
if (ex.isCertainFailure()) {
throw ex;
}
try {
if (!verifyDeliveryStatus(DeliveryStatus.NORMAL, ex)) {
ex.setCertainFailure(true);
throw ex;
}
} catch (DeliveryStatusVerificationFailedException ex2) {
podStateManager.setTempBasalCertain(false);
throw ex2;
}
}
}
private synchronized StatusResponse cancelDelivery(EnumSet<DeliveryType> deliveryTypes, boolean acknowledgementBeep) {

View file

@ -392,6 +392,10 @@ public abstract class PodStateManager {
return certain == null || certain;
}
public final void setTempBasalCertain(boolean certain) {
setSafe(() -> podState.setTempBasalCertain(certain));
}
public final void setTempBasal(DateTime startTime, Double amount, Duration duration, boolean certain) {
setTempBasal(startTime, amount, duration, certain, true);
}

View file

@ -469,7 +469,13 @@ public class AapsOmnipodManager {
try {
delegate.cancelTemporaryBasal(isTbrBeepsEnabled());
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
String comment;
if (ex instanceof OmnipodException && !((OmnipodException) ex).isCertainFailure()) {
comment = getStringResource(R.string.omnipod_error_cancel_temp_basal_failed_uncertain);
showNotification(comment, Notification.URGENT, R.raw.boluserror);
} else {
comment = handleAndTranslateException(ex);
}
addFailureToHistory(PodHistoryEntryType.CANCEL_TEMPORARY_BASAL, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}

View file

@ -144,6 +144,7 @@
<string name="omnipod_error_set_basal_failed_delivery_might_be_suspended">Setting basal profile failed. Delivery might be suspended! Please manually refresh the Pod status from the Omnipod tab and resume delivery if needed.</string>
<string name="omnipod_error_set_basal_might_have_failed_delivery_might_be_suspended">Setting basal profile might have failed. Delivery might be suspended! Please manually refresh the Pod status from the Omnipod tab and resume delivery if needed.</string>
<string name="omnipod_error_set_basal_failed_delivery_suspended">Setting basal profile failed. Delivery is suspended! Please manually resume delivery from the Omnipod tab.</string>
<string name="omnipod_error_cancel_temp_basal_failed_uncertain">Cancelling temp basal might have failed. Please manually refresh the Pod status from the Omnipod tab.</string>
<string name="omnipod_error_set_temp_basal_failed_old_tbr_might_be_cancelled">Setting temp basal failed. If a temp basal was previously running, it might have been cancelled. Please manually refresh the Pod status from the Omnipod tab.</string>
<string name="omnipod_error_set_temp_basal_failed_old_tbr_cancelled_new_might_have_failed">Setting temp might have basal failed. If a temp basal was previously running, it has been cancelled. Please manually refresh the Pod status from the Omnipod tab.</string>
<string name="omnipod_error_set_time_failed_delivery_might_be_suspended">Setting time might have failed. Delivery might be suspended! Please manually refresh the Pod status from the Omnipod tab and resume delivery if needed.</string>