updates for display of temp basal
This commit is contained in:
parent
fc919f24cd
commit
d0c947c988
2 changed files with 32 additions and 6 deletions
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
import info.nightscout.androidaps.events.EventProfileSwitchChanged
|
import info.nightscout.androidaps.events.EventProfileSwitchChanged
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange
|
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||||
import info.nightscout.androidaps.interfaces.*
|
import info.nightscout.androidaps.interfaces.*
|
||||||
|
@ -36,10 +37,14 @@ 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.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.functions.Consumer
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import io.reactivex.rxkotlin.subscribeBy
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -55,6 +60,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 disposable: CompositeDisposable = CompositeDisposable(),
|
||||||
|
// private val aapsSchedulers: AapsSchedulers,
|
||||||
|
|
||||||
injector: HasAndroidInjector,
|
injector: HasAndroidInjector,
|
||||||
aapsLogger: AAPSLogger,
|
aapsLogger: AAPSLogger,
|
||||||
|
@ -175,10 +182,17 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
)
|
)
|
||||||
rxBus.send(EventTempBasalChange())
|
rxBus.send(EventTempBasalChange())
|
||||||
}
|
}
|
||||||
.ignoreElements(),
|
.ignoreElements()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
private fun observeDeliverySuspended(): Completable = Completable.defer {
|
private fun observeDeliverySuspended(): Completable = Completable.defer {
|
||||||
if (podStateManager.deliveryStatus == DeliveryStatus.SUSPENDED)
|
if (podStateManager.deliveryStatus == DeliveryStatus.SUSPENDED)
|
||||||
Completable.complete()
|
Completable.complete()
|
||||||
|
@ -204,7 +218,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override val baseBasalRate: Double
|
override val baseBasalRate: Double
|
||||||
get() = podStateManager.basalProgram?.rateAt(Date()) ?: 0.0
|
get() {
|
||||||
|
val date = Date()
|
||||||
|
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
||||||
|
aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}")
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
override val reservoirLevel: Double
|
override val reservoirLevel: Double
|
||||||
get() {
|
get() {
|
||||||
|
@ -290,8 +309,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
tbrType: PumpSync.TemporaryBasalType
|
tbrType: PumpSync.TemporaryBasalType
|
||||||
): PumpEnactResult {
|
): PumpEnactResult {
|
||||||
val tempBasalBeeps = sp.getBoolean(R.string.key_omnipod_common_tbr_beeps_enabled, false)
|
val tempBasalBeeps = sp.getBoolean(R.string.key_omnipod_common_tbr_beeps_enabled, false)
|
||||||
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: $durationInMinutes min :: $absoluteRate U/h :: " +
|
aapsLogger.info(
|
||||||
"enforce: $enforceNew :: tbrType: $tbrType")
|
LTag.PUMP, "setTempBasalAbsolute: $durationInMinutes min :: $absoluteRate U/h :: " +
|
||||||
|
"enforce: $enforceNew :: tbrType: $tbrType"
|
||||||
|
)
|
||||||
return executeProgrammingCommand(
|
return executeProgrammingCommand(
|
||||||
historyEntry = history.createRecord(
|
historyEntry = history.createRecord(
|
||||||
commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
|
commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
|
||||||
|
@ -308,7 +329,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
pre = observeNoActiveTempBasal(enforceNew),
|
pre = observeNoActiveTempBasal(enforceNew),
|
||||||
tempBasal = OmnipodDashPodStateManager.TempBasal(
|
tempBasal = OmnipodDashPodStateManager.TempBasal(
|
||||||
startTime = System.currentTimeMillis(),
|
startTime = System.currentTimeMillis(),
|
||||||
rate=absoluteRate,
|
rate = absoluteRate,
|
||||||
durationInMinutes = durationInMinutes.toShort(),
|
durationInMinutes = durationInMinutes.toShort(),
|
||||||
)
|
)
|
||||||
).toPumpEnactResult()
|
).toPumpEnactResult()
|
||||||
|
@ -657,6 +678,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
PumpType.OMNIPOD_DASH,
|
PumpType.OMNIPOD_DASH,
|
||||||
serialNumber()
|
serialNumber()
|
||||||
)
|
)
|
||||||
|
podStateManager.tempBasal = null
|
||||||
}
|
}
|
||||||
|
|
||||||
OmnipodCommandType.SET_BASAL_PROFILE -> {
|
OmnipodCommandType.SET_BASAL_PROFILE -> {
|
||||||
|
@ -691,6 +713,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
OmnipodCommandType.SUSPEND_DELIVERY -> {
|
OmnipodCommandType.SUSPEND_DELIVERY -> {
|
||||||
if (!confirmation.success) {
|
if (!confirmation.success) {
|
||||||
pumpSync.invalidateTemporaryBasal(historyEntry.pumpId())
|
pumpSync.invalidateTemporaryBasal(historyEntry.pumpId())
|
||||||
|
} else {
|
||||||
|
podStateManager.tempBasal = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,11 +141,12 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
get() = podState.tempBasal
|
get() = podState.tempBasal
|
||||||
set(tempBasal) {
|
set(tempBasal) {
|
||||||
podState.tempBasal = tempBasal
|
podState.tempBasal = tempBasal
|
||||||
|
rxBus.send(EventOmnipodDashPumpValuesChanged())
|
||||||
store()
|
store()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val tempBasalActive: Boolean
|
override val tempBasalActive: Boolean
|
||||||
get() = tempBasal?.let {
|
get() = !isSuspended && tempBasal?.let {
|
||||||
it.startTime + it.durationInMinutes *60 * 1000 > System.currentTimeMillis()
|
it.startTime + it.durationInMinutes *60 * 1000 > System.currentTimeMillis()
|
||||||
} ?: false
|
} ?: false
|
||||||
|
|
||||||
|
@ -153,6 +154,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
get() = podState.basalProgram
|
get() = podState.basalProgram
|
||||||
set(basalProgram) {
|
set(basalProgram) {
|
||||||
podState.basalProgram = basalProgram
|
podState.basalProgram = basalProgram
|
||||||
|
rxBus.send(EventOmnipodDashPumpValuesChanged())
|
||||||
store()
|
store()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue