This commit is contained in:
Andrei Vereha 2021-06-29 19:46:11 +02:00
parent b4777a1312
commit 33891e509a
3 changed files with 28 additions and 4 deletions

View file

@ -156,12 +156,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
override fun isConnected(): Boolean { override fun isConnected(): Boolean {
return true return !podStateManager.isPodRunning ||
podStateManager.bluetoothConnectionState == OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED
} }
override fun isConnecting(): Boolean { override fun isConnecting(): Boolean {
// TODO // TODO
return false return stopConnecting != null
} }
override fun isHandshakeInProgress(): Boolean { override fun isHandshakeInProgress(): Boolean {
@ -182,7 +183,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
try { try {
val stop = CountDownLatch(1) val stop = CountDownLatch(1)
stopConnecting = stop stopConnecting = stop
omnipodManager.connect(stop) val error = omnipodManager.connect(stop).ignoreElements().blockingGet()
aapsLogger.info(LTag.PUMPCOMM, "connect error=$error")
} finally { } finally {
stopConnecting = null stopConnecting = null
} }
@ -190,6 +192,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
override fun disconnect(reason: String) { override fun disconnect(reason: String) {
stopConnecting?.let { it.countDown() }
omnipodManager.disconnect() omnipodManager.disconnect()
} }

View file

@ -42,5 +42,6 @@ interface OmnipodDashManager {
fun deactivatePod(): Observable<PodEvent> fun deactivatePod(): Observable<PodEvent>
fun disconnect() fun disconnect()
fun connect(stop: CountDownLatch)
fun connect(stop: CountDownLatch): Observable<PodEvent>
} }

View file

@ -15,6 +15,7 @@ import io.reactivex.Observable
import io.reactivex.functions.Action import io.reactivex.functions.Action
import io.reactivex.functions.Consumer import io.reactivex.functions.Consumer
import java.util.* import java.util.*
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -74,6 +75,25 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
} }
override fun disconnect() {
bleManager.disconnect()
}
override fun connect(stop: CountDownLatch): Observable<PodEvent> {
return observeConnectToPodWithStop(stop)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
private fun observeConnectToPodWithStop(stop: CountDownLatch): Observable<PodEvent> {
return Observable.defer {
bleManager.connect(stop)
.doOnError { throwable -> logger.warn(LTag.PUMPBTCOMM, "observeConnectToPodWithStop error=$throwable") }
}
}
private val observeConnectToPod: Observable<PodEvent> private val observeConnectToPod: Observable<PodEvent>
get() = Observable.defer { get() = Observable.defer {
bleManager.connect() bleManager.connect()