- Allow resetting pairingParameters in PodStateManager if the setup state is ADDRESS_ASSIGNED

- Improve pod status screen
- Improve event dispatching in AapsPodStateManager (send less events)
- Add more FIXMEs and TODOs
This commit is contained in:
Bart Sopers 2020-08-10 20:15:52 +02:00
parent a0ca8cf9cc
commit 341474295f
11 changed files with 73 additions and 79 deletions

View file

@ -45,6 +45,7 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.omnipod_fragment.*
import org.apache.commons.lang3.StringUtils
import javax.inject.Inject
class OmnipodFragment : DaggerFragment() {
@ -87,11 +88,6 @@ class OmnipodFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
omnipod_rl_status.text = resourceHelper.gs(RileyLinkServiceState.NotStarted.getResourceId(RileyLinkTargetDevice.Omnipod))
omnipod_pod_status.setTextColor(Color.WHITE)
omnipod_pod_status.text = "{fa-bed}"
omnipod_pod_mgmt.setOnClickListener {
if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
startActivity(Intent(context, PodManagementActivity::class.java))
@ -147,10 +143,6 @@ class OmnipodFragment : DaggerFragment() {
}
omnipod_lastconnection.setTextColor(Color.WHITE)
setVisibilityOfPodDebugButton()
updateGUI()
}
override fun onResume() {
@ -181,6 +173,7 @@ class OmnipodFragment : DaggerFragment() {
.subscribe({
setVisibilityOfPodDebugButton()
}, { fabricPrivacy.logException(it) })
updateGUI()
}
fun setVisibilityOfPodDebugButton() {
@ -212,12 +205,10 @@ class OmnipodFragment : DaggerFragment() {
@Synchronized
private fun setDeviceStatus() {
//val omnipodPumpStatus: OmnipodPumpStatus = OmnipodUtil.getPumpStatus()
// omnipodPumpStatus.rileyLinkServiceState = checkStatusSet(omnipodPumpStatus.rileyLinkServiceState,
// RileyLinkUtil.getServiceState()) as RileyLinkServiceState?
aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus)
val errors = ArrayList<String>();
val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState
val resourceId = rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod)
@ -228,22 +219,18 @@ class OmnipodFragment : DaggerFragment() {
rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.Omnipod))
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
}
omnipod_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
omnipod_rl_status.setTextColor(if (rileyLinkServiceState.isError || rileyLinkError != null) Color.RED else Color.WHITE)
// omnipodPumpStatus.rileyLinkError = checkStatusSet(omnipodPumpStatus.rileyLinkError,
// RileyLinkUtil.getError()) as RileyLinkError?
omnipod_errors.text =
rileyLinkError?.let {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod))
} ?: "-"
val driverState = omnipodUtil.getDriverState();
aapsLogger.info(LTag.PUMP, "getDriverState: [driverState={}]", driverState)
if (rileyLinkError != null) {
errors.add(resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.Omnipod)))
}
val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo
if (rileyLinkErrorInfo != null) {
errors.add(rileyLinkErrorInfo)
}
if (!podStateManager.hasState() || !podStateManager.isPaired) {
if (podStateManager.hasState()) {
@ -262,7 +249,6 @@ class OmnipodFragment : DaggerFragment() {
}
omnipodPumpStatus.podNumber == null
} else {
omnipodPumpStatus.podLotNumber = "" + podStateManager.lot
omnipod_pod_address.text = podStateManager.address.toString()
omnipod_pod_lot.text = podStateManager.lot.toString()
omnipod_pod_tid.text = podStateManager.tid.toString()
@ -270,24 +256,30 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_expiry.text = podStateManager.expiryDateAsString
omnipodPumpStatus.podNumber = podStateManager.address.toString()
var stateText: String?
val stateText: String
if (podStateManager.hasFaultEvent()) {
val faultEventCode = podStateManager.faultEvent.faultEventCode
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault) + " (" + faultEventCode.value + " " + faultEventCode.name + ")"
} else if (podStateManager.isSetupCompleted) {
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_running)
if (podStateManager.lastDeliveryStatus != null) {
stateText += " (last delivery status: " + podStateManager.lastDeliveryStatus.name + ")"
when {
podStateManager.hasFaultEvent() -> {
val faultEventCode = podStateManager.faultEvent.faultEventCode
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault)
errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
}
podStateManager.isSetupCompleted -> {
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_running, if (podStateManager.lastDeliveryStatus == null) null else podStateManager.lastDeliveryStatus.name)
}
else -> {
stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress, podStateManager.setupProgress.name)
}
} else {
stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress)
stateText += " (setup progress: " + podStateManager.setupProgress.name + ")"
}
omnipod_pod_status.text = stateText
}
omnipod_pod_status.setTextColor(if (podStateManager.hasFaultEvent()) Color.RED else Color.WHITE)
omnipod_errors.text = if (errors.size == 0) "-" else StringUtils.join(errors, System.lineSeparator())
val status = commandQueue.spannedStatus()
if (status.toString() == "") {
omnipod_queue.visibility = View.GONE
@ -397,10 +389,10 @@ class OmnipodFragment : DaggerFragment() {
omnipod_lastconnection.setTextColor(Color.WHITE)
}
omnipod_errors.text = omnipodPumpStatus.errorInfo
updateAcknowledgeAlerts()
setVisibilityOfPodDebugButton()
omnipod_refresh.isEnabled = podStateManager.isPaired
}

View file

@ -605,6 +605,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
}
// FIXME do we actually need this? If a user presses refresh during an action,
// I suppose the GetStatusCommand would just be queued?
private void setRefreshButtonEnabled(boolean enabled) {
rxBus.send(new EventOmnipodRefreshButtonState(enabled));
}

View file

@ -6,8 +6,6 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import net.danlew.android.joda.JodaTimeAndroid;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -79,7 +77,7 @@ public abstract class PodStateManager {
if (!hasState()) {
throw new IllegalStateException("Cannot set pairing parameters: podState is null");
}
if (isPaired()) {
if (isPaired() && getSetupProgress().isAfter(SetupProgress.ADDRESS_ASSIGNED)) {
throw new IllegalStateException("Cannot set pairing parameters: pairing parameters have already been set");
}
if (piVersion == null) {
@ -125,11 +123,11 @@ public abstract class PodStateManager {
}
public final void increaseMessageNumber() {
setAndStore(() -> podState.setMessageNumber((podState.getMessageNumber() + 1) & 0b1111));
setAndStore(() -> podState.setMessageNumber((podState.getMessageNumber() + 1) & 0b1111), false);
}
public final void increasePacketNumber() {
setAndStore(() -> podState.setPacketNumber((podState.getPacketNumber() + 1) & 0b11111));
setAndStore(() -> podState.setPacketNumber((podState.getPacketNumber() + 1) & 0b11111), false);
}
public final synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) {
@ -144,7 +142,7 @@ public abstract class PodStateManager {
int seed = ((sum & 0xFFFF) ^ syncWord);
NonceState nonceState = new NonceState(podState.getLot(), podState.getTid(), (byte) (seed & 0xFF));
setAndStore(() -> podState.setNonceState(nonceState));
setAndStore(() -> podState.setNonceState(nonceState), false);
}
public final synchronized int getCurrentNonce() {
@ -158,7 +156,7 @@ public abstract class PodStateManager {
if (!isPaired()) {
throw new IllegalStateException("Cannot advance to next nonce: Pod is not paired yet");
}
setAndStore(() -> podState.getNonceState().advanceToNextNonce());
setAndStore(() -> podState.getNonceState().advanceToNextNonce(), false);
}
public final DateTime getLastSuccessfulCommunication() {
@ -178,7 +176,7 @@ public abstract class PodStateManager {
}
public final boolean hasFaultEvent() {
return getSafe(() -> podState.getFaultEvent()) != null;
return podState != null && podState.getFaultEvent() != null;
}
public final PodInfoFaultEvent getFaultEvent() {
@ -202,6 +200,9 @@ public abstract class PodStateManager {
}
public final boolean hasActiveAlerts() {
if (podState == null) {
return false;
}
AlertSet activeAlerts = podState.getActiveAlerts();
return activeAlerts != null && activeAlerts.size() > 0;
}
@ -358,12 +359,18 @@ public abstract class PodStateManager {
}
private void setAndStore(Runnable runnable) {
setAndStore(runnable, true);
}
private void setAndStore(Runnable runnable, boolean notifyPodStateChanged) {
if (!hasState()) {
throw new IllegalStateException("Cannot mutate PodState: podState is null");
}
runnable.run();
storePodState();
notifyPodStateChanged();
if (notifyPodStateChanged) {
notifyPodStateChanged();
}
}
private void storePodState() {

View file

@ -11,8 +11,6 @@ import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
@ -27,13 +25,14 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
@Singleton
public class OmnipodPumpStatus extends PumpStatus {
// TODO remove all fields that can also be obtained via PodStateManager
// We can probably get rid of this class altogether
private final ResourceHelper resourceHelper;
private final SP sp;
private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus;
public String errorDescription = null;
public String rileyLinkErrorDescription = null;
public String rileyLinkAddress = null;
public boolean inPreInit = true;
@ -58,7 +57,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public boolean beepSMBEnabled = true;
public boolean beepTBREnabled = true;
public boolean podDebuggingOptionsEnabled = false;
public String podLotNumber = "???";
public boolean timeChangeEventEnabled = true;
public OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@ -77,7 +75,6 @@ public class OmnipodPumpStatus extends PumpStatus {
initSettings();
}
@Override
public void initSettings() {
this.activeProfileName = "";
@ -87,11 +84,10 @@ public class OmnipodPumpStatus extends PumpStatus {
this.pumpType = PumpType.Insulet_Omnipod;
}
// For Omnipod, this method only returns a RileyLink error description
@Override
public String getErrorInfo() {
//verifyConfiguration();
return (this.errorDescription == null) ? "-" : this.errorDescription;
return this.rileyLinkErrorDescription;
}
@ -124,7 +120,7 @@ public class OmnipodPumpStatus extends PumpStatus {
@Override
public String toString() {
return "OmnipodPumpStatus{" +
"errorDescription='" + errorDescription + '\'' +
"rileyLinkErrorDescription='" + rileyLinkErrorDescription + '\'' +
", rileyLinkAddress='" + rileyLinkAddress + '\'' +
", inPreInit=" + inPreInit +
", currentBasal=" + currentBasal +

View file

@ -23,8 +23,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -85,8 +83,6 @@ public class AapsPodStateManager extends PodStateManager {
omnipodPumpStatus.lastBolusAmount = null;
omnipodPumpStatus.reservoirRemainingUnits = 0.0;
omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
sendEvent(new EventOmnipodPumpValuesChanged());
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
} else {
// Update active alerts
@ -97,14 +93,11 @@ public class AapsPodStateManager extends PodStateManager {
if (!omnipodPumpStatus.ackAlertsAvailable || !alertsText.equals(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsAvailable = true;
omnipodPumpStatus.ackAlertsText = TextUtils.join("\n", alerts);
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
}
} else {
if (omnipodPumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsText = null;
omnipodPumpStatus.ackAlertsAvailable = false;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
}
}
@ -119,15 +112,15 @@ public class AapsPodStateManager extends PodStateManager {
omnipodPumpStatus.lastBolusTime = lastBolusStartTime;
omnipodPumpStatus.lastBolusAmount = lastBolusAmount;
omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel();
boolean sendRefreshOverviewEvent = isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType);
omnipodPumpStatus.pumpStatusType = isSuspended() ? PumpStatusType.Suspended : PumpStatusType.Running;
sendEvent(new EventOmnipodPumpValuesChanged());
if (isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
if (sendRefreshOverviewEvent) {
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
}
}
}
rxBus.send(new EventOmnipodDeviceStatusChange(this));
sendEvent(new EventOmnipodPumpValuesChanged());
}
private List<String> getTranslatedActiveAlerts() {

View file

@ -191,6 +191,7 @@ public class OmnipodUITask {
}
// FIXME a lot of this is not needed anymore since introducing PodStateManager
public void postProcess(OmnipodUIPostprocessor postprocessor) {
EventOmnipodDeviceStatusChange statusChange;

View file

@ -5,4 +5,5 @@ import info.nightscout.androidaps.events.Event
/**
* Created by andy on 04.06.2018.
*/
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodAcknowledgeAlertsChanged : Event()

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManage
/**
* Created by andy on 4.8.2019
*/
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodDeviceStatusChange : Event {
var rileyLinkServiceState: RileyLinkServiceState? = null

View file

@ -7,8 +7,6 @@ import android.os.IBinder;
import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime;
import javax.inject.Inject;
import info.nightscout.androidaps.R;
@ -164,17 +162,17 @@ public class RileyLinkOmnipodService extends RileyLinkService {
public boolean verifyConfiguration() {
try {
omnipodPumpStatus.errorDescription = "-";
omnipodPumpStatus.rileyLinkErrorDescription = null;
String rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
if (StringUtils.isEmpty(rileyLinkAddress)) {
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: no address");
omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
return false;
} else {
if (!rileyLinkAddress.matches(omnipodPumpStatus.regexMac)) {
omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress);
} else {
if (!rileyLinkAddress.equals(this.omnipodPumpStatus.rileyLinkAddress)) {
@ -199,7 +197,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
return true;
} catch (Exception ex) {
this.omnipodPumpStatus.errorDescription = ex.getMessage();
this.omnipodPumpStatus.rileyLinkErrorDescription = ex.getMessage();
aapsLogger.error(LTag.PUMPCOMM, "Error on Verification: " + ex.getMessage(), ex);
return false;
}

View file

@ -575,7 +575,7 @@
android:layout_weight="1.5"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/medtronic_errors"
android:text="@string/omnipod_errors"
android:textSize="14sp" />
<TextView

View file

@ -1864,10 +1864,11 @@
<string name="omnipod_pod_address">Pod Address</string>
<string name="omnipod_pod_expiry">Pod Expires</string>
<string name="omnipod_pod_status_no_pod_connected">No Pod connected</string>
<string name="omnipod_pod_setup_in_progress">Pod setup in progress</string>
<string name="omnipod_pod_setup_in_progress">Pod setup in progress (setup progress: %1$s)</string>
<string name="omnipod_pod_status_not_initalized">Pod not initialized</string>
<string name="omnipod_pod_status_pod_fault">!!! Pod Fault</string>
<string name="omnipod_pod_status_pod_running">Pod running</string>
<string name="omnipod_pod_status_pod_fault">Pod Fault</string>
<string name="omnipod_pod_status_pod_fault_description">Pod Fault: %1$s %2$s</string>
<string name="omnipod_pod_status_pod_running">Pod running (last delivery status: %1$s)</string>
<string name="omnipod_pod_active_alerts">Active Pod Alerts</string>
<string name="omnipod_ack_short">Ack Alerts</string>
<string name="omnipod_last_bolus" translatable="false">%1$.2f %2$s (%3$s)</string>
@ -1881,6 +1882,7 @@
<!-- Omnipod - Error -->
<string name="omnipod_error_rileylink_address_invalid">RileyLink Address invalid.</string>
<string name="omnipod_error_operation_not_possible_no_configuration">Operation is not possible.\n\nYou need to configure Omnipod first, before you can use this operation.</string>
<string name="omnipod_error_operation_not_possible_no_profile">Operation is not possible.\n\n You need to wait few minutes, until AAPS tries to set profile for first time.</string>
<string name="omnipod_error_illegal_init_action_type">Illegal PodInitActionType: %1$s</string>
@ -1987,5 +1989,6 @@
<string name="omnipod_pod_lot">LOT</string>
<string name="omnipod_pod_tid">TID</string>
<string name="omnipod_pod_fw_version">PM / PI version</string>
<string name="omnipod_errors">Errors</string>
</resources>