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 {
// TODO update Treatments
// 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(
history.createRecord(
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
// 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
podStateManager.resetActiveCommand()
podStateManager.markActiveCommandFailed()
source.onSuccess(
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
)

View file

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

View file

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