wip: stop connecting

This commit is contained in:
Andrei Vereha 2021-06-28 20:54:47 +02:00
parent 0582fe0326
commit b4777a1312
2 changed files with 22 additions and 5 deletions

View file

@ -48,8 +48,10 @@ import io.reactivex.Completable
import io.reactivex.Single
import org.json.JSONObject
import java.util.*
import java.util.concurrent.CountDownLatch
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.concurrent.thread
import kotlin.math.ceil
import kotlin.random.Random
@ -73,6 +75,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
private val handler: Handler = Handler(Looper.getMainLooper())
private lateinit var statusChecker: Runnable
var nextPodWarningCheck : Long = 0
@Volatile var stopConnecting: CountDownLatch? = null
companion object {
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
@ -171,19 +174,29 @@ class OmnipodDashPumpPlugin @Inject constructor(
}
override fun connect(reason: String) {
// empty on purpose
thread(
start = true,
name = "ConnectionThread",
) {
// TODO quadruple check that we are not creating a party of Threads here
try {
val stop = CountDownLatch(1)
stopConnecting = stop
omnipodManager.connect(stop)
} finally {
stopConnecting = null
}
}
}
override fun disconnect(reason: String) {
// TODO
omnipodManager.disconnect()
}
override fun stopConnecting() {
// TODO
stopConnecting?.let { it.countDown() }
}
override fun getPumpStatus(reason: String) {
aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason")
if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) {

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
import io.reactivex.Observable
import java.util.*
import java.util.concurrent.CountDownLatch
interface OmnipodDashManager {
@ -39,4 +40,7 @@ interface OmnipodDashManager {
fun silenceAlerts(alertTypes: EnumSet<AlertType>): Observable<PodEvent>
fun deactivatePod(): Observable<PodEvent>
fun disconnect()
fun connect(stop: CountDownLatch)
}