Restore command queue in Pod status, properly update it and disable buttons when queue is not empty
This commit is contained in:
parent
ae4b25af89
commit
6b6b4eb759
5 changed files with 42 additions and 57 deletions
|
@ -75,7 +75,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStorage
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoRecentPulseLog;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPodStateActionsAllowedChanged;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService;
|
||||
|
@ -133,7 +132,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
private long nextPodCheck;
|
||||
private boolean sentIdToFirebase;
|
||||
private long lastConnectionTimeMillis;
|
||||
private boolean podStateActionsAllowed = true;
|
||||
|
||||
@Inject
|
||||
public OmnipodPumpPlugin(
|
||||
|
@ -403,7 +401,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
if (firstRun) {
|
||||
initializeAfterRileyLinkConnection();
|
||||
} else if (!omnipodStatusRequestList.isEmpty()) {
|
||||
setAllowPodStateActions(false);
|
||||
Iterator<OmnipodStatusRequestType> iterator = omnipodStatusRequestList.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
@ -439,10 +436,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
|
||||
}
|
||||
iterator.remove();
|
||||
setAllowPodStateActions(true);
|
||||
}
|
||||
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
||||
setAllowPodStateActions(false);
|
||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
|
||||
|
||||
if (result.success) {
|
||||
|
@ -463,7 +458,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
timeChangeRetries = 0;
|
||||
}
|
||||
}
|
||||
setAllowPodStateActions(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -777,7 +771,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) {
|
||||
setAllowPodStateActions(false);
|
||||
omnipodStatusRequestList.add(pumpStatusRequest);
|
||||
}
|
||||
|
||||
|
@ -859,7 +852,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull
|
||||
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||
setAllowPodStateActions(false);
|
||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
|
||||
|
||||
if (result.success) {
|
||||
|
@ -868,7 +860,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
result.carbsDelivered(detailedBolusInfo.carbs);
|
||||
}
|
||||
setAllowPodStateActions(true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -902,17 +893,4 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
|
||||
}
|
||||
|
||||
private void setAllowPodStateActions(boolean allowed) {
|
||||
if (podStateActionsAllowed != allowed) {
|
||||
podStateActionsAllowed = allowed;
|
||||
rxBus.send(new EventOmnipodPodStateActionsAllowedChanged());
|
||||
}
|
||||
}
|
||||
|
||||
// Allow usage of buttons in Omnipod tab that read or modify the Pod state:
|
||||
// Refresh Status, Acknowledge Alerts and Get Pulse Log
|
||||
public boolean isPodStateActionsAllowed() {
|
||||
return podStateActionsAllowed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -203,12 +203,7 @@ public class OmnipodManager {
|
|||
|
||||
try {
|
||||
cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep);
|
||||
} catch (Exception ex) {
|
||||
logCommandExecutionFinished("setBasalSchedule");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
return executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podStateManager, schedule,
|
||||
false, podStateManager.getScheduleOffset(), acknowledgementBeep)));
|
||||
|
@ -231,21 +226,18 @@ public class OmnipodManager {
|
|||
|
||||
try {
|
||||
cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep);
|
||||
} catch (Exception ex) {
|
||||
logCommandExecutionFinished("setTemporaryBasal");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
try {
|
||||
StatusResponse statusResponse = executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction(
|
||||
podStateManager, rate, duration,
|
||||
acknowledgementBeep, completionBeep)));
|
||||
return statusResponse;
|
||||
} catch (OmnipodException ex) {
|
||||
// Treat all exceptions as uncertain failures, because all delivery has been suspended here.
|
||||
// Setting this to an uncertain failure will enable for the user to get an appropriate warning
|
||||
ex.setCertainFailure(false);
|
||||
throw ex;
|
||||
try {
|
||||
StatusResponse statusResponse = executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction(
|
||||
podStateManager, rate, duration,
|
||||
acknowledgementBeep, completionBeep)));
|
||||
return statusResponse;
|
||||
} catch (OmnipodException ex) {
|
||||
// Treat all exceptions as uncertain failures, because all delivery has been suspended here.
|
||||
// Setting this to an uncertain failure will enable for the user to get an appropriate warning
|
||||
ex.setCertainFailure(false);
|
||||
throw ex;
|
||||
}
|
||||
} finally {
|
||||
logCommandExecutionFinished("setTemporaryBasal");
|
||||
}
|
||||
|
@ -295,8 +287,6 @@ public class OmnipodManager {
|
|||
// Catch uncertain exceptions as we still want to report bolus progress indication
|
||||
aapsLogger.error(LTag.PUMPBTCOMM, "Caught exception[certainFailure=false] in bolus", ex);
|
||||
commandDeliveryStatus = CommandDeliveryStatus.UNCERTAIN_FAILURE;
|
||||
} finally {
|
||||
logCommandExecutionFinished("bolus");
|
||||
}
|
||||
|
||||
DateTime startDate = DateTime.now().minus(OmnipodConstants.AVERAGE_BOLUS_COMMAND_COMMUNICATION_DURATION);
|
||||
|
@ -365,6 +355,8 @@ public class OmnipodManager {
|
|||
})
|
||||
.subscribe());
|
||||
|
||||
logCommandExecutionFinished("bolus");
|
||||
|
||||
return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.event
|
||||
|
||||
import info.nightscout.androidaps.events.Event
|
||||
|
||||
/**
|
||||
* Created by andy on 04.06.2018.
|
||||
*/
|
||||
class EventOmnipodPodStateActionsAllowedChanged : Event()
|
|
@ -24,10 +24,10 @@ import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStatusR
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPodStateActionsAllowedChanged
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil
|
||||
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
|
@ -129,7 +129,7 @@ class OmnipodFragment : DaggerFragment() {
|
|||
} else {
|
||||
disablePodActionButtons()
|
||||
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog);
|
||||
commandQueue.readStatus("Clicked Refresh", null)
|
||||
commandQueue.readStatus("Clicked Pulse Log", null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,9 +152,10 @@ class OmnipodFragment : DaggerFragment() {
|
|||
updatePodActionButtons()
|
||||
}, { fabricPrivacy.logException(it) })
|
||||
disposables += rxBus
|
||||
.toObservable(EventOmnipodPodStateActionsAllowedChanged::class.java)
|
||||
.toObservable(EventQueueChanged::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
updateQueueStatus()
|
||||
updatePodActionButtons()
|
||||
}, { fabricPrivacy.logException(it) })
|
||||
disposables += rxBus
|
||||
|
@ -176,6 +177,7 @@ class OmnipodFragment : DaggerFragment() {
|
|||
updateRileyLinkStatus()
|
||||
updateOmipodStatus()
|
||||
updatePodActionButtons()
|
||||
updateQueueStatus()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
@ -339,6 +341,16 @@ class OmnipodFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateQueueStatus() {
|
||||
val status = commandQueue.spannedStatus()
|
||||
if (status.toString() == "") {
|
||||
omnipod_queue.visibility = View.GONE
|
||||
} else {
|
||||
omnipod_queue.visibility = View.VISIBLE
|
||||
omnipod_queue.text = status
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePodActionButtons() {
|
||||
updateRefreshStatusButton()
|
||||
updateAcknowledgeAlertsButton()
|
||||
|
@ -353,12 +365,12 @@ class OmnipodFragment : DaggerFragment() {
|
|||
|
||||
private fun updateRefreshStatusButton() {
|
||||
omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED)
|
||||
&& rileyLinkServiceData.rileyLinkServiceState.isReady && omnipodPumpPlugin.isPodStateActionsAllowed
|
||||
&& rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty()
|
||||
}
|
||||
|
||||
private fun updateAcknowledgeAlertsButton() {
|
||||
if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts() && !podStateManager.isPodDead) {
|
||||
omnipod_pod_active_alerts_ack.isEnabled = omnipodPumpPlugin.isPodStateActionsAllowed && rileyLinkServiceData.rileyLinkServiceState.isReady
|
||||
omnipod_pod_active_alerts_ack.isEnabled = rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty()
|
||||
} else {
|
||||
omnipod_pod_active_alerts_ack.isEnabled = false
|
||||
}
|
||||
|
@ -367,7 +379,7 @@ class OmnipodFragment : DaggerFragment() {
|
|||
fun updatePulseLogButton() {
|
||||
if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) {
|
||||
omnipod_pod_debug.visibility = View.VISIBLE
|
||||
omnipod_pod_debug.isEnabled = podStateManager.isPodActivationCompleted && omnipodPumpPlugin.isPodStateActionsAllowed && rileyLinkServiceData.rileyLinkServiceState.isReady
|
||||
omnipod_pod_debug.isEnabled = podStateManager.isPodActivationCompleted && rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty()
|
||||
} else {
|
||||
omnipod_pod_debug.visibility = View.GONE
|
||||
}
|
||||
|
@ -412,4 +424,8 @@ class OmnipodFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun isQueueEmpty(): Boolean {
|
||||
return commandQueue.size() == 0 && commandQueue.performing() == null
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -320,6 +320,13 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/omnipod_queue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textAlignment="center" />
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
|
|
Loading…
Reference in a new issue