fix injection crash

This commit is contained in:
Milos Kozak 2023-09-20 16:05:48 +02:00
parent 7cb27fced0
commit 26a07f2477
55 changed files with 139 additions and 195 deletions

View file

@ -1,14 +1,10 @@
package info.nightscout.core.constraints package info.nightscout.core.constraints
import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import javax.inject.Inject
class ConstraintObject<T : Comparable<T>>(private var value: T, injector: HasAndroidInjector) : Constraint<T> { class ConstraintObject<T : Comparable<T>>(private var value: T, private val aapsLogger: AAPSLogger) : Constraint<T> {
@Inject lateinit var aapsLogger: AAPSLogger
private var originalValue: T private var originalValue: T
private val reasons: MutableList<String> = ArrayList() private val reasons: MutableList<String> = ArrayList()
@ -115,7 +111,6 @@ class ConstraintObject<T : Comparable<T>>(private var value: T, injector: HasAnd
} }
init { init {
injector.androidInjector().inject(this)
originalValue = value originalValue = value
} }
} }

View file

@ -272,7 +272,7 @@ class BolusWizard @Inject constructor(
val bolusStep = activePlugin.activePump.pumpDescription.bolusStep val bolusStep = activePlugin.activePump.pumpDescription.bolusStep
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep) calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep)
insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(calculatedTotalInsulin, injector)).value() insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(calculatedTotalInsulin, aapsLogger)).value()
aapsLogger.debug(this.toString()) aapsLogger.debug(this.toString())
return this return this

View file

@ -13,16 +13,10 @@ import org.junit.jupiter.api.Test
*/ */
class ConstraintTest : TestBase() { class ConstraintTest : TestBase() {
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
@Test fun doTests() { @Test fun doTests() {
val b = ConstraintObject(true, injector) val b = ConstraintObject(false, aapsLogger)
Assertions.assertEquals(true, b.value()) Assertions.assertEquals(true, b.value())
Assertions.assertEquals("", b.getReasons()) Assertions.assertEquals("", b.getReasons())
Assertions.assertEquals("", b.getMostLimitedReasons()) Assertions.assertEquals("", b.getMostLimitedReasons())
@ -38,7 +32,7 @@ class ConstraintTest : TestBase() {
Assertions.assertEquals(false, b.value()) Assertions.assertEquals(false, b.value())
Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons()) Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons())
Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons()) Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getMostLimitedReasons())
val d = ConstraintObject(10.0, injector) val d = ConstraintObject(10.0, aapsLogger)
d.set(5.0, "Set 5d", this) d.set(5.0, "Set 5d", this)
Assertions.assertEquals(5.0, d.value(), 0.01) Assertions.assertEquals(5.0, d.value(), 0.01)
Assertions.assertEquals("ConstraintTest: Set 5d", d.getReasons()) Assertions.assertEquals("ConstraintTest: Set 5d", d.getReasons())

View file

@ -310,8 +310,8 @@ class CommandQueueImplementation @Inject constructor(
removeAll(type) removeAll(type)
} }
// apply constraints // apply constraints
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)).value() detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
detailedBolusInfo.carbs = constraintChecker.applyCarbsConstraints(ConstraintObject(detailedBolusInfo.carbs.toInt(), injector)).value().toDouble() detailedBolusInfo.carbs = constraintChecker.applyCarbsConstraints(ConstraintObject(detailedBolusInfo.carbs.toInt(), aapsLogger)).value().toDouble()
// add new command to queue // add new command to queue
if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) { if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) {
add(CommandSMBBolus(injector, detailedBolusInfo, callback)) add(CommandSMBBolus(injector, detailedBolusInfo, callback))
@ -368,7 +368,7 @@ class CommandQueueImplementation @Inject constructor(
} }
// remove all unfinished // remove all unfinished
removeAll(CommandType.TEMPBASAL) removeAll(CommandType.TEMPBASAL)
val rateAfterConstraints = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, injector), profile).value() val rateAfterConstraints = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, aapsLogger), profile).value()
// add new command to queue // add new command to queue
add(CommandTempBasalAbsolute(injector, rateAfterConstraints, durationInMinutes, enforceNew, profile, tbrType, callback)) add(CommandTempBasalAbsolute(injector, rateAfterConstraints, durationInMinutes, enforceNew, profile, tbrType, callback))
notifyAboutNewCommand() notifyAboutNewCommand()
@ -383,7 +383,7 @@ class CommandQueueImplementation @Inject constructor(
} }
// remove all unfinished // remove all unfinished
removeAll(CommandType.TEMPBASAL) removeAll(CommandType.TEMPBASAL)
val percentAfterConstraints = constraintChecker.applyBasalPercentConstraints(ConstraintObject(percent, injector), profile).value() val percentAfterConstraints = constraintChecker.applyBasalPercentConstraints(ConstraintObject(percent, aapsLogger), profile).value()
// add new command to queue // add new command to queue
add(CommandTempBasalPercent(injector, percentAfterConstraints, durationInMinutes, enforceNew, profile, tbrType, callback)) add(CommandTempBasalPercent(injector, percentAfterConstraints, durationInMinutes, enforceNew, profile, tbrType, callback))
notifyAboutNewCommand() notifyAboutNewCommand()
@ -396,7 +396,7 @@ class CommandQueueImplementation @Inject constructor(
callback?.result(executingNowError())?.run() callback?.result(executingNowError())?.run()
return false return false
} }
val rateAfterConstraints = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, injector)).value() val rateAfterConstraints = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
// remove all unfinished // remove all unfinished
removeAll(CommandType.EXTENDEDBOLUS) removeAll(CommandType.EXTENDEDBOLUS)
// add new command to queue // add new command to queue

View file

@ -88,9 +88,6 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
if (it is Command) { if (it is Command) {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
it.rh = rh it.rh = rh
@ -143,14 +140,14 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
) )
`when`(profileFunction.getProfile()).thenReturn(validProfile) `when`(profileFunction.getProfile()).thenReturn(validProfile)
val bolusConstraint = ConstraintObject(0.0, injector) val bolusConstraint = ConstraintObject(0.0, aapsLogger)
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(bolusConstraint) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(bolusConstraint)
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint) `when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint)
val carbsConstraint = ConstraintObject(0, injector) val carbsConstraint = ConstraintObject(0, aapsLogger)
`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(carbsConstraint) `when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(carbsConstraint)
val rateConstraint = ConstraintObject(0.0, injector) val rateConstraint = ConstraintObject(0.0, aapsLogger)
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint) `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint)
val percentageConstraint = ConstraintObject(0, injector) val percentageConstraint = ConstraintObject(0, aapsLogger)
`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint) `when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint)
`when`(rh.gs(info.nightscout.core.ui.R.string.connectiontimedout)).thenReturn("Connection timed out") `when`(rh.gs(info.nightscout.core.ui.R.string.connectiontimedout)).thenReturn("Connection timed out")
`when`(rh.gs(info.nightscout.core.ui.R.string.format_insulin_units)).thenReturn("%1\$.2f U") `when`(rh.gs(info.nightscout.core.ui.R.string.format_insulin_units)).thenReturn("%1\$.2f U")

View file

@ -34,9 +34,6 @@ class QueueThreadTest : TestBaseWithProfile() {
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
if (it is Command) { if (it is Command) {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
it.rh = rh it.rh = rh
@ -67,14 +64,14 @@ class QueueThreadTest : TestBaseWithProfile() {
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager) Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile) Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
val bolusConstraint = ConstraintObject(0.0, injector) val bolusConstraint = ConstraintObject(0.0, aapsLogger)
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(bolusConstraint) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(bolusConstraint)
Mockito.`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint) Mockito.`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint)
val carbsConstraint = ConstraintObject(0, injector) val carbsConstraint = ConstraintObject(0, aapsLogger)
Mockito.`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(carbsConstraint) Mockito.`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(carbsConstraint)
val rateConstraint = ConstraintObject(0.0, injector) val rateConstraint = ConstraintObject(0.0, aapsLogger)
Mockito.`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint) Mockito.`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint)
val percentageConstraint = ConstraintObject(0, injector) val percentageConstraint = ConstraintObject(0, aapsLogger)
Mockito.`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())) Mockito.`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject()))
.thenReturn(percentageConstraint) .thenReturn(percentageConstraint)
Mockito.`when`(rh.gs(ArgumentMatchers.eq(info.nightscout.core.ui.R.string.temp_basal_absolute), anyObject(), anyObject())).thenReturn("TEMP BASAL %1\$.2f U/h %2\$d min") Mockito.`when`(rh.gs(ArgumentMatchers.eq(info.nightscout.core.ui.R.string.temp_basal_absolute), anyObject(), anyObject())).thenReturn("TEMP BASAL %1\$.2f U/h %2\$d min")

View file

@ -152,7 +152,7 @@ class LoopFragment : DaggerFragment(), MenuProvider {
var constraints = var constraints =
it.constraintsProcessed?.let { constraintsProcessed -> it.constraintsProcessed?.let { constraintsProcessed ->
val allConstraints = ConstraintObject(0.0, injector) val allConstraints = ConstraintObject(0.0, aapsLogger)
constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) } constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) }
constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) } constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) }
allConstraints.getMostLimitedReasons() allConstraints.getMostLimitedReasons()

View file

@ -275,11 +275,11 @@ class LoopPlugin @Inject constructor(
// check rate for constraints // check rate for constraints
val resultAfterConstraints = apsResult.newAndClone(injector) val resultAfterConstraints = apsResult.newAndClone(injector)
resultAfterConstraints.rateConstraint = ConstraintObject(resultAfterConstraints.rate, injector) resultAfterConstraints.rateConstraint = ConstraintObject(resultAfterConstraints.rate, aapsLogger)
resultAfterConstraints.rate = constraintChecker.applyBasalConstraints(resultAfterConstraints.rateConstraint!!, profile).value() resultAfterConstraints.rate = constraintChecker.applyBasalConstraints(resultAfterConstraints.rateConstraint!!, profile).value()
resultAfterConstraints.percentConstraint = ConstraintObject(resultAfterConstraints.percent, injector) resultAfterConstraints.percentConstraint = ConstraintObject(resultAfterConstraints.percent, aapsLogger)
resultAfterConstraints.percent = constraintChecker.applyBasalPercentConstraints(resultAfterConstraints.percentConstraint!!, profile).value() resultAfterConstraints.percent = constraintChecker.applyBasalPercentConstraints(resultAfterConstraints.percentConstraint!!, profile).value()
resultAfterConstraints.smbConstraint = ConstraintObject(resultAfterConstraints.smb, injector) resultAfterConstraints.smbConstraint = ConstraintObject(resultAfterConstraints.smb, aapsLogger)
resultAfterConstraints.smb = constraintChecker.applyBolusConstraints(resultAfterConstraints.smbConstraint!!).value() resultAfterConstraints.smb = constraintChecker.applyBolusConstraints(resultAfterConstraints.smbConstraint!!).value()
// safety check for multiple SMBs // safety check for multiple SMBs

View file

@ -116,7 +116,7 @@ class OpenAPSAMAPlugin @Inject constructor(
aapsLogger.debug(LTag.APS, rh.gs(R.string.openapsma_no_glucose_data)) aapsLogger.debug(LTag.APS, rh.gs(R.string.openapsma_no_glucose_data))
return return
} }
val inputConstraints = ConstraintObject(0.0, injector) // fake. only for collecting all results val inputConstraints = ConstraintObject(0.0, aapsLogger) // fake. only for collecting all results
val maxBasal = constraintChecker.getMaxBasalAllowed(profile).also { val maxBasal = constraintChecker.getMaxBasalAllowed(profile).also {
inputConstraints.copyReasons(it) inputConstraints.copyReasons(it)
}.value() }.value()

View file

@ -79,7 +79,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
var tddLast24H: Double? = null var tddLast24H: Double? = null
var tddLast4H: Double? = null var tddLast4H: Double? = null
var tddLast8to4H: Double? = null var tddLast8to4H: Double? = null
var dynIsfEnabled: Constraint<Boolean> = ConstraintObject(false, injector) var dynIsfEnabled: Constraint<Boolean> = ConstraintObject(false, aapsLogger)
// last values // last values
override var lastAPSRun: Long = 0 override var lastAPSRun: Long = 0
@ -131,7 +131,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
return return
} }
val inputConstraints = ConstraintObject(0.0, injector) // fake. only for collecting all results val inputConstraints = ConstraintObject(0.0, aapsLogger) // fake. only for collecting all results
val maxBasal = constraintChecker.getMaxBasalAllowed(profile).also { val maxBasal = constraintChecker.getMaxBasalAllowed(profile).also {
inputConstraints.copyReasons(it) inputConstraints.copyReasons(it)
}.value() }.value()
@ -209,19 +209,19 @@ open class OpenAPSSMBPlugin @Inject constructor(
val iobArray = iobCobCalculator.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget) val iobArray = iobCobCalculator.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget)
profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart) profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart)
startPart = System.currentTimeMillis() startPart = System.currentTimeMillis()
val smbAllowed = ConstraintObject(!tempBasalFallback, injector).also { val smbAllowed = ConstraintObject(!tempBasalFallback, aapsLogger).also {
constraintChecker.isSMBModeEnabled(it) constraintChecker.isSMBModeEnabled(it)
inputConstraints.copyReasons(it) inputConstraints.copyReasons(it)
} }
val advancedFiltering = ConstraintObject(!tempBasalFallback, injector).also { val advancedFiltering = ConstraintObject(!tempBasalFallback, aapsLogger).also {
constraintChecker.isAdvancedFilteringEnabled(it) constraintChecker.isAdvancedFilteringEnabled(it)
inputConstraints.copyReasons(it) inputConstraints.copyReasons(it)
} }
val uam = ConstraintObject(true, injector).also { val uam = ConstraintObject(false, aapsLogger).also {
constraintChecker.isUAMEnabled(it) constraintChecker.isUAMEnabled(it)
inputConstraints.copyReasons(it) inputConstraints.copyReasons(it)
} }
dynIsfEnabled = ConstraintObject(true, injector).also { dynIsfEnabled = ConstraintObject(false, aapsLogger).also {
constraintChecker.isDynIsfModeEnabled(it) constraintChecker.isDynIsfModeEnabled(it)
inputConstraints.copyReasons(it) inputConstraints.copyReasons(it)
} }
@ -241,12 +241,12 @@ open class OpenAPSSMBPlugin @Inject constructor(
if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null) { if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null) {
inputConstraints.copyReasons( inputConstraints.copyReasons(
ConstraintObject(false, injector).also { ConstraintObject(false, aapsLogger).also {
it.set(false, rh.gs(R.string.fallback_smb_no_tdd), this) it.set(false, rh.gs(R.string.fallback_smb_no_tdd), this)
} }
) )
inputConstraints.copyReasons( inputConstraints.copyReasons(
ConstraintObject(false, injector).apply { set(true, "tdd1D=$tdd1D tdd7D=$tdd7D tddLast4H=$tddLast4H tddLast8to4H=$tddLast8to4H tddLast24H=$tddLast24H", this) } ConstraintObject(false, aapsLogger).apply { set(true, "tdd1D=$tdd1D tdd7D=$tdd7D tddLast4H=$tddLast4H tddLast8to4H=$tddLast8to4H tddLast24H=$tddLast24H", this) }
) )
} }

View file

@ -22,13 +22,7 @@ class APSResultTest : TestBaseWithProfile() {
@Mock lateinit var constraintsChecker: ConstraintsChecker @Mock lateinit var constraintsChecker: ConstraintsChecker
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
private lateinit var closedLoopEnabled: Constraint<Boolean> private lateinit var closedLoopEnabled: Constraint<Boolean>
@ -336,7 +330,7 @@ class APSResultTest : TestBaseWithProfile() {
@BeforeEach @BeforeEach
fun prepare() { fun prepare() {
closedLoopEnabled = ConstraintObject(false, injector) closedLoopEnabled = ConstraintObject(false, aapsLogger)
`when`(constraintsChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled) `when`(constraintsChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled)
`when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0) `when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0)
`when`(profileFunction.getProfile()).thenReturn(validProfile) `when`(profileFunction.getProfile()).thenReturn(validProfile)

View file

@ -40,7 +40,7 @@ ActionsTestBase : TestBaseWithProfile() {
private var suspended = false private var suspended = false
override var lastRun: Loop.LastRun? = Loop.LastRun() override var lastRun: Loop.LastRun? = Loop.LastRun()
override var closedLoopEnabled: Constraint<Boolean>? = ConstraintObject(true, injector) override var closedLoopEnabled: Constraint<Boolean>? = ConstraintObject(false, aapsLogger)
override val isSuspended: Boolean = suspended override val isSuspended: Boolean = suspended
override val isLGS: Boolean = false override val isLGS: Boolean = false
override val isSuperBolus: Boolean = false override val isSuperBolus: Boolean = false
@ -169,9 +169,6 @@ ActionsTestBase : TestBaseWithProfile() {
it.rh = rh it.rh = rh
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
} }
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
} }
} }

View file

@ -1,22 +1,22 @@
package info.nightscout.plugins.constraints package info.nightscout.plugins.constraints
import dagger.android.HasAndroidInjector
import info.nightscout.core.constraints.ConstraintObject import info.nightscout.core.constraints.ConstraintObject
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.ConstraintsChecker import info.nightscout.interfaces.constraints.ConstraintsChecker
import info.nightscout.interfaces.constraints.PluginConstraints import info.nightscout.interfaces.constraints.PluginConstraints
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.rx.logging.AAPSLogger
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class ConstraintsCheckerImpl @Inject constructor( class ConstraintsCheckerImpl @Inject constructor(
private val activePlugin: ActivePlugin, private val activePlugin: ActivePlugin,
val injector: HasAndroidInjector private val aapsLogger: AAPSLogger
) : ConstraintsChecker { ) : ConstraintsChecker {
override fun isLoopInvocationAllowed(): Constraint<Boolean> = isLoopInvocationAllowed(ConstraintObject(true, injector)) override fun isLoopInvocationAllowed(): Constraint<Boolean> = isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> { override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -28,7 +28,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isClosedLoopAllowed(): Constraint<Boolean> = isClosedLoopAllowed(ConstraintObject(true, injector)) override fun isClosedLoopAllowed(): Constraint<Boolean> = isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> { override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -40,7 +40,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isLgsAllowed(): Constraint<Boolean> = isLgsAllowed(ConstraintObject(true, injector)) override fun isLgsAllowed(): Constraint<Boolean> = isLgsAllowed(ConstraintObject(true, aapsLogger))
override fun isLgsAllowed(value: Constraint<Boolean>): Constraint<Boolean> { override fun isLgsAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -52,7 +52,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isAutosensModeEnabled(): Constraint<Boolean> = isAutosensModeEnabled(ConstraintObject(true, injector)) override fun isAutosensModeEnabled(): Constraint<Boolean> = isAutosensModeEnabled(ConstraintObject(true, aapsLogger))
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -64,7 +64,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isSMBModeEnabled(): Constraint<Boolean> = isSMBModeEnabled(ConstraintObject(true, injector)) override fun isSMBModeEnabled(): Constraint<Boolean> = isSMBModeEnabled(ConstraintObject(true, aapsLogger))
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -76,7 +76,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isDynIsfModeEnabled(): Constraint<Boolean> = isDynIsfModeEnabled(ConstraintObject(true, injector)) override fun isDynIsfModeEnabled(): Constraint<Boolean> = isDynIsfModeEnabled(ConstraintObject(true, aapsLogger))
override fun isDynIsfModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isDynIsfModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -88,7 +88,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isUAMEnabled(): Constraint<Boolean> = isUAMEnabled(ConstraintObject(true, injector)) override fun isUAMEnabled(): Constraint<Boolean> = isUAMEnabled(ConstraintObject(true, aapsLogger))
override fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -100,7 +100,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isAdvancedFilteringEnabled(): Constraint<Boolean> = isAdvancedFilteringEnabled(ConstraintObject(true, injector)) override fun isAdvancedFilteringEnabled(): Constraint<Boolean> = isAdvancedFilteringEnabled(ConstraintObject(true, aapsLogger))
override fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -112,7 +112,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isSuperBolusEnabled(): Constraint<Boolean> = isSuperBolusEnabled(ConstraintObject(true, injector)) override fun isSuperBolusEnabled(): Constraint<Boolean> = isSuperBolusEnabled(ConstraintObject(true, aapsLogger))
override fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -124,7 +124,7 @@ class ConstraintsCheckerImpl @Inject constructor(
return value return value
} }
override fun isAutomationEnabled(): Constraint<Boolean> = isAutomationEnabled(ConstraintObject(true, injector)) override fun isAutomationEnabled(): Constraint<Boolean> = isAutomationEnabled(ConstraintObject(true, aapsLogger))
override fun applyBasalConstraints(absoluteRate: Constraint<Double>, profile: Profile): Constraint<Double> { override fun applyBasalConstraints(absoluteRate: Constraint<Double>, profile: Profile): Constraint<Double> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
@ -201,20 +201,20 @@ class ConstraintsCheckerImpl @Inject constructor(
*/ */
override fun getMaxBasalAllowed(profile: Profile): Constraint<Double> = override fun getMaxBasalAllowed(profile: Profile): Constraint<Double> =
applyBasalConstraints(ConstraintObject(Double.MAX_VALUE, injector), profile) applyBasalConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger), profile)
override fun getMaxBasalPercentAllowed(profile: Profile): Constraint<Int> = override fun getMaxBasalPercentAllowed(profile: Profile): Constraint<Int> =
applyBasalPercentConstraints(ConstraintObject(Int.MAX_VALUE, injector), profile) applyBasalPercentConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger), profile)
override fun getMaxBolusAllowed(): Constraint<Double> = override fun getMaxBolusAllowed(): Constraint<Double> =
applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector)) applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
override fun getMaxExtendedBolusAllowed(): Constraint<Double> = override fun getMaxExtendedBolusAllowed(): Constraint<Double> =
applyExtendedBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector)) applyExtendedBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
override fun getMaxCarbsAllowed(): Constraint<Int> = override fun getMaxCarbsAllowed(): Constraint<Int> =
applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, injector)) applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger))
override fun getMaxIOBAllowed(): Constraint<Double> = override fun getMaxIOBAllowed(): Constraint<Double> =
applyMaxIOBConstraints(ConstraintObject(Double.MAX_VALUE, injector)) applyMaxIOBConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
} }

View file

@ -6,6 +6,7 @@ import info.nightscout.interfaces.constraints.PluginConstraints
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.plugins.constraints.R import info.nightscout.plugins.constraints.R
import info.nightscout.rx.logging.AAPSLogger
import javax.inject.Inject import javax.inject.Inject
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -13,13 +14,14 @@ class Objective4(injector: HasAndroidInjector) : Objective(injector, "maxbasal",
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var aapsLogger: AAPSLogger
init { init {
tasks.add( tasks.add(
object : Task(this, R.string.objectives_maxbasal_gate) { object : Task(this, R.string.objectives_maxbasal_gate) {
override fun isCompleted(): Boolean { override fun isCompleted(): Boolean {
val profile = profileFunction.getProfile() ?: return false val profile = profileFunction.getProfile() ?: return false
val maxBasalSet = (activePlugin.activeAPS as PluginConstraints).applyBasalConstraints(ConstraintObject(Double.MAX_VALUE, injector), profile) val maxBasalSet = (activePlugin.activeAPS as PluginConstraints).applyBasalConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger), profile)
val maxDailyBasal = profile.getMaxDailyBasal() val maxDailyBasal = profile.getMaxDailyBasal()
return maxBasalSet.value() > 2.8 * maxDailyBasal return maxBasalSet.value() > 2.8 * maxDailyBasal
} }

View file

@ -4,6 +4,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.core.constraints.ConstraintObject import info.nightscout.core.constraints.ConstraintObject
import info.nightscout.plugins.constraints.R import info.nightscout.plugins.constraints.R
import info.nightscout.plugins.constraints.safety.SafetyPlugin import info.nightscout.plugins.constraints.safety.SafetyPlugin
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import javax.inject.Inject import javax.inject.Inject
@ -11,13 +12,14 @@ import javax.inject.Inject
class Objective5(injector: HasAndroidInjector) : Objective(injector, "maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate) { class Objective5(injector: HasAndroidInjector) : Objective(injector, "maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate) {
@Inject lateinit var safetyPlugin: SafetyPlugin @Inject lateinit var safetyPlugin: SafetyPlugin
@Inject lateinit var aapsLogger: AAPSLogger
init { init {
tasks.add(MinimumDurationTask(this, T.days(5).msecs())) tasks.add(MinimumDurationTask(this, T.days(5).msecs()))
tasks.add( tasks.add(
object : Task(this, R.string.closedmodeenabled) { object : Task(this, R.string.closedmodeenabled) {
override fun isCompleted(): Boolean { override fun isCompleted(): Boolean {
val closedLoopEnabled = ConstraintObject(true, injector) val closedLoopEnabled = ConstraintObject(false, aapsLogger)
safetyPlugin.isClosedLoopAllowed(closedLoopEnabled) safetyPlugin.isClosedLoopAllowed(closedLoopEnabled)
return closedLoopEnabled.value() return closedLoopEnabled.value()
} }

View file

@ -121,7 +121,7 @@ class SafetyPlugin @Inject constructor(
currentBasal currentBasal
) + " U/h", this ) + " U/h", this
) )
val absoluteConstraint = ConstraintObject(absoluteRate, injector) val absoluteConstraint = ConstraintObject(absoluteRate, aapsLogger)
applyBasalConstraints(absoluteConstraint, profile) applyBasalConstraints(absoluteConstraint, profile)
percentRate.copyReasons(absoluteConstraint) percentRate.copyReasons(absoluteConstraint)
val pump = activePlugin.activePump val pump = activePlugin.activePump

View file

@ -34,13 +34,7 @@ class BgQualityCheckPluginTest : TestBase() {
private lateinit var plugin: BgQualityCheckPlugin private lateinit var plugin: BgQualityCheckPlugin
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
private val now = 100000000L private val now = 100000000L
//private val autosensDataStore = AutosensDataStoreObject() //private val autosensDataStore = AutosensDataStoreObject()
@ -565,13 +559,13 @@ class BgQualityCheckPluginTest : TestBase() {
@Test @Test
fun applyMaxIOBConstraintsTest() { fun applyMaxIOBConstraintsTest() {
plugin.state = BgQualityCheck.State.UNKNOWN plugin.state = BgQualityCheck.State.UNKNOWN
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, injector)).value(), 0.001) Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
plugin.state = BgQualityCheck.State.FIVE_MIN_DATA plugin.state = BgQualityCheck.State.FIVE_MIN_DATA
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, injector)).value(), 0.001) Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
plugin.state = BgQualityCheck.State.RECALCULATED plugin.state = BgQualityCheck.State.RECALCULATED
Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, injector)).value(), 0.001) Assertions.assertEquals(10.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
plugin.state = BgQualityCheck.State.DOUBLED plugin.state = BgQualityCheck.State.DOUBLED
Assertions.assertEquals(0.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, injector)).value(), 0.001) Assertions.assertEquals(0.0, plugin.applyMaxIOBConstraints(ConstraintObject(10.0, aapsLogger)).value(), 0.001)
} }
} }

View file

@ -20,13 +20,6 @@ class StorageConstraintPluginTest : TestBase() {
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
@Mock lateinit var uiInteraction: UiInteraction @Mock lateinit var uiInteraction: UiInteraction
private val injector = HasAndroidInjector {
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
private lateinit var storageConstraintPlugin: StorageConstraintPlugin private lateinit var storageConstraintPlugin: StorageConstraintPlugin
@BeforeEach fun prepareMock() { @BeforeEach fun prepareMock() {
@ -49,9 +42,9 @@ class StorageConstraintPluginTest : TestBase() {
val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction) val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction)
// Set free space under 200(Mb) to disable loop // Set free space under 200(Mb) to disable loop
mocked.memSize = 150L mocked.memSize = 150L
Assertions.assertEquals(false, mocked.isClosedLoopAllowed(ConstraintObject(true, injector)).value()) Assertions.assertEquals(false, mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value())
// Set free space over 200(Mb) to enable loop // Set free space over 200(Mb) to enable loop
mocked.memSize = 300L mocked.memSize = 300L
Assertions.assertEquals(true, mocked.isClosedLoopAllowed(ConstraintObject(true, injector)).value()) Assertions.assertEquals(true, mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value())
} }
} }

View file

@ -516,7 +516,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE
val wizard = quickWizardEntry.doCalc(profile, profileName, actualBg) val wizard = quickWizardEntry.doCalc(profile, profileName, actualBg)
if (wizard.calculatedTotalInsulin > 0.0 && quickWizardEntry.carbs() > 0.0) { if (wizard.calculatedTotalInsulin > 0.0 && quickWizardEntry.carbs() > 0.0) {
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(quickWizardEntry.carbs(), injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(quickWizardEntry.carbs(), aapsLogger)).value()
activity?.let { activity?.let {
if (abs(wizard.insulinAfterConstraints - wizard.calculatedTotalInsulin) >= pump.pumpDescription.pumpType.determineCorrectBolusStepSize(wizard.insulinAfterConstraints) || carbsAfterConstraints != quickWizardEntry.carbs()) { if (abs(wizard.insulinAfterConstraints - wizard.calculatedTotalInsulin) >= pump.pumpDescription.pumpType.determineCorrectBolusStepSize(wizard.insulinAfterConstraints) || carbsAfterConstraints != quickWizardEntry.carbs()) {
OKDialog.show(it, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), rh.gs(R.string.constraints_violation) + "\n" + rh.gs(R.string.change_your_input)) OKDialog.show(it, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), rh.gs(R.string.constraints_violation) + "\n" + rh.gs(R.string.change_your_input))

View file

@ -732,7 +732,7 @@ class SmsCommunicatorPlugin @Inject constructor(
else if (tempBasalPct == 0 && divided[1] != "0%") sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) else if (tempBasalPct == 0 && divided[1] != "0%") sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format)))
else if (duration <= 0 || duration % durationStep != 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.sms_wrong_tbr_duration, durationStep))) else if (duration <= 0 || duration % durationStep != 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.sms_wrong_tbr_duration, durationStep)))
else { else {
tempBasalPct = constraintChecker.applyBasalPercentConstraints(ConstraintObject(tempBasalPct, injector), profile).value() tempBasalPct = constraintChecker.applyBasalPercentConstraints(ConstraintObject(tempBasalPct, aapsLogger), profile).value()
val passCode = generatePassCode() val passCode = generatePassCode()
val reply = rh.gs(R.string.smscommunicator_basal_pct_reply_with_code, tempBasalPct, duration, passCode) val reply = rh.gs(R.string.smscommunicator_basal_pct_reply_with_code, tempBasalPct, duration, passCode)
receivedSms.processed = true receivedSms.processed = true
@ -787,7 +787,7 @@ class SmsCommunicatorPlugin @Inject constructor(
else if (tempBasal == 0.0 && divided[1] != "0") sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) else if (tempBasal == 0.0 && divided[1] != "0") sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format)))
else if (duration <= 0 || duration % durationStep != 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.sms_wrong_tbr_duration, durationStep))) else if (duration <= 0 || duration % durationStep != 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.sms_wrong_tbr_duration, durationStep)))
else { else {
tempBasal = constraintChecker.applyBasalConstraints(ConstraintObject(tempBasal, injector), profile).value() tempBasal = constraintChecker.applyBasalConstraints(ConstraintObject(tempBasal, aapsLogger), profile).value()
val passCode = generatePassCode() val passCode = generatePassCode()
val reply = rh.gs(R.string.smscommunicator_basal_reply_with_code, tempBasal, duration, passCode) val reply = rh.gs(R.string.smscommunicator_basal_reply_with_code, tempBasal, duration, passCode)
receivedSms.processed = true receivedSms.processed = true
@ -864,7 +864,7 @@ class SmsCommunicatorPlugin @Inject constructor(
} else { } else {
var extended = SafeParse.stringToDouble(divided[1]) var extended = SafeParse.stringToDouble(divided[1])
val duration = SafeParse.stringToInt(divided[2]) val duration = SafeParse.stringToInt(divided[2])
extended = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(extended, injector)).value() extended = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(extended, aapsLogger)).value()
if (extended == 0.0 || duration == 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) if (extended == 0.0 || duration == 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format)))
else { else {
val passCode = generatePassCode() val passCode = generatePassCode()
@ -918,7 +918,7 @@ class SmsCommunicatorPlugin @Inject constructor(
private fun processBOLUS(divided: Array<String>, receivedSms: Sms) { private fun processBOLUS(divided: Array<String>, receivedSms: Sms) {
var bolus = SafeParse.stringToDouble(divided[1]) var bolus = SafeParse.stringToDouble(divided[1])
val isMeal = divided.size > 2 && divided[2].equals("MEAL", ignoreCase = true) val isMeal = divided.size > 2 && divided[2].equals("MEAL", ignoreCase = true)
bolus = constraintChecker.applyBolusConstraints(ConstraintObject(bolus, injector)).value() bolus = constraintChecker.applyBolusConstraints(ConstraintObject(bolus, aapsLogger)).value()
if (divided.size == 3 && !isMeal) { if (divided.size == 3 && !isMeal) {
sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format)))
} else if (bolus > 0.0) { } else if (bolus > 0.0) {
@ -1031,7 +1031,7 @@ class SmsCommunicatorPlugin @Inject constructor(
return return
} }
} }
grams = constraintChecker.applyCarbsConstraints(ConstraintObject(grams, injector)).value() grams = constraintChecker.applyCarbsConstraints(ConstraintObject(grams, aapsLogger)).value()
if (grams == 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) if (grams == 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format)))
else { else {
val passCode = generatePassCode() val passCode = generatePassCode()

View file

@ -269,7 +269,7 @@ class DataHandlerMobile @Inject constructor(
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribe({ .subscribe({
aapsLogger.debug(LTag.WEAR, "ActionFillConfirmed received $it from ${it.sourceNodeId}") aapsLogger.debug(LTag.WEAR, "ActionFillConfirmed received $it from ${it.sourceNodeId}")
if (constraintChecker.applyBolusConstraints(ConstraintObject(it.insulin, injector)).value() - it.insulin != 0.0) { if (constraintChecker.applyBolusConstraints(ConstraintObject(it.insulin, aapsLogger)).value() - it.insulin != 0.0) {
ToastUtils.showToastInUiThread(context, "aborting: previously applied constraint changed") ToastUtils.showToastInUiThread(context, "aborting: previously applied constraint changed")
sendError("aborting: previously applied constraint changed") sendError("aborting: previously applied constraint changed")
} else } else
@ -383,7 +383,7 @@ class DataHandlerMobile @Inject constructor(
return return
} }
val carbsBeforeConstraints = command.carbs val carbsBeforeConstraints = command.carbs
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbsBeforeConstraints, injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbsBeforeConstraints, aapsLogger)).value()
if (carbsAfterConstraints - carbsBeforeConstraints != 0) { if (carbsAfterConstraints - carbsBeforeConstraints != 0) {
sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_carbs_constraint)) sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_carbs_constraint))
return return
@ -480,7 +480,7 @@ class DataHandlerMobile @Inject constructor(
val wizard = quickWizardEntry.doCalc(profile, profileName, actualBg) val wizard = quickWizardEntry.doCalc(profile, profileName, actualBg)
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(quickWizardEntry.carbs(), injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(quickWizardEntry.carbs(), aapsLogger)).value()
if (carbsAfterConstraints != quickWizardEntry.carbs()) { if (carbsAfterConstraints != quickWizardEntry.carbs()) {
sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_carbs_constraint)) sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_carbs_constraint))
return return
@ -506,8 +506,8 @@ class DataHandlerMobile @Inject constructor(
} }
private fun handleBolusPreCheck(command: EventData.ActionBolusPreCheck) { private fun handleBolusPreCheck(command: EventData.ActionBolusPreCheck) {
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(command.insulin, injector)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(command.insulin, aapsLogger)).value()
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(command.carbs, injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(command.carbs, aapsLogger)).value()
val pump = activePlugin.activePump val pump = activePlugin.activePump
if (insulinAfterConstraints > 0 && (!pump.isInitialized() || pump.isSuspended() || loop.isDisconnected)) { if (insulinAfterConstraints > 0 && (!pump.isInitialized() || pump.isSuspended() || loop.isDisconnected)) {
sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_pump_not_available)) sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_pump_not_available))
@ -530,7 +530,7 @@ class DataHandlerMobile @Inject constructor(
private fun handleECarbsPreCheck(command: EventData.ActionECarbsPreCheck) { private fun handleECarbsPreCheck(command: EventData.ActionECarbsPreCheck) {
val startTimeStamp = System.currentTimeMillis() + T.mins(command.carbsTimeShift.toLong()).msecs() val startTimeStamp = System.currentTimeMillis() + T.mins(command.carbsTimeShift.toLong()).msecs()
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(command.carbs, injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(command.carbs, aapsLogger)).value()
var message = rh.gs(info.nightscout.core.ui.R.string.carbs) + ": " + carbsAfterConstraints + rh.gs(R.string.grams_short) + var message = rh.gs(info.nightscout.core.ui.R.string.carbs) + ": " + carbsAfterConstraints + rh.gs(R.string.grams_short) +
"\n" + rh.gs(info.nightscout.core.ui.R.string.time) + ": " + dateUtil.timeString(startTimeStamp) + "\n" + rh.gs(info.nightscout.core.ui.R.string.time) + ": " + dateUtil.timeString(startTimeStamp) +
"\n" + rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + command.duration + rh.gs(R.string.hour_short) "\n" + rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + command.duration + rh.gs(R.string.hour_short)
@ -558,7 +558,7 @@ class DataHandlerMobile @Inject constructor(
3 -> sp.getDouble("fill_button3", 0.0) 3 -> sp.getDouble("fill_button3", 0.0)
else -> return else -> return
} }
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value()
var message = rh.gs(info.nightscout.core.ui.R.string.prime_fill) + ": " + insulinAfterConstraints + rh.gs(R.string.units_short) var message = rh.gs(info.nightscout.core.ui.R.string.prime_fill) + ": " + insulinAfterConstraints + rh.gs(R.string.units_short)
if (insulinAfterConstraints - amount != 0.0) message += "\n" + rh.gs(info.nightscout.core.ui.R.string.constraint_applied) if (insulinAfterConstraints - amount != 0.0) message += "\n" + rh.gs(info.nightscout.core.ui.R.string.constraint_applied)
rxBus.send( rxBus.send(
@ -572,7 +572,7 @@ class DataHandlerMobile @Inject constructor(
} }
private fun handleFillPreCheck(command: EventData.ActionFillPreCheck) { private fun handleFillPreCheck(command: EventData.ActionFillPreCheck) {
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(command.insulin, injector)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(command.insulin, aapsLogger)).value()
var message = rh.gs(info.nightscout.core.ui.R.string.prime_fill) + ": " + insulinAfterConstraints + rh.gs(R.string.units_short) var message = rh.gs(info.nightscout.core.ui.R.string.prime_fill) + ": " + insulinAfterConstraints + rh.gs(R.string.units_short)
if (insulinAfterConstraints - command.insulin != 0.0) message += "\n" + rh.gs(info.nightscout.core.ui.R.string.constraint_applied) if (insulinAfterConstraints - command.insulin != 0.0) message += "\n" + rh.gs(info.nightscout.core.ui.R.string.constraint_applied)
rxBus.send( rxBus.send(

View file

@ -839,7 +839,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
smsCommunicatorPlugin.processSms(sms) smsCommunicatorPlugin.processSms(sms)
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BASAL 20% 20") assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BASAL 20% 20")
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("TBR duration must be a multiple of 30 minutes and greater than 0.") assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("TBR duration must be a multiple of 30 minutes and greater than 0.")
`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(20, injector)) `when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(20, aapsLogger))
//BASAL 20% 30 //BASAL 20% 30
smsCommunicatorPlugin.messages = ArrayList() smsCommunicatorPlugin.messages = ArrayList()
@ -865,7 +865,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
smsCommunicatorPlugin.processSms(sms) smsCommunicatorPlugin.processSms(sms)
assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BASAL 1 0") assertThat(smsCommunicatorPlugin.messages[0].text).isEqualTo("BASAL 1 0")
assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("TBR duration must be a multiple of 30 minutes and greater than 0.") assertThat(smsCommunicatorPlugin.messages[1].text).isEqualTo("TBR duration must be a multiple of 30 minutes and greater than 0.")
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(1.0, injector)) `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger))
//BASAL 1 20 //BASAL 1 20
smsCommunicatorPlugin.messages = ArrayList() smsCommunicatorPlugin.messages = ArrayList()

View file

@ -36,9 +36,6 @@ class ComboPluginTest : TestBase() {
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
if (it is PumpEnactResult) { if (it is PumpEnactResult) {
it.context = context it.context = context
} }
@ -58,7 +55,7 @@ class ComboPluginTest : TestBase() {
fun invalidBasalRateOnComboPumpShouldLimitLoopInvocation() { fun invalidBasalRateOnComboPumpShouldLimitLoopInvocation() {
comboPlugin.setPluginEnabled(PluginType.PUMP, true) comboPlugin.setPluginEnabled(PluginType.PUMP, true)
comboPlugin.setValidBasalRateProfileSelectedOnPump(false) comboPlugin.setValidBasalRateProfileSelectedOnPump(false)
val c = comboPlugin.isLoopInvocationAllowed(ConstraintObject(true, injector)) val c = comboPlugin.isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
Assertions.assertEquals("Combo: No valid basal rate read from pump", c.getReasons()) Assertions.assertEquals("Combo: No valid basal rate read from pump", c.getReasons())
Assertions.assertEquals(false, c.value()) Assertions.assertEquals(false, c.value())
comboPlugin.setPluginEnabled(PluginType.PUMP, false) comboPlugin.setPluginEnabled(PluginType.PUMP, false)

View file

@ -1014,7 +1014,7 @@ class ComboV2Plugin @Inject constructor(
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
.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)) .applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger))
.value() .value()
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, LTag.PUMP,

View file

@ -147,7 +147,7 @@ class DanaRKoreanPlugin @Inject constructor(
} }
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)).value() detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
require(detailedBolusInfo.carbs > 0) require(detailedBolusInfo.carbs > 0)
return if (detailedBolusInfo.insulin > 0) { return if (detailedBolusInfo.insulin > 0) {
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id) val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
@ -192,7 +192,7 @@ class DanaRKoreanPlugin @Inject constructor(
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: TemporaryBasalType): PumpEnactResult { override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: TemporaryBasalType): PumpEnactResult {
// Recheck pump status if older than 30 min // Recheck pump status if older than 30 min
//This should not be needed while using queue because connection should be done before calling this //This should not be needed while using queue because connection should be done before calling this
val absoluteRateAfterConstraint = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, injector), profile).value() val absoluteRateAfterConstraint = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, aapsLogger), profile).value()
var doTempOff = baseBasalRate - absoluteRateAfterConstraint == 0.0 && absoluteRateAfterConstraint >= 0.10 var doTempOff = baseBasalRate - absoluteRateAfterConstraint == 0.0 && absoluteRateAfterConstraint >= 0.10
val doLowTemp = absoluteRateAfterConstraint < baseBasalRate || absoluteRateAfterConstraint < 0.10 val doLowTemp = absoluteRateAfterConstraint < baseBasalRate || absoluteRateAfterConstraint < 0.10
val doHighTemp = absoluteRateAfterConstraint > baseBasalRate && !useExtendedBoluses val doHighTemp = absoluteRateAfterConstraint > baseBasalRate && !useExtendedBoluses
@ -266,7 +266,7 @@ class DanaRKoreanPlugin @Inject constructor(
val durationInHalfHours = max(durationInMinutes / 30, 1) val durationInHalfHours = max(durationInMinutes / 30, 1)
// We keep current basal running so need to sub current basal // We keep current basal running so need to sub current basal
var extendedRateToSet: Double = absoluteRateAfterConstraint - baseBasalRate var extendedRateToSet: Double = absoluteRateAfterConstraint - baseBasalRate
extendedRateToSet = constraintChecker.applyBasalConstraints(ConstraintObject(extendedRateToSet, injector), profile).value() extendedRateToSet = constraintChecker.applyBasalConstraints(ConstraintObject(extendedRateToSet, aapsLogger), profile).value()
// needs to be rounded to 0.1 // needs to be rounded to 0.1
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2) // *2 because of half hours extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2) // *2 because of half hours

View file

@ -159,7 +159,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
// Pump interface // Pump interface
@NonNull @Override @NonNull @Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new ConstraintObject<>(detailedBolusInfo.insulin, getInjector())).value(); detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new ConstraintObject<>(detailedBolusInfo.insulin, getAapsLogger())).value();
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
// v2 stores end time for bolus, we need to adjust time // v2 stores end time for bolus, we need to adjust time
// default delivery speed is 12 sec/U // default delivery speed is 12 sec/U
@ -224,7 +224,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
absoluteRate = constraintChecker.applyBasalConstraints(new ConstraintObject<>(absoluteRate, getInjector()), profile).value(); absoluteRate = constraintChecker.applyBasalConstraints(new ConstraintObject<>(absoluteRate, getAapsLogger()), profile).value();
boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d; boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d;
final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d; final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d;
@ -290,7 +290,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew, @NonNull PumpSync.TemporaryBasalType tbrType) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew, @NonNull PumpSync.TemporaryBasalType tbrType) {
DanaPump pump = danaPump; DanaPump pump = danaPump;
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
percent = constraintChecker.applyBasalPercentConstraints(new ConstraintObject<>(percent, getInjector()), profile).value(); percent = constraintChecker.applyBasalPercentConstraints(new ConstraintObject<>(percent, getAapsLogger()), profile).value();
if (percent < 0) { if (percent < 0) {
result.isTempCancel(false).enacted(false).success(false).comment(info.nightscout.core.ui.R.string.invalid_input); result.isTempCancel(false).enacted(false).success(false).comment(info.nightscout.core.ui.R.string.invalid_input);
aapsLogger.error("setTempBasalPercent: Invalid input"); aapsLogger.error("setTempBasalPercent: Invalid input");
@ -351,7 +351,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@NonNull @Override @NonNull @Override
public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
DanaPump pump = danaPump; DanaPump pump = danaPump;
insulin = constraintChecker.applyExtendedBolusConstraints(new ConstraintObject<>(insulin, getInjector())).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new ConstraintObject<>(insulin, getAapsLogger())).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep());

View file

@ -226,7 +226,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew, @NonNull PumpSync.TemporaryBasalType tbrType) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew, @NonNull PumpSync.TemporaryBasalType tbrType) {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
percent = constraintChecker.applyBasalPercentConstraints(new ConstraintObject<>(percent, getInjector()), profile).value(); percent = constraintChecker.applyBasalPercentConstraints(new ConstraintObject<>(percent, getAapsLogger()), profile).value();
if (percent < 0) { if (percent < 0) {
result.isTempCancel(false).enacted(false).success(false).comment(info.nightscout.core.ui.R.string.invalid_input); result.isTempCancel(false).enacted(false).success(false).comment(info.nightscout.core.ui.R.string.invalid_input);
getAapsLogger().error("setTempBasalPercent: Invalid input"); getAapsLogger().error("setTempBasalPercent: Invalid input");
@ -273,7 +273,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@NonNull @Override @NonNull @Override
public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
insulin = constraintChecker.applyExtendedBolusConstraints(new ConstraintObject<>(insulin, getInjector())).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new ConstraintObject<>(insulin, getAapsLogger())).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep());

View file

@ -160,7 +160,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
@NonNull @Override @NonNull @Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new ConstraintObject<>(detailedBolusInfo.insulin, getInjector())).value(); detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new ConstraintObject<>(detailedBolusInfo.insulin, getAapsLogger())).value();
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId()); EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId());
boolean connectionOK = false; boolean connectionOK = false;
@ -207,7 +207,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
//This should not be needed while using queue because connection should be done before calling this //This should not be needed while using queue because connection should be done before calling this
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
absoluteRate = constraintChecker.applyBasalConstraints(new ConstraintObject<>(absoluteRate, getInjector()), profile).value(); absoluteRate = constraintChecker.applyBasalConstraints(new ConstraintObject<>(absoluteRate, getAapsLogger()), profile).value();
boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d; boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d;
final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d; final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d;
@ -286,7 +286,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
// We keep current basal running so need to sub current basal // We keep current basal running so need to sub current basal
double extendedRateToSet = absoluteRate - getBaseBasalRate(); double extendedRateToSet = absoluteRate - getBaseBasalRate();
extendedRateToSet = constraintChecker.applyBasalConstraints(new ConstraintObject<>(extendedRateToSet, getInjector()), profile).value(); extendedRateToSet = constraintChecker.applyBasalConstraints(new ConstraintObject<>(extendedRateToSet, getAapsLogger()), profile).value();
// needs to be rounded to 0.1 // needs to be rounded to 0.1
extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet, pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet, pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours

View file

@ -12,7 +12,7 @@ class MsgBolusStart(
init { init {
setCommand(0x0102) setCommand(0x0102)
// HARDCODED LIMIT // HARDCODED LIMIT
amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value()
addParamInt((amount * 100).toInt()) addParamInt((amount * 100).toInt())
aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount") aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount")
} }

View file

@ -13,7 +13,7 @@ class MsgBolusStartWithSpeed(
init { init {
setCommand(0x0104) setCommand(0x0104)
// HARDCODED LIMIT // HARDCODED LIMIT
amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value()
addParamInt((amount * 100).toInt()) addParamInt((amount * 100).toInt())
addParamByte(speed.toByte()) addParamByte(speed.toByte())
aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount speed: $speed") aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount speed: $speed")

View file

@ -17,7 +17,7 @@ class MsgSetExtendedBolusStart(
// HARDCODED LIMITS // HARDCODED LIMITS
if (halfHours < 1) halfHours = 1 if (halfHours < 1) halfHours = 1
if (halfHours > 16) halfHours = 16 if (halfHours > 16) halfHours = 16
amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value()
addParamInt((amount * 100).toInt()) addParamInt((amount * 100).toInt())
addParamByte(halfHours) addParamByte(halfHours)
aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start: " + (amount * 100).toInt() / 100.0 + "U halfHours: " + halfHours.toInt()) aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start: " + (amount * 100).toInt() / 100.0 + "U halfHours: " + halfHours.toInt())

View file

@ -32,13 +32,7 @@ class DanaRPluginTest : TestBaseWithProfile() {
private lateinit var danaRPlugin: DanaRPlugin private lateinit var danaRPlugin: DanaRPlugin
val injector = HasAndroidInjector { val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
@BeforeEach @BeforeEach
fun prepareMocks() { fun prepareMocks() {
@ -60,7 +54,7 @@ class DanaRPluginTest : TestBaseWithProfile() {
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Double.MAX_VALUE, injector) val c = ConstraintObject(Double.MAX_VALUE, aapsLogger)
danaRPlugin.applyBasalConstraints(c, validProfile) danaRPlugin.applyBasalConstraints(c, validProfile)
Assertions.assertEquals(0.8, c.value(), 0.01) Assertions.assertEquals(0.8, c.value(), 0.01)
Assertions.assertEquals("DanaR: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons()) Assertions.assertEquals("DanaR: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons())
@ -72,7 +66,7 @@ class DanaRPluginTest : TestBaseWithProfile() {
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Int.MAX_VALUE, injector) val c = ConstraintObject(Int.MAX_VALUE, aapsLogger)
danaRPlugin.applyBasalPercentConstraints(c, validProfile) danaRPlugin.applyBasalPercentConstraints(c, validProfile)
Assertions.assertEquals(200, c.value()) Assertions.assertEquals(200, c.value())
Assertions.assertEquals("DanaR: Limiting max percent rate to 200% because of pump limit", c.getReasons()) Assertions.assertEquals("DanaR: Limiting max percent rate to 200% because of pump limit", c.getReasons())

View file

@ -9,7 +9,7 @@ import org.mockito.Mockito
class MessageHashTableRTest : DanaRTestBase() { class MessageHashTableRTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val messageHashTable = MessageHashTableR(injector) val messageHashTable = MessageHashTableR(injector)
val testMessage = messageHashTable.findMessage(0x41f2) val testMessage = messageHashTable.findMessage(0x41f2)
Assertions.assertEquals("CMD_HISTORY_ALL", testMessage.messageName) Assertions.assertEquals("CMD_HISTORY_ALL", testMessage.messageName)

View file

@ -9,7 +9,7 @@ import org.mockito.Mockito.`when`
class MsgBolusStartTest : DanaRTestBase() { class MsgBolusStartTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val packet = MsgBolusStart(injector, 1.0) val packet = MsgBolusStart(injector, 1.0)
// test message decoding // test message decoding

View file

@ -9,7 +9,7 @@ import org.mockito.Mockito
class MsgBolusStartWithSpeedTest : DanaRTestBase() { class MsgBolusStartWithSpeedTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val packet = MsgBolusStartWithSpeed(injector, 0.0, 0) val packet = MsgBolusStartWithSpeed(injector, 0.0, 0)
// test message decoding // test message decoding

View file

@ -9,7 +9,7 @@ import org.mockito.Mockito.`when`
class MsgSetExtendedBolusStartTest : DanaRTestBase() { class MsgSetExtendedBolusStartTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val packet = MsgSetExtendedBolusStart(injector, 2.0, 2.toByte()) val packet = MsgSetExtendedBolusStart(injector, 2.0, 2.toByte())
// test message decoding // test message decoding

View file

@ -32,13 +32,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() {
private lateinit var danaRPlugin: DanaRKoreanPlugin private lateinit var danaRPlugin: DanaRKoreanPlugin
val injector = HasAndroidInjector { val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
@BeforeEach @BeforeEach
fun prepareMocks() { fun prepareMocks() {
@ -60,7 +54,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() {
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Double.MAX_VALUE, injector) val c = ConstraintObject(Double.MAX_VALUE, aapsLogger)
danaRPlugin.applyBasalConstraints(c, validProfile) danaRPlugin.applyBasalConstraints(c, validProfile)
Assertions.assertEquals(0.8, c.value(), 0.01) Assertions.assertEquals(0.8, c.value(), 0.01)
Assertions.assertEquals("DanaRKorean: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons()) Assertions.assertEquals("DanaRKorean: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons())
@ -72,7 +66,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() {
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Int.MAX_VALUE, injector) val c = ConstraintObject(Int.MAX_VALUE, aapsLogger)
danaRPlugin.applyBasalPercentConstraints(c, validProfile) danaRPlugin.applyBasalPercentConstraints(c, validProfile)
Assertions.assertEquals(200, c.value()) Assertions.assertEquals(200, c.value())
Assertions.assertEquals("DanaRKorean: Limiting max percent rate to 200% because of pump limit", c.getReasons()) Assertions.assertEquals("DanaRKorean: Limiting max percent rate to 200% because of pump limit", c.getReasons())

View file

@ -10,7 +10,7 @@ import org.mockito.Mockito
class MessageHashTableRKoreanTest : DanaRTestBase() { class MessageHashTableRKoreanTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val messageHashTable = MessageHashTableRKorean(injector) val messageHashTable = MessageHashTableRKorean(injector)
val testMessage = messageHashTable.findMessage(0x41f2) val testMessage = messageHashTable.findMessage(0x41f2)
Assertions.assertEquals("CMD_HISTORY_ALL", testMessage.messageName) Assertions.assertEquals("CMD_HISTORY_ALL", testMessage.messageName)

View file

@ -36,13 +36,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() {
private lateinit var danaRv2Plugin: DanaRv2Plugin private lateinit var danaRv2Plugin: DanaRv2Plugin
val injector = HasAndroidInjector { val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is ConstraintObject<*>) {
it.aapsLogger = aapsLogger
}
}
}
@BeforeEach @BeforeEach
fun prepareMocks() { fun prepareMocks() {
@ -64,7 +58,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() {
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Double.MAX_VALUE, injector) val c = ConstraintObject(Double.MAX_VALUE, aapsLogger)
danaRv2Plugin.applyBasalConstraints(c, validProfile) danaRv2Plugin.applyBasalConstraints(c, validProfile)
Assertions.assertEquals(0.8, c.value(), 0.01) Assertions.assertEquals(0.8, c.value(), 0.01)
Assertions.assertEquals("DanaRv2: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons()) Assertions.assertEquals("DanaRv2: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons())
@ -76,7 +70,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() {
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Int.MAX_VALUE, injector) val c = ConstraintObject(Int.MAX_VALUE, aapsLogger)
danaRv2Plugin.applyBasalPercentConstraints(c, validProfile) danaRv2Plugin.applyBasalPercentConstraints(c, validProfile)
Assertions.assertEquals(200, c.value()) Assertions.assertEquals(200, c.value())
Assertions.assertEquals("DanaRv2: Limiting max percent rate to 200% because of pump limit", c.getReasons()) Assertions.assertEquals("DanaRv2: Limiting max percent rate to 200% because of pump limit", c.getReasons())

View file

@ -13,7 +13,7 @@ class MessageHashTableRv2Test : DanaRTestBase() {
@Test @Test
fun runTest() { fun runTest() {
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val messageHashTableRv2 = MessageHashTableRv2(injector) val messageHashTableRv2 = MessageHashTableRv2(injector)
val forTesting: MessageBase = MsgStatusAPS_v2(injector) val forTesting: MessageBase = MsgStatusAPS_v2(injector)
val testPacket: MessageBase = messageHashTableRv2.findMessage(forTesting.command) val testPacket: MessageBase = messageHashTableRv2.findMessage(forTesting.command)

View file

@ -288,7 +288,7 @@ class DanaRSPlugin @Inject constructor(
@Synchronized @Synchronized
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)).value() detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
val preferencesSpeed = sp.getInt(info.nightscout.pump.dana.R.string.key_danars_bolusspeed, 0) val preferencesSpeed = sp.getInt(info.nightscout.pump.dana.R.string.key_danars_bolusspeed, 0)
var speed = 12 var speed = 12
@ -343,7 +343,7 @@ class DanaRSPlugin @Inject constructor(
// This is called from APS // This is called from APS
@Synchronized @Synchronized
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult { override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult {
val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, injector), profile).value() val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, aapsLogger), profile).value()
var doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0 var doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0
val doLowTemp = absoluteAfterConstrain < baseBasalRate val doLowTemp = absoluteAfterConstrain < baseBasalRate
val doHighTemp = absoluteAfterConstrain > baseBasalRate val doHighTemp = absoluteAfterConstrain > baseBasalRate
@ -419,7 +419,7 @@ class DanaRSPlugin @Inject constructor(
@Synchronized @Synchronized
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult { override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
var percentAfterConstraint = constraintChecker.applyBasalPercentConstraints(ConstraintObject(percent, injector), profile).value() var percentAfterConstraint = constraintChecker.applyBasalPercentConstraints(ConstraintObject(percent, aapsLogger), profile).value()
if (percentAfterConstraint < 0) { if (percentAfterConstraint < 0) {
result.isTempCancel = false result.isTempCancel = false
result.enacted = false result.enacted = false
@ -489,7 +489,7 @@ class DanaRSPlugin @Inject constructor(
@Synchronized @Synchronized
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult { override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult {
var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, injector)).value() var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
// needs to be rounded // needs to be rounded
val durationInHalfHours = max(durationInMinutes / 30, 1) val durationInHalfHours = max(durationInMinutes / 30, 1)
insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep) insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep)

View file

@ -21,7 +21,7 @@ class DanaRSPacketBolusSetStepBolusStart(
opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START
// Speed 0 => 12 sec/U, 1 => 30 sec/U, 2 => 60 sec/U // Speed 0 => 12 sec/U, 1 => 30 sec/U, 2 => 60 sec/U
// HARDCODED LIMIT - if there is one that could be created // HARDCODED LIMIT - if there is one that could be created
amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value()
aapsLogger.debug(LTag.PUMPCOMM, "Bolus start : $amount speed: $speed") aapsLogger.debug(LTag.PUMPCOMM, "Bolus start : $amount speed: $speed")
} }

View file

@ -33,7 +33,7 @@ class DanaRSPluginTest : DanaRSTestBase() {
danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaRSPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaRSPlugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Double.MAX_VALUE, injector) val c = ConstraintObject(Double.MAX_VALUE, aapsLogger)
danaRSPlugin.applyBasalConstraints(c, validProfile) danaRSPlugin.applyBasalConstraints(c, validProfile)
Assertions.assertEquals(java.lang.Double.valueOf(0.8), c.value(), 0.0001) Assertions.assertEquals(java.lang.Double.valueOf(0.8), c.value(), 0.0001)
Assertions.assertEquals("DanaRS: limitingbasalratio", c.getReasons()) Assertions.assertEquals("DanaRS: limitingbasalratio", c.getReasons())
@ -45,7 +45,7 @@ class DanaRSPluginTest : DanaRSTestBase() {
danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaRSPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaRSPlugin.setPluginEnabled(PluginType.PUMP, true)
danaPump.maxBasal = 0.8 danaPump.maxBasal = 0.8
val c = ConstraintObject(Int.MAX_VALUE, injector) val c = ConstraintObject(Int.MAX_VALUE, aapsLogger)
danaRSPlugin.applyBasalPercentConstraints(c, validProfile) danaRSPlugin.applyBasalPercentConstraints(c, validProfile)
Assertions.assertEquals(200, c.value()) Assertions.assertEquals(200, c.value())
Assertions.assertEquals("DanaRS: limitingpercentrate", c.getReasons()) Assertions.assertEquals("DanaRS: limitingpercentrate", c.getReasons())

View file

@ -36,7 +36,7 @@ class DanaRsMessageHashTableTest : DanaRSTestBase() {
@Test @Test
fun runTest() { fun runTest() {
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
val danaRSMessageHashTable = DanaRSMessageHashTable(packetInjector) val danaRSMessageHashTable = DanaRSMessageHashTable(packetInjector)
val forTesting: DanaRSPacket = DanaRSPacketAPSSetEventHistory(packetInjector, DanaPump.HistoryEntry.CARBS.value, 0, 0, 0) val forTesting: DanaRSPacket = DanaRSPacketAPSSetEventHistory(packetInjector, DanaPump.HistoryEntry.CARBS.value, 0, 0, 0)

View file

@ -75,6 +75,6 @@ class DanaRsPacketBolusSetStepBolusStartTest : DanaRSTestBase() {
danaHistoryDatabase, danaHistoryDatabase,
decimalFormatter decimalFormatter
) )
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger))
} }
} }

View file

@ -271,7 +271,7 @@ class DiaconnG8Plugin @Inject constructor(
@Synchronized @Synchronized
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)).value() detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
val carbs = detailedBolusInfo.carbs val carbs = detailedBolusInfo.carbs
detailedBolusInfo.carbs = 0.0 detailedBolusInfo.carbs = 0.0
@ -310,7 +310,7 @@ class DiaconnG8Plugin @Inject constructor(
@Synchronized @Synchronized
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult { override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, injector), profile).value() val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, aapsLogger), profile).value()
val doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0 val doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0
val doLowTemp = absoluteAfterConstrain < baseBasalRate val doLowTemp = absoluteAfterConstrain < baseBasalRate
val doHighTemp = absoluteAfterConstrain > baseBasalRate val doHighTemp = absoluteAfterConstrain > baseBasalRate
@ -397,7 +397,7 @@ class DiaconnG8Plugin @Inject constructor(
@Synchronized @Synchronized
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult { override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult {
var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, injector)).value() var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
// needs to be rounded // needs to be rounded
insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep) insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep)
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)

View file

@ -348,7 +348,7 @@ import kotlin.math.abs
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
aapsLogger.debug(LTag.PUMP, "deliverTreatment: " + detailedBolusInfo.insulin + "U") aapsLogger.debug(LTag.PUMP, "deliverTreatment: " + detailedBolusInfo.insulin + "U")
if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false) if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false)
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)).value() detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
return if (detailedBolusInfo.insulin > 0 && detailedBolusInfo.carbs == 0.0) { return if (detailedBolusInfo.insulin > 0 && detailedBolusInfo.carbs == 0.0) {
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Delivering bolus: " + detailedBolusInfo.insulin + "U") aapsLogger.debug(LTag.PUMP, "deliverTreatment: Delivering bolus: " + detailedBolusInfo.insulin + "U")
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id) val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
@ -388,7 +388,7 @@ import kotlin.math.abs
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - absoluteRate: $absoluteRate, durationInMinutes: $durationInMinutes, enforceNew: $enforceNew") aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - absoluteRate: $absoluteRate, durationInMinutes: $durationInMinutes, enforceNew: $enforceNew")
// round rate to pump rate // round rate to pump rate
val pumpRate = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, injector), profile).value() val pumpRate = constraintChecker.applyBasalConstraints(ConstraintObject(absoluteRate, aapsLogger), profile).value()
temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), T.mins(durationInMinutes.toLong()).msecs(), pumpRate, true, tbrType, 0L, 0L)) temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), T.mins(durationInMinutes.toLong()).msecs(), pumpRate, true, tbrType, 0L, 0L))
val connectionOK = medtrumService?.setTempBasal(pumpRate, durationInMinutes) ?: false val connectionOK = medtrumService?.setTempBasal(pumpRate, durationInMinutes) ?: false
return if (connectionOK return if (connectionOK

View file

@ -227,7 +227,7 @@ class CarbsDialog : DialogFragmentWithDate() {
override fun submit(): Boolean { override fun submit(): Boolean {
if (_binding == null) return false if (_binding == null) return false
val carbs = binding.carbs.value.toInt() val carbs = binding.carbs.value.toInt()
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, aapsLogger)).value()
val units = profileUtil.units val units = profileUtil.units
val activityTTDuration = defaultValueHelper.determineActivityTTDuration() val activityTTDuration = defaultValueHelper.determineActivityTTDuration()
val activityTT = defaultValueHelper.determineActivityTT() val activityTT = defaultValueHelper.determineActivityTT()

View file

@ -96,7 +96,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
val insulin = SafeParse.stringToDouble(binding.insulin.text) val insulin = SafeParse.stringToDouble(binding.insulin.text)
val durationInMinutes = binding.duration.value.toInt() val durationInMinutes = binding.duration.value.toInt()
val actions: LinkedList<String> = LinkedList() val actions: LinkedList<String> = LinkedList()
val insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, injector)).value() val insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
actions.add(rh.gs(info.nightscout.core.ui.R.string.format_insulin_units, insulinAfterConstraint)) actions.add(rh.gs(info.nightscout.core.ui.R.string.format_insulin_units, insulinAfterConstraint))
actions.add(rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes)) actions.add(rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes))
if (abs(insulinAfterConstraint - insulin) > 0.01) if (abs(insulinAfterConstraint - insulin) > 0.01)

View file

@ -118,7 +118,7 @@ class FillDialog : DialogFragmentWithDate() {
val insulin = SafeParse.stringToDouble(binding.fillInsulinAmount.text) val insulin = SafeParse.stringToDouble(binding.fillInsulinAmount.text)
val actions: LinkedList<String?> = LinkedList() val actions: LinkedList<String?> = LinkedList()
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, injector)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
if (insulinAfterConstraints > 0) { if (insulinAfterConstraints > 0) {
actions.add(rh.gs(R.string.fill_warning)) actions.add(rh.gs(R.string.fill_warning))
actions.add("") actions.add("")

View file

@ -191,7 +191,7 @@ class InsulinDialog : DialogFragmentWithDate() {
if (_binding == null) return false if (_binding == null) return false
val pumpDescription = activePlugin.activePump.pumpDescription val pumpDescription = activePlugin.activePump.pumpDescription
val insulin = SafeParse.stringToDouble(binding.amount.text) val insulin = SafeParse.stringToDouble(binding.amount.text)
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, injector)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
val actions: LinkedList<String?> = LinkedList() val actions: LinkedList<String?> = LinkedList()
val units = profileFunction.getUnits() val units = profileFunction.getUnits()
val unitLabel = if (units == GlucoseUnit.MMOL) rh.gs(info.nightscout.core.ui.R.string.mmol) else rh.gs(info.nightscout.core.ui.R.string.mgdl) val unitLabel = if (units == GlucoseUnit.MMOL) rh.gs(info.nightscout.core.ui.R.string.mmol) else rh.gs(info.nightscout.core.ui.R.string.mgdl)

View file

@ -159,9 +159,9 @@ class LoopDialog : DaggerDialogFragment() {
if (_binding == null) return if (_binding == null) return
aapsLogger.debug("UpdateGUI from $from") aapsLogger.debug("UpdateGUI from $from")
val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription
val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(ConstraintObject(true, injector)) val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(ConstraintObject(true, aapsLogger))
val closedLoopAllowed2 = activePlugin.activeObjectives?.isAccomplished(Objectives.MAXIOB_OBJECTIVE) ?: false val closedLoopAllowed2 = activePlugin.activeObjectives?.isAccomplished(Objectives.MAXIOB_OBJECTIVE) ?: false
val lgsEnabled = constraintChecker.isLgsAllowed(ConstraintObject(true, injector)) val lgsEnabled = constraintChecker.isLgsAllowed(ConstraintObject(true, aapsLogger))
val apsMode = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) val apsMode = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
val pump = activePlugin.activePump val pump = activePlugin.activePump

View file

@ -120,13 +120,13 @@ class TempBasalDialog : DialogFragmentWithDate() {
val actions: LinkedList<String> = LinkedList() val actions: LinkedList<String> = LinkedList()
if (isPercentPump) { if (isPercentPump) {
val basalPercentInput = SafeParse.stringToInt(binding.basalPercentInput.text) val basalPercentInput = SafeParse.stringToInt(binding.basalPercentInput.text)
percent = constraintChecker.applyBasalPercentConstraints(ConstraintObject(basalPercentInput, injector), profile).value() percent = constraintChecker.applyBasalPercentConstraints(ConstraintObject(basalPercentInput, aapsLogger), profile).value()
actions.add(rh.gs(info.nightscout.core.ui.R.string.tempbasal_label) + ": $percent%") actions.add(rh.gs(info.nightscout.core.ui.R.string.tempbasal_label) + ": $percent%")
actions.add(rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes)) actions.add(rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes))
if (percent != basalPercentInput) actions.add(rh.gs(info.nightscout.core.ui.R.string.constraint_applied)) if (percent != basalPercentInput) actions.add(rh.gs(info.nightscout.core.ui.R.string.constraint_applied))
} else { } else {
val basalAbsoluteInput = SafeParse.stringToDouble(binding.basalAbsoluteInput.text) val basalAbsoluteInput = SafeParse.stringToDouble(binding.basalAbsoluteInput.text)
absolute = constraintChecker.applyBasalConstraints(ConstraintObject(basalAbsoluteInput, injector), profile).value() absolute = constraintChecker.applyBasalConstraints(ConstraintObject(basalAbsoluteInput, aapsLogger), profile).value()
actions.add(rh.gs(info.nightscout.core.ui.R.string.tempbasal_label) + ": " + rh.gs(info.nightscout.core.ui.R.string.pump_base_basal_rate, absolute)) actions.add(rh.gs(info.nightscout.core.ui.R.string.tempbasal_label) + ": " + rh.gs(info.nightscout.core.ui.R.string.pump_base_basal_rate, absolute))
actions.add(rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes)) actions.add(rh.gs(info.nightscout.core.ui.R.string.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes))
if (abs(absolute - basalAbsoluteInput) > 0.01) if (abs(absolute - basalAbsoluteInput) > 0.01)

View file

@ -138,8 +138,8 @@ class TreatmentDialog : DialogFragmentWithDate() {
val carbs = SafeParse.stringToInt(binding.carbs.text) val carbs = SafeParse.stringToInt(binding.carbs.text)
val recordOnlyChecked = binding.recordOnly.isChecked val recordOnlyChecked = binding.recordOnly.isChecked
val actions: LinkedList<String?> = LinkedList() val actions: LinkedList<String?> = LinkedList()
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, injector)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value()
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, injector)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, aapsLogger)).value()
if (insulinAfterConstraints > 0) { if (insulinAfterConstraints > 0) {
actions.add( actions.add(

View file

@ -444,7 +444,7 @@ class WizardDialog : DaggerDialogFragment() {
SafeParse.stringToDouble(binding.correctionInput.text) SafeParse.stringToDouble(binding.correctionInput.text)
} else } else
sp.getInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, 100).toDouble() sp.getInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, 100).toDouble()
val carbsAfterConstraint = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, injector)).value() val carbsAfterConstraint = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, aapsLogger)).value()
if (abs(carbs - carbsAfterConstraint) > 0.01) { if (abs(carbs - carbsAfterConstraint) > 0.01) {
binding.carbsInput.value = 0.0 binding.carbsInput.value = 0.0
ToastUtils.warnToast(ctx, R.string.carbs_constraint_applied) ToastUtils.warnToast(ctx, R.string.carbs_constraint_applied)