stop bolus

This commit is contained in:
Andrei Vereha 2021-06-06 13:43:44 +02:00
parent 4f459b9fc1
commit a25fffd075

View file

@ -36,11 +36,11 @@ import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.TimeChangeType import info.nightscout.androidaps.utils.TimeChangeType
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.rxkotlin.subscribeBy
import org.json.JSONObject import org.json.JSONObject
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -57,6 +57,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
private val history: DashHistory, private val history: DashHistory,
private val pumpSync: PumpSync, private val pumpSync: PumpSync,
private val rxBus: RxBusWrapper, private val rxBus: RxBusWrapper,
private val aapsSchedulers: AapsSchedulers,
// private val disposable: CompositeDisposable = CompositeDisposable(), // private val disposable: CompositeDisposable = CompositeDisposable(),
// private val aapsSchedulers: AapsSchedulers, // private val aapsSchedulers: AapsSchedulers,
@ -251,14 +253,14 @@ class OmnipodDashPumpPlugin @Inject constructor(
.enacted(false) .enacted(false)
.bolusDelivered(0.0) .bolusDelivered(0.0)
.carbsDelivered(0.0) .carbsDelivered(0.0)
.comment("Invalid input"); .comment("Invalid input")
} }
val requestedBolusAmount = detailedBolusInfo.insulin val requestedBolusAmount = detailedBolusInfo.insulin
var delieveredBolusAmount = 0.0 var delieveredBolusAmount = 0.0
aapsLogger.info( aapsLogger.info(
LTag.PUMP, LTag.PUMP,
"deliverTreatment: units: ${requestedBolusAmount}" "deliverTreatment: units: $requestedBolusAmount"
) )
return executeProgrammingCommand( return executeProgrammingCommand(
pre = observeNoActiveTempBasal(true), pre = observeNoActiveTempBasal(true),
@ -292,7 +294,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
val estimatedDeliveryTimeSeconds = ceil(requestedBolusAmount / 0.05).toLong() * 2 val estimatedDeliveryTimeSeconds = ceil(requestedBolusAmount / 0.05).toLong() * 2
aapsLogger.info(LTag.PUMP, "estimatedDeliveryTimeSeconds: $estimatedDeliveryTimeSeconds") aapsLogger.info(LTag.PUMP, "estimatedDeliveryTimeSeconds: $estimatedDeliveryTimeSeconds")
return Completable.concat(listOf( return Completable.concat(
listOf(
Observable.interval(1, TimeUnit.SECONDS) Observable.interval(1, TimeUnit.SECONDS)
.take(estimatedDeliveryTimeSeconds) .take(estimatedDeliveryTimeSeconds)
.doOnNext { .doOnNext {
@ -305,9 +308,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
progressUpdateEvent.percent = percent.toInt() progressUpdateEvent.percent = percent.toInt()
rxBus.send(progressUpdateEvent) rxBus.send(progressUpdateEvent)
}.ignoreElements(), }.ignoreElements(),
Observable.interval(5, TimeUnit.SECONDS).ignoreElements() Observable.interval(5, TimeUnit.SECONDS).take(1).ignoreElements()
// TODO check delivery status. for now, we are just sleeping for 5 sec // TODO check delivery status. for now, we are just sleeping for 5 sec
)) )
)
} }
private fun pumpSyncBolusStart( private fun pumpSyncBolusStart(
@ -342,7 +346,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
val ret = executeProgrammingCommand( val ret = executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.CANCEL_BOLUS), historyEntry = history.createRecord(OmnipodCommandType.CANCEL_BOLUS),
command = omnipodManager.stopBolus().ignoreElements() command = omnipodManager.stopBolus().ignoreElements()
).toPumpEnactResult() ).subscribeOn(aapsSchedulers.io) // stopBolusDelivering is executed on the main thread
.toPumpEnactResult()
aapsLogger.info(LTag.PUMP, "stopBolusDelivering finished with result: $ret") aapsLogger.info(LTag.PUMP, "stopBolusDelivering finished with result: $ret")
} }