combov2: Store battery and reservoir levels as plain properties

This fixes https://github.com/dv1/AndroidAPS/issues/2

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-11-20 19:55:04 +01:00
parent 2bde0f154d
commit 8bef914eac

View file

@ -459,6 +459,7 @@ class ComboV2Plugin @Inject constructor (
)
pumpStatus = newPumpStatus
updateLevels()
// Send the EventRefreshOverview to keep the overview fragment's content
// up to date. Other actions like a CommandQueue.readStatus() call trigger
@ -725,20 +726,29 @@ class ComboV2Plugin @Inject constructor (
return activeBasalProfile?.get(currentHour)?.cctlBasalToIU() ?: 0.0
}
override val reservoirLevel: Double
get() = pumpStatus?.availableUnitsInReservoir?.toDouble() ?: 0.0
// Store the levels as plain properties. That way, the last reported
// levels are shown on the UI even when the driver connects to the
// pump again and resets the current pump state.
override val batteryLevel: Int
// The Combo does not provide any numeric battery
// level, so we have to use some reasonable values
// based on the indicated battery state.
get() = when (pumpStatus?.batteryState) {
null,
BatteryState.NO_BATTERY -> 5
BatteryState.LOW_BATTERY -> 25
BatteryState.FULL_BATTERY -> 100
override var reservoirLevel: Double = 0.0
private set
override var batteryLevel: Int = 0
private set
private fun updateLevels() {
pumpStatus?.availableUnitsInReservoir?.let {
reservoirLevel = it.toDouble()
}
pumpStatus?.batteryState?.let {
batteryLevel = when (it) {
BatteryState.NO_BATTERY -> 5
BatteryState.LOW_BATTERY -> 25
BatteryState.FULL_BATTERY -> 100
}
}
}
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
val oldInsulinAmount = detailedBolusInfo.insulin
detailedBolusInfo.insulin = constraintChecker