add history, command confirmation for more commands

This commit is contained in:
Andrei Vereha 2021-04-18 21:54:50 +02:00
parent 842f196ae8
commit 142ad126b5
2 changed files with 55 additions and 30 deletions

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.Omn
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOverviewFragment import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOverviewFragment
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
import info.nightscout.androidaps.queue.commands.CustomCommand import info.nightscout.androidaps.queue.commands.CustomCommand
@ -191,8 +192,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
detailedBolusInfo.insulin, detailedBolusInfo.insulin,
if (detailedBolusInfo.isSMB) BolusType.SMB else BolusType.DEFAULT if (detailedBolusInfo.isSMB) BolusType.SMB else BolusType.DEFAULT
), ),
).flatMapObservable { ).flatMapObservable { recordId ->
recordId ->
podStateManager.createActiveCommand(recordId).toObservable() podStateManager.createActiveCommand(recordId).toObservable()
}, },
omnipodManager.bolus( omnipodManager.bolus(
@ -202,34 +202,41 @@ class OmnipodDashPumpPlugin @Inject constructor(
), ),
history.updateFromState(podStateManager).toObservable(), history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(), podStateManager.updateActiveCommand().toObservable(),
).subscribeBy(
onNext = { podEvent ->
aapsLogger.debug(
LTag.PUMP,
"Received PodEvent in deliverTreatment: $podEvent"
)
},
onError = { throwable ->
aapsLogger.error(LTag.PUMP, "Error in deliverTreatment", throwable)
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
},
onComplete = {
aapsLogger.debug("deliverTreatment completed")
source.onSuccess(
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin)
.carbsDelivered(detailedBolusInfo.carbs)
)
}
) )
.subscribeBy(
onNext = { podEvent ->
aapsLogger.debug(
LTag.PUMP,
"Received PodEvent in deliverTreatment: $podEvent"
)
},
onError = { throwable ->
aapsLogger.error(LTag.PUMP, "Error in deliverTreatment", throwable)
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
},
onComplete = {
aapsLogger.debug("deliverTreatment completed")
source.onSuccess(
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin)
.carbsDelivered(detailedBolusInfo.carbs)
)
}
)
}.blockingGet() }.blockingGet()
} }
override fun stopBolusDelivering() { override fun stopBolusDelivering() {
// TODO history
// TODO update Treatments (?) // TODO update Treatments (?)
omnipodManager.stopBolus().blockingSubscribeBy( Observable.concat(
history.createRecord(
commandType = OmnipodCommandType.CANCEL_BOLUS,
).flatMapObservable { recordId ->
podStateManager.createActiveCommand(recordId).toObservable()
},
omnipodManager.stopBolus(),
history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(),
).blockingSubscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, LTag.PUMP,
@ -251,13 +258,22 @@ class OmnipodDashPumpPlugin @Inject constructor(
profile: Profile, profile: Profile,
enforceNew: Boolean enforceNew: Boolean
): PumpEnactResult { ): PumpEnactResult {
// TODO history
// TODO update Treatments // TODO update Treatments
return Single.create<PumpEnactResult> { source -> return Single.create<PumpEnactResult> { source ->
omnipodManager.setTempBasal( Observable.concat(
absoluteRate, history.createRecord(
durationInMinutes.toShort() commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
tempBasalRecord = TempBasalRecord(duration = durationInMinutes, rate = absoluteRate)
).flatMapObservable { recordId ->
podStateManager.createActiveCommand(recordId).toObservable()
},
omnipodManager.setTempBasal(
absoluteRate,
durationInMinutes.toShort()
),
history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(),
).subscribeBy( ).subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
aapsLogger.debug( aapsLogger.debug(
@ -298,11 +314,20 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
// TODO history
// TODO update Treatments // TODO update Treatments
return Single.create<PumpEnactResult> { source -> return Single.create<PumpEnactResult> { source ->
omnipodManager.stopTempBasal().subscribeBy(
Observable.concat(
history.createRecord(
commandType = OmnipodCommandType.CANCEL_TEMPORARY_BASAL
).flatMapObservable { recordId ->
podStateManager.createActiveCommand(recordId).toObservable()
},
omnipodManager.stopTempBasal(),
history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(),
).subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, LTag.PUMP,

View file

@ -4,7 +4,7 @@ sealed class Record
data class BolusRecord(val amout: Double, val bolusType: BolusType) : Record() data class BolusRecord(val amout: Double, val bolusType: BolusType) : Record()
data class TempBasalRecord(val duration: Long, val rate: Double) : Record() data class TempBasalRecord(val duration: Int, val rate: Double) : Record()
enum class BolusType { enum class BolusType {
DEFAULT, SMB DEFAULT, SMB