From d0b1757268390cf7f93ac068648696e0d2d1a283 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 1 Jun 2021 00:18:38 +0200 Subject: [PATCH] bugfix: send error when we can't send the command --- .../pump/omnipod/dash/OmnipodDashPumpPlugin.kt | 11 ++++++++--- .../driver/pod/state/OmnipodDashPodStateManager.kt | 3 ++- .../pod/state/OmnipodDashPodStateManagerImpl.kt | 11 +++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index e572cea2a6..d6d128a7cb 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -311,20 +311,24 @@ class OmnipodDashPumpPlugin @Inject constructor( return Completable.defer { val expectedState = pumpSync.expectedPumpState() when { - expectedState.temporaryBasal == null -> + expectedState.temporaryBasal == null -> { + aapsLogger.info(LTag.PUMP, "No temporary basal to cancel") Completable.complete() + } !enforeNew -> Completable.error( IllegalStateException( "Temporary basal already active and enforeNew is not set." ) ) - else -> // enforceNew == true - // TODO: chain with the completable? + else -> { + // enforceNew == true + aapsLogger.info(LTag.PUMP, "Canceling existing temp basal") executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), omnipodManager.stopTempBasal().ignoreElements() ) + } } } } @@ -591,6 +595,7 @@ class OmnipodDashPumpPlugin @Inject constructor( .flatMap { podStateManager.createActiveCommand(it) } .ignoreElement(), command.doOnError { + podStateManager.activeCommand?.sendError = it aapsLogger.error(LTag.PUMP, "Error executing command", it) }.onErrorComplete(), history.updateFromState(podStateManager), diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index 1396f97443..bc5fdf060a 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -75,7 +75,8 @@ interface OmnipodDashPodStateManager { val sequence: Short, val createdRealtime: Long, var sentRealtime: Long = 0, - val historyId: String + val historyId: String, + var sendError: Throwable?, ) // TODO: set created to "now" on boot data class TempBasal(val startTime: Long, val rate: Double, val durationInMinutes: Short) : Serializable diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index 38819f0a0f..f100620760 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -197,7 +197,8 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( val command = OmnipodDashPodStateManager.ActiveCommand( podState.messageSequenceNumber, createdRealtime = SystemClock.elapsedRealtime(), - historyId = historyId + historyId = historyId, + sendError = null, ) podState.activeCommand = command source.onSuccess(command) @@ -236,10 +237,12 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( "lastResponse=$lastStatusResponseReceived " + "$sequenceNumberOfLastProgrammingCommand $historyId" ) - if (sentRealtime < createdRealtime) { - // command was not sent, clear it up + + if (sentRealtime < createdRealtime) { // command was not sent, clear it up podState.activeCommand = null - source.onComplete() + source.onError(this.sendError + ?: java.lang.IllegalStateException("Could not send command and sendError is " + + "missing") ) } else if (createdRealtime >= lastStatusResponseReceived) // we did not receive a valid response yet source.onComplete()