From e467e9f7b6e91d7f0a25fd0047cad917b70e8d6f Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 4 Jul 2021 18:21:08 +0200 Subject: [PATCH] simplify observeNoActiveCommand --- .../pump/omnipod/dash/OmnipodDashPumpPlugin.kt | 5 ++++- .../driver/pod/state/OmnipodDashPodStateManager.kt | 3 ++- .../pod/state/OmnipodDashPodStateManagerImpl.kt | 11 ++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index df8f87a507..2e54cd7f3d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -1014,7 +1014,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(), diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index 3eeab834ad..ebf81c8de9 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -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 @@ -91,7 +92,7 @@ interface OmnipodDashPodStateManager { requestedBolus: Double? = null ): Single fun updateActiveCommand(): Maybe - fun observeNoActiveCommand(b: Boolean): Observable + fun observeNoActiveCommand(): Completable fun getCommandConfirmationFromState(): CommandConfirmationFromState fun createLastBolus(requestedUnits: Double, historyId: String, bolusType: DetailedBolusInfo.BolusType) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index 95df4367a7..f5de686b76 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -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 @@ -307,13 +308,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( } @Synchronized - override fun observeNoActiveCommand(check: Boolean): Observable { - 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"