Fix: turn APSResult.bolusRequested into a function.

Previously this var was set while parsing determine-basal output, setting it to true if determine-basal provided a value which was assigned to var smb. However, the variable smb is changed when constraints are applied, making the val bolusRequested invalid afterwards. Hence, dynamically evaluate the smb var by turning bolusRequested into a function.
This commit is contained in:
Johannes Mockenhaupt 2021-05-01 00:22:45 +02:00
parent 312136451b
commit dc2d64ceb7
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 6 additions and 8 deletions

View file

@ -403,7 +403,7 @@ open class LoopPlugin @Inject constructor(
val waiting = PumpEnactResult(injector) val waiting = PumpEnactResult(injector)
waiting.queued = true waiting.queued = true
if (resultAfterConstraints.tempBasalRequested) lastRun.tbrSetByPump = waiting if (resultAfterConstraints.tempBasalRequested) lastRun.tbrSetByPump = waiting
if (resultAfterConstraints.bolusRequested) lastRun.smbSetByPump = waiting if (resultAfterConstraints.bolusRequested()) lastRun.smbSetByPump = waiting
rxBus.send(EventLoopUpdateGui()) rxBus.send(EventLoopUpdateGui())
fabricPrivacy.logCustom("APSRequest") fabricPrivacy.logCustom("APSRequest")
applyTBRRequest(resultAfterConstraints, profile, object : Callback() { applyTBRRequest(resultAfterConstraints, profile, object : Callback() {
@ -600,7 +600,7 @@ open class LoopPlugin @Inject constructor(
} }
private fun applySMBRequest(request: APSResult, callback: Callback?) { private fun applySMBRequest(request: APSResult, callback: Callback?) {
if (!request.bolusRequested) { if (!request.bolusRequested()) {
return return
} }
val pump = activePlugin.activePump val pump = activePlugin.activePump

View file

@ -40,7 +40,6 @@ class DetermineBasalResultAMA private constructor(injector: HasAndroidInjector)
tempBasalRequested = false tempBasalRequested = false
} }
} }
bolusRequested = false
} }
override fun newAndClone(injector: HasAndroidInjector): DetermineBasalResultAMA { override fun newAndClone(injector: HasAndroidInjector): DetermineBasalResultAMA {

View file

@ -35,7 +35,6 @@ class DetermineBasalResultSMB private constructor(injector: HasAndroidInjector)
duration = -1 duration = -1
} }
if (result.has("units")) { if (result.has("units")) {
bolusRequested = true
smb = result.getDouble("units") smb = result.getDouble("units")
} else { } else {
smb = 0.0 smb = 0.0

View file

@ -48,7 +48,6 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
var usePercent = false var usePercent = false
var duration = 0 var duration = 0
var tempBasalRequested = false var tempBasalRequested = false
var bolusRequested = false
var iob: IobTotal? = null var iob: IobTotal? = null
var json: JSONObject? = JSONObject() var json: JSONObject? = JSONObject()
var hasPredictions = false var hasPredictions = false
@ -161,7 +160,6 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
newResult.rate = rate newResult.rate = rate
newResult.duration = duration newResult.duration = duration
newResult.tempBasalRequested = tempBasalRequested newResult.tempBasalRequested = tempBasalRequested
newResult.bolusRequested = bolusRequested
newResult.iob = iob newResult.iob = iob
newResult.json = JSONObject(json.toString()) newResult.json = JSONObject(json.toString())
newResult.hasPredictions = hasPredictions newResult.hasPredictions = hasPredictions
@ -309,11 +307,11 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
// closed loop mode: handle change at driver level // closed loop mode: handle change at driver level
if (closedLoopEnabled.value()) { if (closedLoopEnabled.value()) {
aapsLogger.debug(LTag.APS, "DEFAULT: Closed mode") aapsLogger.debug(LTag.APS, "DEFAULT: Closed mode")
return tempBasalRequested || bolusRequested return tempBasalRequested || bolusRequested()
} }
// open loop mode: try to limit request // open loop mode: try to limit request
if (!tempBasalRequested && !bolusRequested) { if (!tempBasalRequested && !bolusRequested()) {
aapsLogger.debug(LTag.APS, "FALSE: No request") aapsLogger.debug(LTag.APS, "FALSE: No request")
return false return false
} }
@ -399,4 +397,6 @@ open class APSResult @Inject constructor(val injector: HasAndroidInjector) {
} }
} }
} }
fun bolusRequested(): Boolean = smb > 0.0
} }