simplify observeNoActiveCommand

This commit is contained in:
Andrei Vereha 2021-07-04 18:21:08 +02:00
parent a1d5b9eba6
commit 093d887f10
3 changed files with 12 additions and 7 deletions

View file

@ -836,7 +836,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
return Completable.concat(
listOf(
pre,
podStateManager.observeNoActiveCommand(checkNoActiveCommand).ignoreElements(),
if (checkNoActiveCommand)
podStateManager.observeNoActiveCommand()
else
Completable.complete(),
historyEntry
.flatMap { activeCommandEntry(it) }
.ignoreElement(),

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.SetUniqueIdResponse
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 io.reactivex.Single
@ -84,7 +85,7 @@ interface OmnipodDashPodStateManager {
requestedBolus: Double? = null
): Single<ActiveCommand>
fun updateActiveCommand(): Maybe<CommandConfirmed>
fun observeNoActiveCommand(b: Boolean): Observable<PodEvent>
fun observeNoActiveCommand(): Completable
fun getCommandConfirmationFromState(): CommandConfirmationFromState
fun createLastBolus(requestedUnits: Double, historyId: String, bolusType: DetailedBolusInfo.BolusType)

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.SetUniqueIdResponse
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Completable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single
@ -269,13 +270,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
}
@Synchronized
override fun observeNoActiveCommand(check: Boolean): Observable<PodEvent> {
return Observable.defer {
if (activeCommand == null || !check) {
Observable.empty()
override fun observeNoActiveCommand(): Completable {
return Completable.defer {
if (activeCommand == null) {
Completable.complete()
} else {
logger.warn(LTag.PUMP, "Active command already existing: $activeCommand")
Observable.error(
Completable.error(
java.lang.IllegalStateException(
"Trying to send a command " +
"and the last command was not confirmed"