From 16a2c8ea55c7e13da8b80fb549be865a23618d70 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sat, 12 Jun 2021 12:16:45 +0200 Subject: [PATCH] try different conn timeout. fix case when connection is established and session is null --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 21 ++++++------------- .../driver/comm/OmnipodDashBleManagerImpl.kt | 10 ++------- .../dash/driver/comm/session/Connection.kt | 2 +- 3 files changed, 9 insertions(+), 24 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 6767772bcc..f2b7c7a8c4 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 @@ -565,20 +565,6 @@ class OmnipodDashPumpPlugin @Inject constructor( } } - private fun observeActiveTempBasal(): Completable { - - return Completable.defer { - if (podStateManager.tempBasalActive || pumpSync.expectedPumpState().temporaryBasal != null) - Completable.complete() - else - Completable.error( - java.lang.IllegalStateException( - "There is no active basal to cancel" - ) - ) - } - } - override fun setTempBasalPercent( percent: Int, durationInMinutes: Int, @@ -598,10 +584,15 @@ class OmnipodDashPumpPlugin @Inject constructor( } override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { + if (!podStateManager.tempBasalActive && + pumpSync.expectedPumpState().temporaryBasal == null) { + // nothing to cancel + return PumpEnactResult(injector).success(true).enacted(false) + } + return executeProgrammingCommand( historyEntry = history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), command = omnipodManager.stopTempBasal().ignoreElements(), - pre = observeActiveTempBasal(), ).toPumpEnactResult() } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt index f0a73a3e2a..ce57f5b508 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt @@ -102,14 +102,8 @@ class OmnipodDashBleManagerImpl @Inject constructor( val conn = connection ?: Connection(podDevice, aapsLogger, context, podState) connection = conn - if (conn.connectionState() is Connected) { - if (conn.session == null) { - emitter.onNext(PodEvent.EstablishingSession) - establishSession(1.toByte()) - emitter.onNext(PodEvent.Connected) - } else { - emitter.onNext(PodEvent.AlreadyConnected(podAddress)) - } + if (conn.connectionState() is Connected && conn.session != null) { + emitter.onNext(PodEvent.AlreadyConnected(podAddress)) emitter.onComplete() return@create } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt index 7b8ff15cf7..98d4c9ff8c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt @@ -181,6 +181,6 @@ class Connection( } companion object { - private const val BASE_CONNECT_TIMEOUT_MS = 6000 + private const val BASE_CONNECT_TIMEOUT_MS = 10000 } }