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 { return Completable.defer {
val expectedState = pumpSync.expectedPumpState() val expectedState = pumpSync.expectedPumpState()
when { when {
expectedState.temporaryBasal == null -> expectedState.temporaryBasal == null -> {
aapsLogger.info(LTag.PUMP, "No temporary basal to cancel")
Completable.complete() Completable.complete()
}
!enforeNew -> !enforeNew ->
Completable.error( Completable.error(
IllegalStateException( IllegalStateException(
"Temporary basal already active and enforeNew is not set." "Temporary basal already active and enforeNew is not set."
) )
) )
else -> // enforceNew == true else -> {
// TODO: chain with the completable? // enforceNew == true
aapsLogger.info(LTag.PUMP, "Canceling existing temp basal")
executeSimpleProgrammingCommand( executeSimpleProgrammingCommand(
history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL),
omnipodManager.stopTempBasal().ignoreElements() omnipodManager.stopTempBasal().ignoreElements()
) )
}
} }
} }
} }
@ -591,6 +595,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
.flatMap { podStateManager.createActiveCommand(it) } .flatMap { podStateManager.createActiveCommand(it) }
.ignoreElement(), .ignoreElement(),
command.doOnError { command.doOnError {
podStateManager.activeCommand?.sendError = it
aapsLogger.error(LTag.PUMP, "Error executing command", it) aapsLogger.error(LTag.PUMP, "Error executing command", it)
}.onErrorComplete(), }.onErrorComplete(),
history.updateFromState(podStateManager), history.updateFromState(podStateManager),

View file

@ -75,7 +75,8 @@ interface OmnipodDashPodStateManager {
val sequence: Short, val sequence: Short,
val createdRealtime: Long, val createdRealtime: Long,
var sentRealtime: Long = 0, var sentRealtime: Long = 0,
val historyId: String val historyId: String,
var sendError: Throwable?,
) )
// TODO: set created to "now" on boot // TODO: set created to "now" on boot
data class TempBasal(val startTime: Long, val rate: Double, val durationInMinutes: Short) : Serializable 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( val command = OmnipodDashPodStateManager.ActiveCommand(
podState.messageSequenceNumber, podState.messageSequenceNumber,
createdRealtime = SystemClock.elapsedRealtime(), createdRealtime = SystemClock.elapsedRealtime(),
historyId = historyId historyId = historyId,
sendError = null,
) )
podState.activeCommand = command podState.activeCommand = command
source.onSuccess(command) source.onSuccess(command)
@ -236,10 +237,12 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
"lastResponse=$lastStatusResponseReceived " + "lastResponse=$lastStatusResponseReceived " +
"$sequenceNumberOfLastProgrammingCommand $historyId" "$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 podState.activeCommand = null
source.onComplete() source.onError(this.sendError
?: java.lang.IllegalStateException("Could not send command and sendError is " +
"missing") )
} else if (createdRealtime >= lastStatusResponseReceived) } else if (createdRealtime >= lastStatusResponseReceived)
// we did not receive a valid response yet // we did not receive a valid response yet
source.onComplete() source.onComplete()