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.data.BolusRecord
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.util.mapProfileToBasalProgram
import info.nightscout.androidaps.queue.commands.CustomCommand
@ -191,8 +192,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
detailedBolusInfo.insulin,
if (detailedBolusInfo.isSMB) BolusType.SMB else BolusType.DEFAULT
),
).flatMapObservable {
recordId ->
).flatMapObservable { recordId ->
podStateManager.createActiveCommand(recordId).toObservable()
},
omnipodManager.bolus(
@ -202,8 +202,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
),
history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(),
)
.subscribeBy(
).subscribeBy(
onNext = { podEvent ->
aapsLogger.debug(
LTag.PUMP,
@ -226,10 +225,18 @@ class OmnipodDashPumpPlugin @Inject constructor(
}
override fun stopBolusDelivering() {
// TODO history
// 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 ->
aapsLogger.debug(
LTag.PUMP,
@ -251,13 +258,22 @@ class OmnipodDashPumpPlugin @Inject constructor(
profile: Profile,
enforceNew: Boolean
): PumpEnactResult {
// TODO history
// TODO update Treatments
return Single.create<PumpEnactResult> { source ->
Observable.concat(
history.createRecord(
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(
onNext = { podEvent ->
aapsLogger.debug(
@ -298,11 +314,20 @@ class OmnipodDashPumpPlugin @Inject constructor(
}
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
// TODO history
// TODO update Treatments
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 ->
aapsLogger.debug(
LTag.PUMP,

View file

@ -4,7 +4,7 @@ sealed class 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 {
DEFAULT, SMB