- Fix local alerts

- Remove duplicate RL error from Pod tab
This commit is contained in:
Bart Sopers 2020-08-10 22:27:52 +02:00
parent 906b8c2585
commit a55be8d33f
4 changed files with 25 additions and 9 deletions

View file

@ -33,6 +33,7 @@ public class RileyLinkServiceData {
boolean tuneUpDone = false;
public RileyLinkError rileyLinkError;
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
private long lastServiceStateChange = 0L;
public RileyLinkFirmwareVersion firmwareVersion;
public RileyLinkTargetFrequency rileyLinkTargetFrequency; // TODO this might not be correct place
@ -52,7 +53,8 @@ public class RileyLinkServiceData {
public byte[] pumpIDBytes;
@Inject
public RileyLinkServiceData() {}
public RileyLinkServiceData() {
}
public void setPumpID(String pumpId, byte[] pumpIdBytes) {
this.pumpID = pumpId;
@ -71,17 +73,22 @@ public class RileyLinkServiceData {
workWithServiceState(newState, errorCode, true);
}
public long getLastServiceStateChange() {
return lastServiceStateChange;
}
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
if (set) {
rileyLinkServiceState = newState;
lastServiceStateChange = System.currentTimeMillis();
this.rileyLinkError = errorCode;
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice));
if (activePlugin.getActivePump().manufacturer()== ManufacturerType.Medtronic)
if (activePlugin.getActivePump().manufacturer() == ManufacturerType.Medtronic)
rxBus.send(new EventMedtronicDeviceStatusChange(newState, errorCode));
else {
rxBus.send(new EventOmnipodDeviceStatusChange(newState, errorCode));

View file

@ -224,9 +224,6 @@ class OmnipodFragment : DaggerFragment() {
}
omnipod_rl_status.setTextColor(if (rileyLinkServiceState.isError || rileyLinkError != null) Color.RED else Color.WHITE)
if (rileyLinkError != null) {
errors.add(resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.Omnipod)))
}
val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo
if (rileyLinkErrorInfo != null) {
errors.add(rileyLinkErrorInfo)

View file

@ -995,15 +995,19 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override
public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) {
long rileyLinkInitializationTimeout = 3 * 60 * 1000L; // 3 minutes
if (podStateManager.isSetupCompleted() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
if (podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) {
// We exceeded the alert threshold, and our last connection failed
if ((podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
rileyLinkServiceData.rileyLinkServiceState.isError() ||
// The below clause is a hack for working around the RL service state forever staying in connecting state on startup if the RL is switched off / unreachable
(rileyLinkServiceData.getRileyLinkServiceState().isConnecting() && rileyLinkServiceData.getLastServiceStateChange() + rileyLinkInitializationTimeout < System.currentTimeMillis())) {
// We exceeded the alert threshold, and either our last command failed or we cannot reach the RL
// We should show an alert
return true;
}
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful & the RL is reachable
// This happens when we simply didn't need to send any commands to the pump
}
}

View file

@ -41,7 +41,7 @@ class LocalAlertUtils @Inject constructor(
}
fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) {
val alarmTimeoutExpired = lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis()
val alarmTimeoutExpired = isAlarmTimeoutExpired(lastConnection, pumpUnreachableThreshold())
val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis()
if (Config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true)
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) {
@ -57,6 +57,14 @@ class LocalAlertUtils @Inject constructor(
if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE))
}
private fun isAlarmTimeoutExpired(lastConnection: Long, unreachableThreshold: Long): Boolean {
if (activePlugin.activePump.pumpDescription.hasCustomUnreachableAlertCheck) {
return activePlugin.activePump.isUnreachableAlertTimeoutExceeded(unreachableThreshold)
} else {
return lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis()
}
}
/*Presnoozes the alarms with 5 minutes if no snooze exists.
* Call only at startup!
*/