bugfix: send error when we can't send the command

This commit is contained in:
Andrei Vereha 2021-06-01 00:18:38 +02:00
parent e867b1397d
commit d0b1757268
3 changed files with 17 additions and 8 deletions

View file

@ -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),

View file

@ -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

View file

@ -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()