add check for onError whent the command was sent

This commit is contained in:
Andrei Vereha 2021-04-26 21:56:54 +02:00
parent b64d530ae9
commit cddf7a3f68
3 changed files with 17 additions and 4 deletions

View file

@ -236,6 +236,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
): PumpEnactResult { ): PumpEnactResult {
// TODO update Treatments // TODO update Treatments
// TODO check for existing basal // TODO check for existing basal
// check existing basal(locally and maybe? get status)
// if enforceNew -> cancel it()
// else -> return error that existing basal is running
// set new temp basal
// update treatments
// profit
return executeProgrammingCommand( return executeProgrammingCommand(
history.createRecord( history.createRecord(
commandType = OmnipodCommandType.SET_TEMPORARY_BASAL, commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
@ -468,7 +474,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
// Here we assume that onError will be called only BEFORE we manage to send a command // Here we assume that onError will be called only BEFORE we manage to send a command
// If it gets called later, we will have the command as "not sent" in history and will not try to // If it gets called later, we will have the command as "not sent" in history and will not try to
// get it's final status, even if it was send // get it's final status, even if it was send
podStateManager.resetActiveCommand()
podStateManager.markActiveCommandFailed()
source.onSuccess( source.onSuccess(
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message) PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
) )

View file

@ -68,7 +68,7 @@ interface OmnipodDashPodStateManager {
fun createActiveCommand(historyId: String): Completable fun createActiveCommand(historyId: String): Completable
fun updateActiveCommand(): Maybe<PodEvent> fun updateActiveCommand(): Maybe<PodEvent>
fun resetActiveCommand() fun markActiveCommandFailed()
data class ActiveCommand( data class ActiveCommand(
val sequence: Short, val sequence: Short,

View file

@ -201,9 +201,14 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
} }
@Synchronized @Synchronized
override fun resetActiveCommand() { override fun markActiveCommandFailed() {
podState.activeCommand?.run {
if (sentRealtime < createdRealtime) {
// command was not sent
podState.activeCommand = null podState.activeCommand = null
} }
}
}
@Synchronized @Synchronized
override fun updateActiveCommand() = Maybe.create<PodEvent> { source -> override fun updateActiveCommand() = Maybe.create<PodEvent> { source ->
@ -214,6 +219,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
"$sequenceNumberOfLastProgrammingCommand $historyId" "$sequenceNumberOfLastProgrammingCommand $historyId"
) )
if (createdRealtime >= lastStatusResponseReceived) if (createdRealtime >= lastStatusResponseReceived)
// we did not receive a valid response yet
source.onComplete() source.onComplete()
else { else {
podState.activeCommand = null podState.activeCommand = null