defer
This commit is contained in:
parent
3ef983b732
commit
3a2fa6d04f
|
@ -33,6 +33,7 @@ import io.reactivex.Observable
|
|||
import io.reactivex.Single
|
||||
import io.reactivex.rxkotlin.blockingSubscribeBy
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import io.reactivex.rxkotlin.toCompletable
|
||||
import org.json.JSONObject
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
@ -81,7 +82,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override fun isConnected(): Boolean {
|
||||
// TODO
|
||||
return true
|
||||
return podStateManager.activeCommand == null
|
||||
}
|
||||
|
||||
override fun isConnecting(): Boolean {
|
||||
|
@ -99,7 +100,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun connect(reason: String) {
|
||||
// TODO
|
||||
if (podStateManager.activeCommand == null) {
|
||||
return
|
||||
}
|
||||
getPumpStatus("unconfirmed command")
|
||||
}
|
||||
|
||||
override fun disconnect(reason: String) {
|
||||
|
@ -414,33 +418,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun playTestBeep(): PumpEnactResult {
|
||||
|
||||
return Single.create<PumpEnactResult> { source ->
|
||||
Observable.concat(
|
||||
omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP),
|
||||
history.updateFromState(podStateManager).toObservable(),
|
||||
podStateManager.updateActiveCommand().toObservable(),
|
||||
).subscribeBy(
|
||||
onNext = { podEvent ->
|
||||
aapsLogger.debug(
|
||||
LTag.PUMP,
|
||||
"Received PodEvent in playTestBeep: $podEvent"
|
||||
)
|
||||
},
|
||||
onError = { throwable ->
|
||||
aapsLogger.error(LTag.PUMP, "Error in playTestBeep", throwable)
|
||||
source.onSuccess(
|
||||
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
|
||||
)
|
||||
},
|
||||
onComplete = {
|
||||
aapsLogger.debug("playTestBeep completed")
|
||||
source.onSuccess(
|
||||
PumpEnactResult(injector).success(true).enacted(true)
|
||||
)
|
||||
}
|
||||
)
|
||||
}.blockingGet()
|
||||
return executeProgrammingCommand(
|
||||
history.createRecord(OmnipodCommandType.PLAY_TEST_BEEP),
|
||||
omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP)
|
||||
)
|
||||
}
|
||||
|
||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {
|
||||
|
|
|
@ -86,8 +86,10 @@ class Connection(
|
|||
val msgIO = MessageIO(aapsLogger, cmdBleIO, dataBleIO)
|
||||
|
||||
fun connect() {
|
||||
disconnect()
|
||||
|
||||
if (session!=null) {
|
||||
disconnect()
|
||||
}
|
||||
aapsLogger.debug("Connecting")
|
||||
if (!gattConnection.connect()) {
|
||||
throw FailedToConnectException("connect() returned false")
|
||||
}
|
||||
|
@ -167,6 +169,6 @@ class Connection(
|
|||
|
||||
companion object {
|
||||
|
||||
private const val CONNECT_TIMEOUT_MS = 7000
|
||||
private const val CONNECT_TIMEOUT_MS = 12000
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state
|
|||
|
||||
import android.os.SystemClock
|
||||
import com.google.gson.Gson
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
|
@ -19,6 +20,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
|||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Single
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
@ -201,16 +203,24 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
@Synchronized
|
||||
override fun updateActiveCommand(): Maybe<PodEvent> {
|
||||
return podState.activeCommand?.run {
|
||||
override fun updateActiveCommand() = Maybe.create<PodEvent> { source ->
|
||||
podState.activeCommand?.run {
|
||||
logger.debug(
|
||||
"Trying to confirm active command with parameters: $activeCommand " +
|
||||
"lastResponse=$lastStatusResponseReceived " +
|
||||
"$sequenceNumberOfLastProgrammingCommand $historyId"
|
||||
)
|
||||
if (createdRealtime >= lastStatusResponseReceived)
|
||||
Maybe.empty()
|
||||
else if (sequenceNumberOfLastProgrammingCommand == sequence)
|
||||
Maybe.just(PodEvent.CommandConfirmed(historyId))
|
||||
else
|
||||
Maybe.just(PodEvent.CommandDenied(historyId))
|
||||
source.onComplete()
|
||||
else {
|
||||
podState.activeCommand = null
|
||||
if (sequenceNumberOfLastProgrammingCommand == sequence)
|
||||
source.onSuccess(PodEvent.CommandConfirmed(historyId))
|
||||
else
|
||||
source.onSuccess(PodEvent.CommandDenied(historyId))
|
||||
}
|
||||
}
|
||||
?: Maybe.empty() // no active programming command
|
||||
?: source.onComplete() // no active programming command
|
||||
}
|
||||
|
||||
override fun increaseEapAkaSequenceNumber(): ByteArray {
|
||||
|
|
|
@ -74,8 +74,8 @@ class DashHistory @Inject constructor(
|
|||
|
||||
fun getRecordsAfter(time: Long): Single<List<HistoryRecordEntity>> = dao.allSince(time)
|
||||
|
||||
fun updateFromState(podState: OmnipodDashPodStateManager): Completable {
|
||||
return podState.activeCommand?.run {
|
||||
fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer {
|
||||
podState.activeCommand?.run {
|
||||
when {
|
||||
|
||||
createdRealtime <= podState.lastStatusResponseReceived &&
|
||||
|
|
Loading…
Reference in a new issue