observe there is no activeCommand
This commit is contained in:
parent
24e5223ad1
commit
4bd5e7c625
3 changed files with 26 additions and 6 deletions
|
@ -473,6 +473,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
): PumpEnactResult {
|
||||
return Single.create<PumpEnactResult> { source ->
|
||||
Observable.concat(
|
||||
podStateManager.observeNoActiveCommand(),
|
||||
historyId.flatMapObservable { recordId ->
|
||||
podStateManager.createActiveCommand(recordId).toObservable()
|
||||
},
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
|
@ -67,6 +68,7 @@ interface OmnipodDashPodStateManager {
|
|||
|
||||
fun createActiveCommand(historyId: String): Completable
|
||||
fun updateActiveCommand(): Maybe<PodEvent>
|
||||
fun observeNoActiveCommand(): Observable<PodEvent>
|
||||
fun maybeMarkActiveCommandFailed()
|
||||
|
||||
data class ActiveCommand(
|
||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
|||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
@ -182,16 +183,16 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
get() = podState.activeCommand
|
||||
|
||||
@Synchronized
|
||||
override fun createActiveCommand(historyId: String): Completable {
|
||||
return if (activeCommand == null) {
|
||||
override fun createActiveCommand(historyId: String) = Completable.create { source ->
|
||||
if (activeCommand == null) {
|
||||
podState.activeCommand = OmnipodDashPodStateManager.ActiveCommand(
|
||||
podState.messageSequenceNumber,
|
||||
createdRealtime = SystemClock.elapsedRealtime(),
|
||||
historyId = historyId
|
||||
)
|
||||
Completable.complete()
|
||||
source.onComplete()
|
||||
} else {
|
||||
Completable.error(
|
||||
source.onError(
|
||||
java.lang.IllegalStateException(
|
||||
"Trying to send a command " +
|
||||
"and the last command was not confirmed"
|
||||
|
@ -200,6 +201,22 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun observeNoActiveCommand(): Observable<PodEvent> {
|
||||
return Observable.defer {
|
||||
if (activeCommand == null) {
|
||||
Observable.empty()
|
||||
} else {
|
||||
Observable.error(
|
||||
java.lang.IllegalStateException(
|
||||
"Trying to send a command " +
|
||||
"and the last command was not confirmed"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun maybeMarkActiveCommandFailed() {
|
||||
podState.activeCommand?.run {
|
||||
|
|
Loading…
Reference in a new issue