Remove SetupProgress enum in favor of PodProgressStatus, which comes directly from the Pod

This commit is contained in:
Bart Sopers 2020-08-15 11:23:45 +02:00
parent c56bc5ae61
commit 59ad718969
21 changed files with 205 additions and 259 deletions

View file

@ -13,22 +13,17 @@ import java.util.Locale;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
@ -172,7 +167,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
// TODO needs improvement
if (omnipodPumpStatus != null) {
PodStateManager podStateManager = ((OmnipodPumpPlugin) pumpPlugin).getPodStateManager();
if (podStateManager.isPaired()) {
if (podStateManager.isPodInitialized()) {
this.serialNumber.setText(String.valueOf(podStateManager.getLot()));
this.connectedDevice.setText(omnipodPumpStatus.pumpType == PumpType.Insulet_Omnipod ? "Eros Pod" : "Dash Pod");
} else {

View file

@ -226,8 +226,8 @@ class OmnipodFragment : DaggerFragment() {
errors.add(rileyLinkErrorInfo)
}
if (!podStateManager.hasState() || !podStateManager.isPaired) {
if (podStateManager.hasState()) {
if (!podStateManager.hasPodState() || !podStateManager.isPodInitialized) {
if (podStateManager.hasPodState()) {
omnipod_pod_address.text = podStateManager.address.toString()
} else {
omnipod_pod_address.text = "-"
@ -236,7 +236,7 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_tid.text = "-"
omnipod_pod_fw_version.text = "-"
omnipod_pod_expiry.text = "-"
if (podStateManager.hasState()) {
if (podStateManager.hasPodState()) {
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_not_initalized)
} else {
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_no_pod_connected)
@ -251,18 +251,18 @@ class OmnipodFragment : DaggerFragment() {
val stateText: String
when {
podStateManager.hasFaultEvent() -> {
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 -> {
podStateManager.isPodRunning -> {
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, podStateManager.podProgressStatus.name)
}
}
@ -285,7 +285,7 @@ class OmnipodFragment : DaggerFragment() {
fun updateGUI() {
setDeviceStatus()
if (podStateManager.isSetupCompleted) {
if (podStateManager.isPodRunning) {
updateLastConnection()
// last bolus
@ -323,11 +323,11 @@ class OmnipodFragment : DaggerFragment() {
setVisibilityOfPodDebugButton()
omnipod_refresh.isEnabled = podStateManager.isPaired
omnipod_refresh.isEnabled = podStateManager.isPodInitialized
}
private fun updateLastConnection() {
if (podStateManager.isSetupCompleted && podStateManager.lastSuccessfulCommunication != null) { // Null check for backwards compatibility
if (podStateManager.isPodRunning && podStateManager.lastSuccessfulCommunication != null) { // Null check for backwards compatibility
omnipod_lastconnection.text = readableDuration(podStateManager.lastSuccessfulCommunication)
if (omnipodPumpPlugin.isUnreachableAlertTimeoutExceeded(localAlertUtils.pumpUnreachableThreshold())) {
omnipod_lastconnection.setTextColor(Color.RED)
@ -336,7 +336,7 @@ class OmnipodFragment : DaggerFragment() {
}
} else {
omnipod_lastconnection.setTextColor(Color.WHITE)
if (podStateManager.hasState() && podStateManager.lastSuccessfulCommunication != null) {
if (podStateManager.hasPodState() && podStateManager.lastSuccessfulCommunication != null) {
omnipod_lastconnection.text = readableDuration(podStateManager.lastSuccessfulCommunication)
} else {
omnipod_lastconnection.text = "-"
@ -369,7 +369,7 @@ class OmnipodFragment : DaggerFragment() {
}
private fun updateAcknowledgeAlerts() {
if (podStateManager.hasState() && podStateManager.hasActiveAlerts()) {
if (podStateManager.hasPodState() && podStateManager.hasActiveAlerts()) {
omnipod_pod_active_alerts_ack.isEnabled = true
omnipod_pod_active_alerts.text = TextUtils.join(System.lineSeparator(), omnipodUtil.getTranslatedActiveAlerts(podStateManager))
} else {

View file

@ -10,7 +10,6 @@ import android.os.SystemClock;
import androidx.annotation.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -407,7 +406,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (isServiceSet()) {
if (isBusy || !podStateManager.isSetupCompleted() || podStateManager.hasFaultEvent())
if (isBusy || !podStateManager.isPodRunning() || podStateManager.hasFaultEvent())
return true;
if (busyTimestamps.size() > 0) {
@ -497,7 +496,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override
public boolean isSuspended() {
return omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod ||
!podStateManager.isSetupCompleted() || podStateManager.isSuspended();
!podStateManager.isPodRunning() || podStateManager.isSuspended();
}
@Override
@ -622,7 +621,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
setRefreshButtonEnabled(false);
if (podStateManager.isPaired()) {
if (podStateManager.isPodInitialized()) {
aapsLogger.debug(LTag.PUMP, "PodStateManager (saved): " + podStateManager);
if (!isRefresh) {
@ -903,7 +902,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@NotNull
@Override
public String serialNumber() {
return podStateManager.hasState() ? String.valueOf(podStateManager.getAddress()) : "None";
return podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None";
}
@NotNull
@ -998,7 +997,7 @@ 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.isPodRunning() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
if ((podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
rileyLinkServiceData.rileyLinkServiceState.isError() ||

View file

@ -137,7 +137,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
for (int i = 0; 2 > i; i++) {
if (podStateManager.isPaired() && message.isNonceResyncable()) {
if (podStateManager.isPodInitialized() && message.isNonceResyncable()) {
podStateManager.advanceToNextNonce();
}

View file

@ -27,7 +27,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.Prime
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalDeliveryStatusException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.CancelDeliveryCommand;
@ -39,7 +39,7 @@ 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.PacketType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
@ -83,25 +83,36 @@ public class OmnipodManager {
logStartingCommandExecution("pairAndPrime");
try {
if (!podStateManager.hasState() || !podStateManager.isPaired() || podStateManager.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) {
if (!podStateManager.isPodInitialized() || podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PAIRING_COMPLETED)) {
// Always send both 0x07 and 0x03 on retries
try {
communicationService.executeAction(
new AssignAddressAction(podStateManager));
} catch (IllegalPacketTypeException ex) {
if (ex.getActual() == PacketType.ACK && podStateManager.isPaired()) {
if (ex.getActual() == PacketType.ACK && podStateManager.isPodInitialized()) {
// When we already assigned the address before, it's possible to only get an ACK here
aapsLogger.debug("Received ACK instead of response. Ignoring because we already assigned the address successfully");
aapsLogger.debug("Received ACK instead of response in AssignAddressAction. Ignoring because we already assigned the address successfully");
} else {
throw ex;
}
}
communicationService.executeAction(new SetupPodAction(podStateManager));
} else if (SetupProgress.PRIMING.isBefore(podStateManager.getSetupProgress())) {
throw new IllegalSetupProgressException(SetupProgress.POD_CONFIGURED, podStateManager.getSetupProgress());
try {
communicationService.executeAction(new SetupPodAction(podStateManager));
} catch (IllegalPacketTypeException ex) {
if (PacketType.ACK.equals(ex.getActual())) {
// TODO is this true for the SetupPodCommand?
// Pod is already configured
aapsLogger.debug("Received ACK instead of response in SetupPodAction. Ignoring");
}
}
} else if (podStateManager.getPodProgressStatus().isAfter(PodProgressStatus.PRIMING)) {
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_COMPLETED, podStateManager.getPodProgressStatus());
}
// Make sure we have an up to date PodProgressStatus
getPodStatus();
communicationService.executeAction(new PrimeAction(new PrimeService(), podStateManager));
} finally {
logCommandExecutionFinished("pairAndPrime");
@ -110,16 +121,20 @@ public class OmnipodManager {
long delayInSeconds = calculateBolusDuration(OmnipodConst.POD_PRIME_BOLUS_UNITS, OmnipodConst.POD_PRIMING_DELIVERY_RATE).getStandardSeconds();
return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
.map(o -> verifySetupAction(statusResponse ->
PrimeAction.updatePrimingStatus(podStateManager, statusResponse, aapsLogger), SetupProgress.PRIMING_FINISHED)) //
.map(o -> verifySetupAction(PodProgressStatus.PRIMING_COMPLETED)) //
.observeOn(Schedulers.io());
}
public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) {
if (!podStateManager.hasState() || !podStateManager.isPaired() || podStateManager.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, !podStateManager.hasState() ? null : podStateManager.getSetupProgress());
} else if (podStateManager.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
throw new IllegalSetupProgressException(SetupProgress.CANNULA_INSERTING, podStateManager.getSetupProgress());
if (!podStateManager.isPodInitialized() || podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PRIMING_COMPLETED)) {
throw new IllegalPodProgressException(PodProgressStatus.PRIMING_COMPLETED, !podStateManager.isPodInitialized() ? null : podStateManager.getPodProgressStatus());
}
// Make sure we have the latest PodProgressStatus
getPodStatus();
if (podStateManager.getPodProgressStatus().isAfter(PodProgressStatus.INSERTING_CANNULA)) {
throw new IllegalPodProgressException(PodProgressStatus.PRIMING_COMPLETED, podStateManager.getPodProgressStatus());
}
logStartingCommandExecution("insertCannula [basalSchedule=" + basalSchedule + "]");
@ -133,14 +148,13 @@ public class OmnipodManager {
long delayInSeconds = calculateBolusDuration(OmnipodConst.POD_CANNULA_INSERTION_BOLUS_UNITS, OmnipodConst.POD_CANNULA_INSERTION_DELIVERY_RATE).getStandardSeconds();
return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
.map(o -> verifySetupAction(statusResponse ->
InsertCannulaAction.updateCannulaInsertionStatus(podStateManager, statusResponse, aapsLogger), SetupProgress.COMPLETED)) //
.map(o -> verifySetupAction(PodProgressStatus.ABOVE_FIFTY_UNITS)) //
.observeOn(Schedulers.io());
}
public synchronized StatusResponse getPodStatus() {
if (!podStateManager.hasState()) {
throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, null);
if (!podStateManager.isPodInitialized()) {
throw new IllegalPodProgressException(PodProgressStatus.REMINDER_INITIALIZED, null);
}
logStartingCommandExecution("getPodStatus");
@ -424,8 +438,8 @@ public class OmnipodManager {
}
public synchronized void deactivatePod() {
if (!podStateManager.isPaired()) {
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null);
if (!podStateManager.isPodInitialized()) {
throw new IllegalPodProgressException(PodProgressStatus.REMINDER_INITIALIZED, null);
}
logStartingCommandExecution("deactivatePod");
@ -460,8 +474,8 @@ public class OmnipodManager {
return podStateManager.getTime();
}
public boolean isReadyForDelivery() {
return podStateManager.isSetupCompleted();
public boolean isPodRunning() {
return podStateManager.isPodRunning();
}
public boolean hasActiveBolus() {
@ -510,24 +524,23 @@ public class OmnipodManager {
}
private void assertReadyForDelivery() {
if (!isReadyForDelivery()) {
throw new IllegalSetupProgressException(SetupProgress.COMPLETED, !podStateManager.hasState() ? null : podStateManager.getSetupProgress());
if (!isPodRunning()) {
throw new IllegalPodProgressException(PodProgressStatus.ABOVE_FIFTY_UNITS, podStateManager.hasPodState() ? podStateManager.getPodProgressStatus() : null);
}
}
private SetupActionResult verifySetupAction(StatusResponseConsumer setupActionResponseHandler, SetupProgress expectedSetupProgress) {
private SetupActionResult verifySetupAction(PodProgressStatus expectedPodProgressStatus) {
SetupActionResult result = null;
for (int i = 0; ACTION_VERIFICATION_TRIES > i; i++) {
try {
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podStateManager));
setupActionResponseHandler.accept(delayedStatusResponse);
StatusResponse statusResponse = getPodStatus();
if (podStateManager.getSetupProgress().equals(expectedSetupProgress)) {
if (statusResponse.getPodProgressStatus().equals(expectedPodProgressStatus)) {
result = new SetupActionResult(SetupActionResult.ResultType.SUCCESS);
break;
} else {
result = new SetupActionResult(SetupActionResult.ResultType.FAILURE) //
.setupProgress(podStateManager.getSetupProgress());
.podProgressStatus(statusResponse.getPodProgressStatus());
break;
}
} catch (Exception ex) {
@ -547,6 +560,8 @@ public class OmnipodManager {
}
private static Duration calculateBolusDuration(double units, double deliveryRate) {
// TODO take current (temp) basal into account
// Be aware that the Pod possibly doesn't have a Basal Schedule yet
return Duration.standardSeconds((long) Math.ceil(units / deliveryRate));
}

View file

@ -1,12 +1,12 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
public class SetupActionResult {
private final ResultType resultType;
private String message;
private Exception exception;
private SetupProgress setupProgress;
private PodProgressStatus podProgressStatus;
public SetupActionResult(ResultType resultType) {
this.resultType = resultType;
@ -22,8 +22,8 @@ public class SetupActionResult {
return this;
}
public SetupActionResult setupProgress(SetupProgress setupProgress) {
this.setupProgress = setupProgress;
public SetupActionResult podProgressStatus(PodProgressStatus podProgressStatus) {
this.podProgressStatus = podProgressStatus;
return this;
}
@ -39,8 +39,8 @@ public class SetupActionResult {
return exception;
}
public SetupProgress getSetupProgress() {
return setupProgress;
public PodProgressStatus getPodProgressStatus() {
return podProgressStatus;
}
public enum ResultType {

View file

@ -7,12 +7,12 @@ import java.util.Random;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.AssignAddressCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
@ -28,11 +28,11 @@ public class AssignAddressAction implements OmnipodAction<VersionResponse> {
@Override
public VersionResponse execute(OmnipodCommunicationManager communicationService) {
if (!podStateManager.hasState()) {
if (!podStateManager.hasPodState()) {
podStateManager.initState(generateRandomAddress());
}
if (podStateManager.isPaired() && podStateManager.getSetupProgress().isAfter(SetupProgress.ADDRESS_ASSIGNED)) {
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podStateManager.getSetupProgress());
if (podStateManager.isPodInitialized() && podStateManager.getPodProgressStatus().isAfter(PodProgressStatus.REMINDER_INITIALIZED)) {
throw new IllegalPodProgressException(PodProgressStatus.REMINDER_INITIALIZED, podStateManager.getPodProgressStatus());
}
AssignAddressCommand assignAddress = new AssignAddressCommand(podStateManager.getAddress());
@ -49,8 +49,8 @@ public class AssignAddressAction implements OmnipodAction<VersionResponse> {
throw new IllegalMessageAddressException(podStateManager.getAddress(), assignAddressResponse.getAddress());
}
podStateManager.setPairingParameters(assignAddressResponse.getLot(), assignAddressResponse.getTid(), //
assignAddressResponse.getPiVersion(), assignAddressResponse.getPmVersion(), DateTimeZone.getDefault());
podStateManager.setInitializationParameters(assignAddressResponse.getLot(), assignAddressResponse.getTid(), //
assignAddressResponse.getPiVersion(), assignAddressResponse.getPmVersion(), DateTimeZone.getDefault(), assignAddressResponse.getPodProgressStatus());
return assignAddressResponse;
}

View file

@ -1,13 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm.action;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.InsertCannulaService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
@ -32,40 +30,26 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
this.initialBasalSchedule = initialBasalSchedule;
}
public static void updateCannulaInsertionStatus(PodStateManager podStateManager, StatusResponse statusResponse, AAPSLogger aapsLogger) {
if (podStateManager.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING) &&
statusResponse.getPodProgressStatus().isReadyForDelivery()) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Updating SetupProgress from CANNULA_INSERTING to COMPLETED");
podStateManager.setSetupProgress(SetupProgress.COMPLETED);
}
}
@Override
public StatusResponse execute(OmnipodCommunicationManager communicationService) {
if (!podStateManager.isPaired() || podStateManager.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
throw new IllegalSetupProgressException(SetupProgress.PRIMING_FINISHED, podStateManager.getSetupProgress());
if (!podStateManager.isPodInitialized() || podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PRIMING_COMPLETED)) {
throw new IllegalPodProgressException(PodProgressStatus.PRIMING_COMPLETED, podStateManager.isPodInitialized() ? podStateManager.getPodProgressStatus() : null);
}
if (podStateManager.getSetupProgress().isBefore(SetupProgress.INITIAL_BASAL_SCHEDULE_SET)) {
if (podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.BASAL_INITIALIZED)) {
service.programInitialBasalSchedule(communicationService, podStateManager, initialBasalSchedule);
podStateManager.setSetupProgress(SetupProgress.INITIAL_BASAL_SCHEDULE_SET);
}
if (podStateManager.getSetupProgress().isBefore(SetupProgress.STARTING_INSERT_CANNULA)) {
service.executeExpirationRemindersAlertCommand(communicationService, podStateManager);
podStateManager.setSetupProgress(SetupProgress.STARTING_INSERT_CANNULA);
if (podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.INSERTING_CANNULA)) {
}
if (podStateManager.getSetupProgress().isBefore(SetupProgress.CANNULA_INSERTING)) {
StatusResponse statusResponse = service.executeInsertionBolusCommand(communicationService, podStateManager);
podStateManager.setSetupProgress(SetupProgress.CANNULA_INSERTING);
return statusResponse;
} else if (podStateManager.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING)) {
if (podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.INSERTING_CANNULA)) {
service.executeExpirationRemindersAlertCommand(communicationService, podStateManager);
return service.executeInsertionBolusCommand(communicationService, podStateManager);
} else if (podStateManager.getPodProgressStatus().equals(PodProgressStatus.INSERTING_CANNULA)) {
// Check status
StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podStateManager));
updateCannulaInsertionStatus(podStateManager, statusResponse, communicationService.aapsLogger);
return statusResponse;
return communicationService.executeAction(new GetStatusAction(podStateManager));
} else {
throw new IllegalSetupProgressException(null, podStateManager.getSetupProgress());
throw new IllegalPodProgressException(null, podStateManager.getPodProgressStatus());
}
}
}

View file

@ -1,14 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm.action;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
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.state.PodStateManager;
public class PrimeAction implements OmnipodAction<StatusResponse> {
@ -27,35 +24,20 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
this.podStateManager = podStateManager;
}
public static void updatePrimingStatus(PodStateManager podStateManager, StatusResponse statusResponse, AAPSLogger aapsLogger) {
if (podStateManager.getSetupProgress().equals(SetupProgress.PRIMING) && statusResponse.getPodProgressStatus().equals(PodProgressStatus.PRIMING_COMPLETED)) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Updating SetupProgress from PRIMING to PRIMING_FINISHED");
podStateManager.setSetupProgress(SetupProgress.PRIMING_FINISHED);
}
}
@Override
public StatusResponse execute(OmnipodCommunicationManager communicationService) {
if (podStateManager.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) {
throw new IllegalSetupProgressException(SetupProgress.POD_CONFIGURED, podStateManager.getSetupProgress());
if (!podStateManager.isPodInitialized() || podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PAIRING_COMPLETED)) {
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_COMPLETED, podStateManager.isPodInitialized() ? podStateManager.getPodProgressStatus() : null);
}
if (podStateManager.getSetupProgress().isBefore(SetupProgress.STARTING_PRIME)) {
if (podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.PRIMING)) {
service.executeDisableTab5Sub16FaultConfigCommand(communicationService, podStateManager);
service.executeFinishSetupReminderAlertCommand(communicationService, podStateManager);
podStateManager.setSetupProgress(SetupProgress.STARTING_PRIME);
}
if (podStateManager.getSetupProgress().isBefore(SetupProgress.PRIMING)) {
StatusResponse statusResponse = service.executePrimeBolusCommand(communicationService, podStateManager);
podStateManager.setSetupProgress(SetupProgress.PRIMING);
return statusResponse;
} else if (podStateManager.getSetupProgress().equals(SetupProgress.PRIMING)) {
return service.executePrimeBolusCommand(communicationService, podStateManager);
} else if (podStateManager.getPodProgressStatus().equals(PodProgressStatus.PRIMING)) {
// Check status
StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podStateManager));
updatePrimingStatus(podStateManager, statusResponse, communicationService.aapsLogger);
return statusResponse;
return communicationService.executeAction(new GetStatusAction(podStateManager));
} else {
throw new IllegalSetupProgressException(null, podStateManager.getSetupProgress());
throw new IllegalPodProgressException(null, podStateManager.getPodProgressStatus());
}
}
}

View file

@ -6,16 +6,12 @@ import java.util.Collections;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.SetupPodCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
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.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
@ -23,7 +19,7 @@ public class SetupPodAction implements OmnipodAction<VersionResponse> {
private final PodStateManager podStateManager;
public SetupPodAction(PodStateManager podStateManager) {
if(podStateManager == null) {
if (podStateManager == null) {
throw new IllegalArgumentException("Pod state manager can not be null");
}
this.podStateManager = podStateManager;
@ -31,8 +27,8 @@ public class SetupPodAction implements OmnipodAction<VersionResponse> {
@Override
public VersionResponse execute(OmnipodCommunicationManager communicationService) {
if (!podStateManager.getSetupProgress().equals(SetupProgress.ADDRESS_ASSIGNED)) {
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podStateManager.getSetupProgress());
if (!podStateManager.isPodInitialized() || !podStateManager.getPodProgressStatus().equals(PodProgressStatus.REMINDER_INITIALIZED)) {
throw new IllegalPodProgressException(PodProgressStatus.REMINDER_INITIALIZED, podStateManager.isPodInitialized() ? podStateManager.getPodProgressStatus() : null);
}
DateTime activationDate = DateTime.now(podStateManager.getTimeZone());
@ -41,17 +37,8 @@ public class SetupPodAction implements OmnipodAction<VersionResponse> {
OmnipodMessage message = new OmnipodMessage(OmnipodConst.DEFAULT_ADDRESS,
Collections.singletonList(setupPodCommand), podStateManager.getMessageNumber());
VersionResponse setupPodResponse;
try {
setupPodResponse = communicationService.exchangeMessages(VersionResponse.class, podStateManager,
message, OmnipodConst.DEFAULT_ADDRESS, podStateManager.getAddress());
} catch (IllegalPacketTypeException ex) {
if (PacketType.ACK.equals(ex.getActual())) {
// Pod is already configured
podStateManager.setSetupProgress(SetupProgress.POD_CONFIGURED);
return null;
}
throw ex;
}
setupPodResponse = communicationService.exchangeMessages(VersionResponse.class, podStateManager,
message, OmnipodConst.DEFAULT_ADDRESS, podStateManager.getAddress());
if (!setupPodResponse.isSetupPodVersionResponse()) {
throw new IllegalVersionResponseTypeException("setupPod", "assignAddress");
@ -59,11 +46,6 @@ public class SetupPodAction implements OmnipodAction<VersionResponse> {
if (setupPodResponse.getAddress() != podStateManager.getAddress()) {
throw new IllegalMessageAddressException(podStateManager.getAddress(), setupPodResponse.getAddress());
}
if (setupPodResponse.getPodProgressStatus() != PodProgressStatus.PAIRING_COMPLETED) {
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_COMPLETED, setupPodResponse.getPodProgressStatus());
}
podStateManager.setSetupProgress(SetupProgress.POD_CONFIGURED);
return setupPodResponse;
}

View file

@ -49,7 +49,7 @@ public class InsertCannulaService {
autoOffAlertConfiguration //
);
return new ConfigureAlertsAction(podStateManager, alertConfigurations).execute(communicationService);
return communicationService.executeAction(new ConfigureAlertsAction(podStateManager, alertConfigurations));
}
public StatusResponse executeInsertionBolusCommand(OmnipodCommunicationManager communicationService, PodStateManager podStateManager) {

View file

@ -1,26 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
public class IllegalSetupProgressException extends OmnipodException {
private final SetupProgress expected;
private final SetupProgress actual;
public IllegalSetupProgressException(SetupProgress expected, SetupProgress actual) {
super(String.format(Locale.getDefault(), "Illegal setup progress: %s, expected: %s", actual, expected), true);
this.expected = expected;
this.actual = actual;
}
public SetupProgress getExpected() {
return expected;
}
public SetupProgress getActual() {
return actual;
}
}

View file

@ -37,7 +37,32 @@ public enum PodProgressStatus {
return value;
}
public boolean isReadyForDelivery() {
public boolean isAddressAssigned() {
return this.isAtLeast(REMINDER_INITIALIZED);
}
public boolean isRunning() {
return this == ABOVE_FIFTY_UNITS || this == FIFTY_OR_LESS_UNITS;
}
// TODO there must be a better name for this... but I can't think of it
public boolean isDead() {
return this.isAtLeast(FAULT_EVENT_OCCURRED);
}
public boolean isAtMost(PodProgressStatus other) {
return value <= other.value;
}
public boolean isBefore(PodProgressStatus other) {
return value < other.value;
}
public boolean isAtLeast(PodProgressStatus other) {
return this.ordinal() >= other.ordinal();
}
public boolean isAfter(PodProgressStatus other) {
return this.ordinal() > other.ordinal();
}
}

View file

@ -1,21 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
public enum SetupProgress {
ADDRESS_ASSIGNED,
POD_CONFIGURED,
STARTING_PRIME,
PRIMING,
PRIMING_FINISHED,
INITIAL_BASAL_SCHEDULE_SET,
STARTING_INSERT_CANNULA,
CANNULA_INSERTING,
COMPLETED;
public boolean isBefore(SetupProgress other) {
return this.ordinal() < other.ordinal();
}
public boolean isAfter(SetupProgress other) {
return this.ordinal() > other.ordinal();
}
}

View file

@ -26,7 +26,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion;
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.util.OmniCRC;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
@ -43,10 +42,6 @@ public abstract class PodStateManager {
this.gsonInstance = createGson();
}
public final boolean hasState() {
return podState != null;
}
public final void removeState() {
this.podState = null;
storePodState();
@ -54,7 +49,7 @@ public abstract class PodStateManager {
}
public final void initState(int address) {
if (hasState()) {
if (hasPodState()) {
throw new IllegalStateException("Can not init a new pod state: podState <> null");
}
podState = new PodState(address);
@ -62,23 +57,43 @@ public abstract class PodStateManager {
notifyPodStateChanged();
}
public final boolean isPaired() {
return hasState() //
/**
* @return true if we have a Pod state (which at least contains an ddress), indicating it is legal to call getters on PodStateManager
*/
public final boolean hasPodState() {
return podState != null;
}
/**
* @return true if we have a Pod state and the Pod has been initialized, meaning it has an address assigned.
*/
public final boolean isPodInitialized() {
return hasPodState() //
&& podState.getLot() != null && podState.getTid() != null //
&& podState.getPiVersion() != null && podState.getPmVersion() != null //
&& podState.getTimeZone() != null //
&& podState.getSetupProgress() != null;
&& podState.getPodProgressStatus() != null;
}
public final boolean isSetupCompleted() {
return isPaired() && SetupProgress.COMPLETED.equals(podState.getSetupProgress());
/**
* @return true if we have a Pod state and the Pod is running, meaning the activation process has completed and the Pod is not deactivated or in a fault state
*/
public final boolean isPodRunning() {
return isPodInitialized() && getPodProgressStatus().isRunning();
}
public final void setPairingParameters(int lot, int tid, FirmwareVersion piVersion, FirmwareVersion pmVersion, DateTimeZone timeZone) {
if (!hasState()) {
/**
* @return true if we have a Pod state and the Pod is dead, meaning it is either in a fault state or activation time has been exceeded or it is deactivated
*/
public boolean isPodDead() {
return isPodInitialized() && getPodProgressStatus().isDead();
}
public final void setInitializationParameters(int lot, int tid, FirmwareVersion piVersion, FirmwareVersion pmVersion, DateTimeZone timeZone, PodProgressStatus podProgressStatus) {
if (!hasPodState()) {
throw new IllegalStateException("Cannot set pairing parameters: podState is null");
}
if (isPaired() && getSetupProgress().isAfter(SetupProgress.ADDRESS_ASSIGNED)) {
if (isPodInitialized() && getPodProgressStatus().isAfter(PodProgressStatus.REMINDER_INITIALIZED)) {
throw new IllegalStateException("Cannot set pairing parameters: pairing parameters have already been set");
}
if (piVersion == null) {
@ -90,6 +105,9 @@ public abstract class PodStateManager {
if (timeZone == null) {
throw new IllegalArgumentException("Cannot set pairing parameters: timeZone can not be null");
}
if (podProgressStatus == null) {
throw new IllegalArgumentException("Cannot set pairing parameters: podProgressStatus can not be null");
}
setAndStore(() -> {
podState.setLot(lot);
@ -98,7 +116,7 @@ public abstract class PodStateManager {
podState.setPmVersion(pmVersion);
podState.setTimeZone(timeZone);
podState.setNonceState(new NonceState(lot, tid));
podState.setSetupProgress(SetupProgress.ADDRESS_ASSIGNED);
podState.setPodProgressStatus(podProgressStatus);
podState.getConfiguredAlerts().put(AlertSlot.SLOT7, AlertType.FINISH_SETUP_REMINDER);
});
}
@ -132,7 +150,7 @@ public abstract class PodStateManager {
}
public final synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) {
if (!isPaired()) {
if (!isPodInitialized()) {
throw new IllegalStateException("Cannot resync nonce: Pod is not paired yet");
}
@ -147,14 +165,14 @@ public abstract class PodStateManager {
}
public final synchronized int getCurrentNonce() {
if (!isPaired()) {
if (!isPodInitialized()) {
throw new IllegalStateException("Cannot get current nonce: Pod is not paired yet");
}
return podState.getNonceState().getCurrentNonce();
}
public final synchronized void advanceToNextNonce() {
if (!isPaired()) {
if (!isPodInitialized()) {
throw new IllegalStateException("Cannot advance to next nonce: Pod is not paired yet");
}
setAndStore(() -> podState.getNonceState().advanceToNextNonce(), false);
@ -176,6 +194,10 @@ public abstract class PodStateManager {
setAndStore(() -> podState.setLastFailedCommunication(dateTime));
}
public final DateTime getLastUpdatedFromStatusResponse() {
return getSafe(() -> podState.getLastUpdatedFromStatusResponse());
}
public final boolean hasFaultEvent() {
return podState != null && podState.getFaultEvent() != null;
}
@ -260,17 +282,6 @@ public abstract class PodStateManager {
return expiresAt == null ? "???" : DateUtil.dateAndTimeString(expiresAt.toDate());
}
public final SetupProgress getSetupProgress() {
return getSafe(() -> podState.getSetupProgress());
}
public final void setSetupProgress(SetupProgress setupProgress) {
if (setupProgress == null) {
throw new IllegalArgumentException("Setup progress can not be null");
}
setAndStore(() -> podState.setSetupProgress(setupProgress));
}
public final PodProgressStatus getPodProgressStatus() {
return getSafe(() -> podState.getPodProgressStatus());
}
@ -343,7 +354,7 @@ public abstract class PodStateManager {
}
public final void updateFromStatusResponse(StatusResponse statusResponse) {
if (!hasState()) {
if (!hasPodState()) {
throw new IllegalStateException("Cannot update from status response: podState is null");
}
setAndStore(() -> {
@ -366,6 +377,7 @@ public abstract class PodStateManager {
podState.setLastDeliveryStatus(statusResponse.getDeliveryStatus());
podState.setReservoirLevel(statusResponse.getReservoirLevel());
podState.setPodProgressStatus(statusResponse.getPodProgressStatus());
podState.setLastUpdatedFromStatusResponse(DateTime.now());
});
}
@ -374,7 +386,7 @@ public abstract class PodStateManager {
}
private void setAndStore(Runnable runnable, boolean notifyPodStateChanged) {
if (!hasState()) {
if (!hasPodState()) {
throw new IllegalStateException("Cannot mutate PodState: podState is null");
}
runnable.run();
@ -418,7 +430,7 @@ public abstract class PodStateManager {
// Not actually "safe" as it throws an Exception, but it prevents NPEs
private <T> T getSafe(Supplier<T> supplier) {
if (!hasState()) {
if (!hasPodState()) {
throw new IllegalStateException("Cannot read from PodState: podState is null");
}
return supplier.get();
@ -454,6 +466,7 @@ public abstract class PodStateManager {
private int messageNumber;
private DateTime lastSuccessfulCommunication;
private DateTime lastFailedCommunication;
private DateTime lastUpdatedFromStatusResponse;
private DateTimeZone timeZone;
private DateTime activatedAt;
private DateTime expiresAt;
@ -461,7 +474,6 @@ public abstract class PodStateManager {
private Double reservoirLevel;
private boolean suspended;
private NonceState nonceState;
private SetupProgress setupProgress;
private PodProgressStatus podProgressStatus;
private DeliveryStatus lastDeliveryStatus;
private AlertSet activeAlerts;
@ -545,6 +557,14 @@ public abstract class PodStateManager {
this.lastFailedCommunication = lastFailedCommunication;
}
DateTime getLastUpdatedFromStatusResponse() {
return lastUpdatedFromStatusResponse;
}
void setLastUpdatedFromStatusResponse(DateTime lastUpdatedFromStatusResponse) {
this.lastUpdatedFromStatusResponse = lastUpdatedFromStatusResponse;
}
DateTimeZone getTimeZone() {
return timeZone;
}
@ -601,14 +621,6 @@ public abstract class PodStateManager {
this.nonceState = nonceState;
}
public SetupProgress getSetupProgress() {
return setupProgress;
}
void setSetupProgress(SetupProgress setupProgress) {
this.setupProgress = setupProgress;
}
public PodProgressStatus getPodProgressStatus() {
return podProgressStatus;
}
@ -696,6 +708,7 @@ public abstract class PodStateManager {
", messageNumber=" + messageNumber +
", lastSuccessfulCommunication=" + lastSuccessfulCommunication +
", lastFailedCommunication=" + lastFailedCommunication +
", lastUpdatedFromStatusResponse=" + lastUpdatedFromStatusResponse +
", timeZone=" + timeZone +
", activatedAt=" + activatedAt +
", expiresAt=" + expiresAt +
@ -703,7 +716,7 @@ public abstract class PodStateManager {
", reservoirLevel=" + reservoirLevel +
", suspended=" + suspended +
", nonceState=" + nonceState +
", setupProgress=" + setupProgress +
", podProgressStatus=" + podProgressStatus +
", lastDeliveryStatus=" + lastDeliveryStatus +
", activeAlerts=" + activeAlerts +
", basalSchedule=" + basalSchedule +

View file

@ -16,7 +16,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.model.FullInitPodWizardModel
@ -104,7 +104,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
wizardPagerContext.clearContext()
wizardPagerContext.pagerSettings = pagerSettings
val isFullInit = !podStateManager.isPaired || podStateManager.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED)
val isFullInit = !podStateManager.isPodInitialized || podStateManager.podProgressStatus.isBefore(PodProgressStatus.PRIMING_COMPLETED)
if (isFullInit) {
wizardPagerContext.wizardModel = FullInitPodWizardModel(applicationContext)
} else {
@ -156,16 +156,16 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}
fun refreshButtons() {
initpod_init_pod.isEnabled = !podStateManager.isPaired() ||
podStateManager.setupProgress.isBefore(SetupProgress.COMPLETED)
initpod_init_pod.isEnabled = !podStateManager.isPodRunning()
initpod_remove_pod.isEnabled = podStateManager.hasState() && podStateManager.isPaired
initpod_reset_pod.isEnabled = podStateManager.hasState()
initpod_remove_pod.isEnabled = podStateManager.isPodInitialized
initpod_reset_pod.isEnabled = podStateManager.hasPodState()
if (!rileyLinkServiceData.rileyLinkServiceState.isReady) {
// if rileylink is not running we disable all operations that require a RL connection
initpod_init_pod.isEnabled = false
initpod_remove_pod.isEnabled = false
initpod_reset_pod.isEnabled = false
}
}

View file

@ -15,7 +15,6 @@ import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType;
@ -60,7 +59,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
@Override
public void execute() {
if (actionType == PodActionType.InitPod) {
if (podStateManager.getSetupProgress().isBefore(SetupProgress.COMPLETED)) {
if (!podStateManager.isPodRunning()) {
omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodInitializing);
} else {
omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached);

View file

@ -44,7 +44,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMes
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.MessageDecodingException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
@ -453,7 +452,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
}
public boolean isInitialized() {
return delegate.isReadyForDelivery();
return delegate.isPodRunning();
}
private void reportImplicitlyCanceledTbr() {
@ -496,7 +495,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
}
podHistory.setSuccess(success);
podHistory.setPodSerial(podStateManager.hasState() ? String.valueOf(podStateManager.getAddress()) : "None");
podHistory.setPodSerial(podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None");
MainApp.getDbHelper().createOrUpdate(podHistory);
@ -507,8 +506,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
String comment = null;
switch (res.getResultType()) {
case FAILURE: {
aapsLogger.error(LTag.PUMP, "Setup action failed: illegal setup progress: {}", res.getSetupProgress());
comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state, res.getSetupProgress());
aapsLogger.error(LTag.PUMP, "Setup action failed: illegal setup progress: {}", res.getPodProgressStatus());
comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state, res.getPodProgressStatus());
}
break;
case VERIFICATION_FAILURE: {
@ -543,8 +542,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
comment = getStringResource(R.string.omnipod_driver_error_crc_mismatch);
} else if (ex instanceof IllegalPacketTypeException) {
comment = getStringResource(R.string.omnipod_driver_error_invalid_packet_type);
} else if (ex instanceof IllegalPodProgressException || ex instanceof IllegalSetupProgressException
|| ex instanceof IllegalDeliveryStatusException) {
} else if (ex instanceof IllegalPodProgressException || ex instanceof IllegalDeliveryStatusException) {
comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state);
} else if (ex instanceof IllegalVersionResponseTypeException) {
comment = getStringResource(R.string.omnipod_driver_error_invalid_response);

View file

@ -66,7 +66,7 @@ public class AapsPodStateManager extends PodStateManager {
@Override
protected void notifyPodStateChanged() {
if (!hasState()) {
if (!hasPodState()) {
omnipodPumpStatus.lastBolusTime = null;
omnipodPumpStatus.lastBolusAmount = null;
omnipodPumpStatus.reservoirRemainingUnits = 0.0;
@ -77,7 +77,7 @@ public class AapsPodStateManager extends PodStateManager {
Double lastBolusAmount = getLastBolusAmount();
// Update other info: last bolus, units remaining, suspended
boolean suspended = isSuspended() || !isSetupCompleted() || hasFaultEvent();
boolean suspended = isSuspended() || !isPodRunning() || hasFaultEvent();
if (Objects.equals(lastBolusStartTime, omnipodPumpStatus.lastBolusTime) //
|| !Objects.equals(lastBolusAmount, omnipodPumpStatus.lastBolusAmount) //
|| !isReservoirStatusUpToDate(omnipodPumpStatus, getReservoirLevel())

View file

@ -1866,7 +1866,7 @@
<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 (setup progress: %1$s)</string>
<string name="omnipod_pod_setup_in_progress">Pod setup in progress (Pod progress status: %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_fault_description">Pod Fault: %1$s %2$s</string>

View file

@ -13,6 +13,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -39,8 +40,8 @@ public class AapsPodStateManagerTest {
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper);
podStateManager.initState(0x0);
podStateManager.setPairingParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone);
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
assertEquals(now, podStateManager.getTime());
assertEquals(Duration.standardHours(1).plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), podStateManager.getScheduleOffset());
@ -57,8 +58,8 @@ public class AapsPodStateManagerTest {
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper);
podStateManager.initState(0x0);
podStateManager.setPairingParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone);
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
DateTimeZone newTimeZone = DateTimeZone.forOffsetHours(2);
DateTimeZone.setDefault(newTimeZone);
@ -80,8 +81,8 @@ public class AapsPodStateManagerTest {
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper);
podStateManager.initState(0x0);
podStateManager.setPairingParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone);
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
DateTimeZone newTimeZone = DateTimeZone.forOffsetHours(2);
DateTimeZone.setDefault(newTimeZone);