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 pumpStatus = newPumpStatus
updateLevels()
// Send the EventRefreshOverview to keep the overview fragment's content // Send the EventRefreshOverview to keep the overview fragment's content
// up to date. Other actions like a CommandQueue.readStatus() call trigger // 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 return activeBasalProfile?.get(currentHour)?.cctlBasalToIU() ?: 0.0
} }
override val reservoirLevel: Double // Store the levels as plain properties. That way, the last reported
get() = pumpStatus?.availableUnitsInReservoir?.toDouble() ?: 0.0 // 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 override var reservoirLevel: Double = 0.0
// The Combo does not provide any numeric battery private set
// level, so we have to use some reasonable values override var batteryLevel: Int = 0
// based on the indicated battery state. private set
get() = when (pumpStatus?.batteryState) {
null, private fun updateLevels() {
BatteryState.NO_BATTERY -> 5 pumpStatus?.availableUnitsInReservoir?.let {
BatteryState.LOW_BATTERY -> 25 reservoirLevel = it.toDouble()
BatteryState.FULL_BATTERY -> 100
} }
pumpStatus?.batteryState?.let {
batteryLevel = when (it) {
BatteryState.NO_BATTERY -> 5
BatteryState.LOW_BATTERY -> 25
BatteryState.FULL_BATTERY -> 100
}
}
}
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
val oldInsulinAmount = detailedBolusInfo.insulin val oldInsulinAmount = detailedBolusInfo.insulin
detailedBolusInfo.insulin = constraintChecker detailedBolusInfo.insulin = constraintChecker