diff --git a/core/main/src/main/java/info/nightscout/core/constraints/ConstraintObject.kt b/core/main/src/main/java/info/nightscout/core/constraints/ConstraintObject.kt index afda3ffa62..d7918e74e4 100644 --- a/core/main/src/main/java/info/nightscout/core/constraints/ConstraintObject.kt +++ b/core/main/src/main/java/info/nightscout/core/constraints/ConstraintObject.kt @@ -1,14 +1,10 @@ package info.nightscout.core.constraints -import dagger.android.HasAndroidInjector import info.nightscout.interfaces.constraints.Constraint import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag -import javax.inject.Inject -class ConstraintObject>(private var value: T, injector: HasAndroidInjector) : Constraint { - - @Inject lateinit var aapsLogger: AAPSLogger +class ConstraintObject>(private var value: T, private val aapsLogger: AAPSLogger) : Constraint { private var originalValue: T private val reasons: MutableList = ArrayList() @@ -115,7 +111,6 @@ class ConstraintObject>(private var value: T, injector: HasAnd } init { - injector.androidInjector().inject(this) originalValue = value } } \ No newline at end of file diff --git a/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt b/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt index 4bba468c45..03cb49cc62 100644 --- a/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt +++ b/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt @@ -272,7 +272,7 @@ class BolusWizard @Inject constructor( val bolusStep = activePlugin.activePump.pumpDescription.bolusStep calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep) - insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(calculatedTotalInsulin, injector)).value() + insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(calculatedTotalInsulin, aapsLogger)).value() aapsLogger.debug(this.toString()) return this diff --git a/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt b/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt index e961021203..0382107051 100644 --- a/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt +++ b/core/main/src/test/java/info/nightscout/core/data/ConstraintTest.kt @@ -13,16 +13,10 @@ import org.junit.jupiter.api.Test */ class ConstraintTest : TestBase() { - private val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } + private val injector = HasAndroidInjector { AndroidInjector { } } @Test fun doTests() { - val b = ConstraintObject(true, injector) + val b = ConstraintObject(false, aapsLogger) Assertions.assertEquals(true, b.value()) Assertions.assertEquals("", b.getReasons()) Assertions.assertEquals("", b.getMostLimitedReasons()) @@ -38,7 +32,7 @@ class ConstraintTest : TestBase() { Assertions.assertEquals(false, b.value()) Assertions.assertEquals("ConstraintTest: Set true\nConstraintTest: Set false", b.getReasons()) 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) Assertions.assertEquals(5.0, d.value(), 0.01) Assertions.assertEquals("ConstraintTest: Set 5d", d.getReasons()) diff --git a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt index 0a5fedafdd..be0d1cd620 100644 --- a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt @@ -310,8 +310,8 @@ class CommandQueueImplementation @Inject constructor( removeAll(type) } // apply constraints - detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)).value() - detailedBolusInfo.carbs = constraintChecker.applyCarbsConstraints(ConstraintObject(detailedBolusInfo.carbs.toInt(), injector)).value().toDouble() + detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value() + detailedBolusInfo.carbs = constraintChecker.applyCarbsConstraints(ConstraintObject(detailedBolusInfo.carbs.toInt(), aapsLogger)).value().toDouble() // add new command to queue if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) { add(CommandSMBBolus(injector, detailedBolusInfo, callback)) @@ -368,7 +368,7 @@ class CommandQueueImplementation @Inject constructor( } // remove all unfinished 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(CommandTempBasalAbsolute(injector, rateAfterConstraints, durationInMinutes, enforceNew, profile, tbrType, callback)) notifyAboutNewCommand() @@ -383,7 +383,7 @@ class CommandQueueImplementation @Inject constructor( } // remove all unfinished 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(CommandTempBasalPercent(injector, percentAfterConstraints, durationInMinutes, enforceNew, profile, tbrType, callback)) notifyAboutNewCommand() @@ -396,7 +396,7 @@ class CommandQueueImplementation @Inject constructor( callback?.result(executingNowError())?.run() return false } - val rateAfterConstraints = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, injector)).value() + val rateAfterConstraints = constraintChecker.applyExtendedBolusConstraints(ConstraintObject(insulin, aapsLogger)).value() // remove all unfinished removeAll(CommandType.EXTENDEDBOLUS) // add new command to queue diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt index dd3aff2fdc..b1654c2b1c 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt @@ -88,9 +88,6 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { private val injector = HasAndroidInjector { AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } if (it is Command) { it.aapsLogger = aapsLogger it.rh = rh @@ -143,14 +140,14 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { ) `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.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint) - val carbsConstraint = ConstraintObject(0, injector) + val carbsConstraint = ConstraintObject(0, aapsLogger) `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) - val percentageConstraint = ConstraintObject(0, injector) + val percentageConstraint = ConstraintObject(0, aapsLogger) `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.format_insulin_units)).thenReturn("%1\$.2f U") diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt index f765930172..ca01e108a2 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt @@ -34,9 +34,6 @@ class QueueThreadTest : TestBaseWithProfile() { private val injector = HasAndroidInjector { AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } if (it is Command) { it.aapsLogger = aapsLogger it.rh = rh @@ -67,14 +64,14 @@ class QueueThreadTest : TestBaseWithProfile() { Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager) 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.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint) - val carbsConstraint = ConstraintObject(0, injector) + val carbsConstraint = ConstraintObject(0, aapsLogger) 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) - val percentageConstraint = ConstraintObject(0, injector) + val percentageConstraint = ConstraintObject(0, aapsLogger) Mockito.`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())) .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") diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopFragment.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopFragment.kt index 1cd172046e..46221bad0d 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopFragment.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopFragment.kt @@ -152,7 +152,7 @@ class LoopFragment : DaggerFragment(), MenuProvider { var constraints = it.constraintsProcessed?.let { constraintsProcessed -> - val allConstraints = ConstraintObject(0.0, injector) + val allConstraints = ConstraintObject(0.0, aapsLogger) constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) } constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) } allConstraints.getMostLimitedReasons() diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt index 787938d90a..7b5eeec332 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt @@ -275,11 +275,11 @@ class LoopPlugin @Inject constructor( // check rate for constraints 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.percentConstraint = ConstraintObject(resultAfterConstraints.percent, injector) + resultAfterConstraints.percentConstraint = ConstraintObject(resultAfterConstraints.percent, aapsLogger) 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() // safety check for multiple SMBs diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index ae7e8192c3..04948aa6da 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -116,7 +116,7 @@ class OpenAPSAMAPlugin @Inject constructor( aapsLogger.debug(LTag.APS, rh.gs(R.string.openapsma_no_glucose_data)) 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 { inputConstraints.copyReasons(it) }.value() diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index 8c93012f07..7c48962884 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -79,7 +79,7 @@ open class OpenAPSSMBPlugin @Inject constructor( var tddLast24H: Double? = null var tddLast4H: Double? = null var tddLast8to4H: Double? = null - var dynIsfEnabled: Constraint = ConstraintObject(false, injector) + var dynIsfEnabled: Constraint = ConstraintObject(false, aapsLogger) // last values override var lastAPSRun: Long = 0 @@ -131,7 +131,7 @@ open class OpenAPSSMBPlugin @Inject constructor( 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 { inputConstraints.copyReasons(it) }.value() @@ -209,19 +209,19 @@ open class OpenAPSSMBPlugin @Inject constructor( val iobArray = iobCobCalculator.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget) profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart) startPart = System.currentTimeMillis() - val smbAllowed = ConstraintObject(!tempBasalFallback, injector).also { + val smbAllowed = ConstraintObject(!tempBasalFallback, aapsLogger).also { constraintChecker.isSMBModeEnabled(it) inputConstraints.copyReasons(it) } - val advancedFiltering = ConstraintObject(!tempBasalFallback, injector).also { + val advancedFiltering = ConstraintObject(!tempBasalFallback, aapsLogger).also { constraintChecker.isAdvancedFilteringEnabled(it) inputConstraints.copyReasons(it) } - val uam = ConstraintObject(true, injector).also { + val uam = ConstraintObject(false, aapsLogger).also { constraintChecker.isUAMEnabled(it) inputConstraints.copyReasons(it) } - dynIsfEnabled = ConstraintObject(true, injector).also { + dynIsfEnabled = ConstraintObject(false, aapsLogger).also { constraintChecker.isDynIsfModeEnabled(it) inputConstraints.copyReasons(it) } @@ -241,12 +241,12 @@ open class OpenAPSSMBPlugin @Inject constructor( if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null) { inputConstraints.copyReasons( - ConstraintObject(false, injector).also { + ConstraintObject(false, aapsLogger).also { it.set(false, rh.gs(R.string.fallback_smb_no_tdd), this) } ) 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) } ) } diff --git a/plugins/aps/src/test/java/info/nightscout/plugins/aps/loop/APSResultTest.kt b/plugins/aps/src/test/java/info/nightscout/plugins/aps/loop/APSResultTest.kt index 43e34c3038..939e85f1c7 100644 --- a/plugins/aps/src/test/java/info/nightscout/plugins/aps/loop/APSResultTest.kt +++ b/plugins/aps/src/test/java/info/nightscout/plugins/aps/loop/APSResultTest.kt @@ -22,13 +22,7 @@ class APSResultTest : TestBaseWithProfile() { @Mock lateinit var constraintsChecker: ConstraintsChecker - private val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } + private val injector = HasAndroidInjector { AndroidInjector { } } private lateinit var closedLoopEnabled: Constraint @@ -336,7 +330,7 @@ class APSResultTest : TestBaseWithProfile() { @BeforeEach fun prepare() { - closedLoopEnabled = ConstraintObject(false, injector) + closedLoopEnabled = ConstraintObject(false, aapsLogger) `when`(constraintsChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled) `when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0) `when`(profileFunction.getProfile()).thenReturn(validProfile) diff --git a/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt b/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt index 0976da4cc7..086d57b44f 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt @@ -40,7 +40,7 @@ ActionsTestBase : TestBaseWithProfile() { private var suspended = false override var lastRun: Loop.LastRun? = Loop.LastRun() - override var closedLoopEnabled: Constraint? = ConstraintObject(true, injector) + override var closedLoopEnabled: Constraint? = ConstraintObject(false, aapsLogger) override val isSuspended: Boolean = suspended override val isLGS: Boolean = false override val isSuperBolus: Boolean = false @@ -169,9 +169,6 @@ ActionsTestBase : TestBaseWithProfile() { it.rh = rh it.aapsLogger = aapsLogger } - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } } } diff --git a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/ConstraintsCheckerImpl.kt b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/ConstraintsCheckerImpl.kt index 09b1688ec8..527e9051b2 100644 --- a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/ConstraintsCheckerImpl.kt +++ b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/ConstraintsCheckerImpl.kt @@ -1,22 +1,22 @@ package info.nightscout.plugins.constraints -import dagger.android.HasAndroidInjector import info.nightscout.core.constraints.ConstraintObject import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.ConstraintsChecker import info.nightscout.interfaces.constraints.PluginConstraints import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.Profile +import info.nightscout.rx.logging.AAPSLogger import javax.inject.Inject import javax.inject.Singleton @Singleton class ConstraintsCheckerImpl @Inject constructor( private val activePlugin: ActivePlugin, - val injector: HasAndroidInjector + private val aapsLogger: AAPSLogger ) : ConstraintsChecker { - override fun isLoopInvocationAllowed(): Constraint = isLoopInvocationAllowed(ConstraintObject(true, injector)) + override fun isLoopInvocationAllowed(): Constraint = isLoopInvocationAllowed(ConstraintObject(true, aapsLogger)) override fun isLoopInvocationAllowed(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -28,7 +28,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isClosedLoopAllowed(): Constraint = isClosedLoopAllowed(ConstraintObject(true, injector)) + override fun isClosedLoopAllowed(): Constraint = isClosedLoopAllowed(ConstraintObject(true, aapsLogger)) override fun isClosedLoopAllowed(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -40,7 +40,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isLgsAllowed(): Constraint = isLgsAllowed(ConstraintObject(true, injector)) + override fun isLgsAllowed(): Constraint = isLgsAllowed(ConstraintObject(true, aapsLogger)) override fun isLgsAllowed(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -52,7 +52,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isAutosensModeEnabled(): Constraint = isAutosensModeEnabled(ConstraintObject(true, injector)) + override fun isAutosensModeEnabled(): Constraint = isAutosensModeEnabled(ConstraintObject(true, aapsLogger)) override fun isAutosensModeEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -64,7 +64,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isSMBModeEnabled(): Constraint = isSMBModeEnabled(ConstraintObject(true, injector)) + override fun isSMBModeEnabled(): Constraint = isSMBModeEnabled(ConstraintObject(true, aapsLogger)) override fun isSMBModeEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -76,7 +76,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isDynIsfModeEnabled(): Constraint = isDynIsfModeEnabled(ConstraintObject(true, injector)) + override fun isDynIsfModeEnabled(): Constraint = isDynIsfModeEnabled(ConstraintObject(true, aapsLogger)) override fun isDynIsfModeEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -88,7 +88,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isUAMEnabled(): Constraint = isUAMEnabled(ConstraintObject(true, injector)) + override fun isUAMEnabled(): Constraint = isUAMEnabled(ConstraintObject(true, aapsLogger)) override fun isUAMEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -100,7 +100,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isAdvancedFilteringEnabled(): Constraint = isAdvancedFilteringEnabled(ConstraintObject(true, injector)) + override fun isAdvancedFilteringEnabled(): Constraint = isAdvancedFilteringEnabled(ConstraintObject(true, aapsLogger)) override fun isAdvancedFilteringEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -112,7 +112,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isSuperBolusEnabled(): Constraint = isSuperBolusEnabled(ConstraintObject(true, injector)) + override fun isSuperBolusEnabled(): Constraint = isSuperBolusEnabled(ConstraintObject(true, aapsLogger)) override fun isSuperBolusEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -124,7 +124,7 @@ class ConstraintsCheckerImpl @Inject constructor( return value } - override fun isAutomationEnabled(): Constraint = isAutomationEnabled(ConstraintObject(true, injector)) + override fun isAutomationEnabled(): Constraint = isAutomationEnabled(ConstraintObject(true, aapsLogger)) override fun applyBasalConstraints(absoluteRate: Constraint, profile: Profile): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java) @@ -201,20 +201,20 @@ class ConstraintsCheckerImpl @Inject constructor( */ override fun getMaxBasalAllowed(profile: Profile): Constraint = - applyBasalConstraints(ConstraintObject(Double.MAX_VALUE, injector), profile) + applyBasalConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger), profile) override fun getMaxBasalPercentAllowed(profile: Profile): Constraint = - applyBasalPercentConstraints(ConstraintObject(Int.MAX_VALUE, injector), profile) + applyBasalPercentConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger), profile) override fun getMaxBolusAllowed(): Constraint = - applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector)) + applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger)) override fun getMaxExtendedBolusAllowed(): Constraint = - applyExtendedBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector)) + applyExtendedBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger)) override fun getMaxCarbsAllowed(): Constraint = - applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, injector)) + applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger)) override fun getMaxIOBAllowed(): Constraint = - applyMaxIOBConstraints(ConstraintObject(Double.MAX_VALUE, injector)) + applyMaxIOBConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger)) } \ No newline at end of file diff --git a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective4.kt b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective4.kt index 49c035bb2f..5081cbfbef 100644 --- a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective4.kt +++ b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective4.kt @@ -6,6 +6,7 @@ import info.nightscout.interfaces.constraints.PluginConstraints import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.plugins.constraints.R +import info.nightscout.rx.logging.AAPSLogger import javax.inject.Inject @Suppress("SpellCheckingInspection") @@ -13,13 +14,14 @@ class Objective4(injector: HasAndroidInjector) : Objective(injector, "maxbasal", @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var aapsLogger: AAPSLogger init { tasks.add( object : Task(this, R.string.objectives_maxbasal_gate) { override fun isCompleted(): Boolean { 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() return maxBasalSet.value() > 2.8 * maxDailyBasal } diff --git a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective5.kt b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective5.kt index 65dbe484e8..a540cc659a 100644 --- a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective5.kt +++ b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective5.kt @@ -4,6 +4,7 @@ import dagger.android.HasAndroidInjector import info.nightscout.core.constraints.ConstraintObject import info.nightscout.plugins.constraints.R import info.nightscout.plugins.constraints.safety.SafetyPlugin +import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.utils.T 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) { @Inject lateinit var safetyPlugin: SafetyPlugin + @Inject lateinit var aapsLogger: AAPSLogger init { tasks.add(MinimumDurationTask(this, T.days(5).msecs())) tasks.add( object : Task(this, R.string.closedmodeenabled) { override fun isCompleted(): Boolean { - val closedLoopEnabled = ConstraintObject(true, injector) + val closedLoopEnabled = ConstraintObject(false, aapsLogger) safetyPlugin.isClosedLoopAllowed(closedLoopEnabled) return closedLoopEnabled.value() } diff --git a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt index 1ce7e85d93..802110d7be 100644 --- a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt +++ b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt @@ -121,7 +121,7 @@ class SafetyPlugin @Inject constructor( currentBasal ) + " U/h", this ) - val absoluteConstraint = ConstraintObject(absoluteRate, injector) + val absoluteConstraint = ConstraintObject(absoluteRate, aapsLogger) applyBasalConstraints(absoluteConstraint, profile) percentRate.copyReasons(absoluteConstraint) val pump = activePlugin.activePump diff --git a/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt b/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt index 09e07728a2..a77eebc91c 100644 --- a/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt +++ b/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt @@ -34,13 +34,7 @@ class BgQualityCheckPluginTest : TestBase() { private lateinit var plugin: BgQualityCheckPlugin - private val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } + private val injector = HasAndroidInjector { AndroidInjector { } } private val now = 100000000L //private val autosensDataStore = AutosensDataStoreObject() @@ -565,13 +559,13 @@ class BgQualityCheckPluginTest : TestBase() { @Test fun applyMaxIOBConstraintsTest() { 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 - 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 - 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 - 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) } } \ No newline at end of file diff --git a/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt b/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt index 51c8a130c9..5d092d95da 100644 --- a/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt +++ b/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt @@ -20,13 +20,6 @@ class StorageConstraintPluginTest : TestBase() { @Mock lateinit var rh: ResourceHelper @Mock lateinit var uiInteraction: UiInteraction - private val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } private lateinit var storageConstraintPlugin: StorageConstraintPlugin @BeforeEach fun prepareMock() { @@ -49,9 +42,9 @@ class StorageConstraintPluginTest : TestBase() { val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction) // Set free space under 200(Mb) to disable loop 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 mocked.memSize = 300L - Assertions.assertEquals(true, mocked.isClosedLoopAllowed(ConstraintObject(true, injector)).value()) + Assertions.assertEquals(true, mocked.isClosedLoopAllowed(ConstraintObject(true, aapsLogger)).value()) } } \ No newline at end of file diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt index 10844c7306..ad9b39f4b7 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewFragment.kt @@ -516,7 +516,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE val wizard = quickWizardEntry.doCalc(profile, profileName, actualBg) 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 { 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)) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index ea6a505ea8..8d5ebf2b4d 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -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 (duration <= 0 || duration % durationStep != 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.sms_wrong_tbr_duration, durationStep))) else { - tempBasalPct = constraintChecker.applyBasalPercentConstraints(ConstraintObject(tempBasalPct, injector), profile).value() + tempBasalPct = constraintChecker.applyBasalPercentConstraints(ConstraintObject(tempBasalPct, aapsLogger), profile).value() val passCode = generatePassCode() val reply = rh.gs(R.string.smscommunicator_basal_pct_reply_with_code, tempBasalPct, duration, passCode) 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 (duration <= 0 || duration % durationStep != 0) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.sms_wrong_tbr_duration, durationStep))) else { - tempBasal = constraintChecker.applyBasalConstraints(ConstraintObject(tempBasal, injector), profile).value() + tempBasal = constraintChecker.applyBasalConstraints(ConstraintObject(tempBasal, aapsLogger), profile).value() val passCode = generatePassCode() val reply = rh.gs(R.string.smscommunicator_basal_reply_with_code, tempBasal, duration, passCode) receivedSms.processed = true @@ -864,7 +864,7 @@ class SmsCommunicatorPlugin @Inject constructor( } else { var extended = SafeParse.stringToDouble(divided[1]) 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))) else { val passCode = generatePassCode() @@ -918,7 +918,7 @@ class SmsCommunicatorPlugin @Inject constructor( private fun processBOLUS(divided: Array, receivedSms: Sms) { var bolus = SafeParse.stringToDouble(divided[1]) 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) { sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) } else if (bolus > 0.0) { @@ -1031,7 +1031,7 @@ class SmsCommunicatorPlugin @Inject constructor( 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))) else { val passCode = generatePassCode() diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt index 2cdfde27c6..5c96274d28 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -269,7 +269,7 @@ class DataHandlerMobile @Inject constructor( .observeOn(aapsSchedulers.io) .subscribe({ 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") sendError("aborting: previously applied constraint changed") } else @@ -383,7 +383,7 @@ class DataHandlerMobile @Inject constructor( return } val carbsBeforeConstraints = command.carbs - val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbsBeforeConstraints, injector)).value() + val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbsBeforeConstraints, aapsLogger)).value() if (carbsAfterConstraints - carbsBeforeConstraints != 0) { sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_carbs_constraint)) return @@ -480,7 +480,7 @@ class DataHandlerMobile @Inject constructor( 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()) { sendError(rh.gs(info.nightscout.core.ui.R.string.wizard_carbs_constraint)) return @@ -506,8 +506,8 @@ class DataHandlerMobile @Inject constructor( } private fun handleBolusPreCheck(command: EventData.ActionBolusPreCheck) { - val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(command.insulin, injector)).value() - val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(command.carbs, injector)).value() + val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(command.insulin, aapsLogger)).value() + val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(command.carbs, aapsLogger)).value() val pump = activePlugin.activePump if (insulinAfterConstraints > 0 && (!pump.isInitialized() || pump.isSuspended() || loop.isDisconnected)) { 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) { 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) + "\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) @@ -558,7 +558,7 @@ class DataHandlerMobile @Inject constructor( 3 -> sp.getDouble("fill_button3", 0.0) 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) if (insulinAfterConstraints - amount != 0.0) message += "\n" + rh.gs(info.nightscout.core.ui.R.string.constraint_applied) rxBus.send( @@ -572,7 +572,7 @@ class DataHandlerMobile @Inject constructor( } 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) if (insulinAfterConstraints - command.insulin != 0.0) message += "\n" + rh.gs(info.nightscout.core.ui.R.string.constraint_applied) rxBus.send( diff --git a/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index 825555b7c8..c997917c7d 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -839,7 +839,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) 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.") - `when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(20, injector)) + `when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(20, aapsLogger)) //BASAL 20% 30 smsCommunicatorPlugin.messages = ArrayList() @@ -865,7 +865,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) 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.") - `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(1.0, injector)) + `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(ConstraintObject(1.0, aapsLogger)) //BASAL 1 20 smsCommunicatorPlugin.messages = ArrayList() diff --git a/pump/combo/src/test/java/info/nightscout/pump/combo/ComboPluginTest.kt b/pump/combo/src/test/java/info/nightscout/pump/combo/ComboPluginTest.kt index dee5d1eb5b..bd74be68e6 100644 --- a/pump/combo/src/test/java/info/nightscout/pump/combo/ComboPluginTest.kt +++ b/pump/combo/src/test/java/info/nightscout/pump/combo/ComboPluginTest.kt @@ -36,9 +36,6 @@ class ComboPluginTest : TestBase() { private val injector = HasAndroidInjector { AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } if (it is PumpEnactResult) { it.context = context } @@ -58,7 +55,7 @@ class ComboPluginTest : TestBase() { fun invalidBasalRateOnComboPumpShouldLimitLoopInvocation() { comboPlugin.setPluginEnabled(PluginType.PUMP, true) 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(false, c.value()) comboPlugin.setPluginEnabled(PluginType.PUMP, false) diff --git a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt index b4029a24fd..7025448262 100644 --- a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt +++ b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt @@ -1014,7 +1014,7 @@ class ComboV2Plugin @Inject constructor( override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { val oldInsulinAmount = detailedBolusInfo.insulin detailedBolusInfo.insulin = constraintChecker - .applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, injector)) + .applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)) .value() aapsLogger.debug( LTag.PUMP, diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt index f6936bc825..c7dd9fd764 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt @@ -147,7 +147,7 @@ class DanaRKoreanPlugin @Inject constructor( } 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) return if (detailedBolusInfo.insulin > 0) { 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 { // Recheck pump status if older than 30 min //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 val doLowTemp = absoluteRateAfterConstraint < baseBasalRate || absoluteRateAfterConstraint < 0.10 val doHighTemp = absoluteRateAfterConstraint > baseBasalRate && !useExtendedBoluses @@ -266,7 +266,7 @@ class DanaRKoreanPlugin @Inject constructor( val durationInHalfHours = max(durationInMinutes / 30, 1) // We keep current basal running so need to sub current basal 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 extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2) // *2 because of half hours diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index 77b6cc0aa7..aa68441d5e 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -159,7 +159,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { // Pump interface @NonNull @Override 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) { // v2 stores end time for bolus, we need to adjust time // default delivery speed is 12 sec/U @@ -224,7 +224,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { 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; 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) { DanaPump pump = danaPump; 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) { result.isTempCancel(false).enacted(false).success(false).comment(info.nightscout.core.ui.R.string.invalid_input); aapsLogger.error("setTempBasalPercent: Invalid input"); @@ -351,7 +351,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { @NonNull @Override public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { DanaPump pump = danaPump; - insulin = constraintChecker.applyExtendedBolusConstraints(new ConstraintObject<>(insulin, getInjector())).value(); + insulin = constraintChecker.applyExtendedBolusConstraints(new ConstraintObject<>(insulin, getAapsLogger())).value(); // needs to be rounded int durationInHalfHours = Math.max(durationInMinutes / 30, 1); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java index 1304e70ca5..a5fd72ca69 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java @@ -226,7 +226,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump @NonNull @Override public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew, @NonNull PumpSync.TemporaryBasalType tbrType) { 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) { result.isTempCancel(false).enacted(false).success(false).comment(info.nightscout.core.ui.R.string.invalid_input); getAapsLogger().error("setTempBasalPercent: Invalid input"); @@ -273,7 +273,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump @NonNull @Override 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 int durationInHalfHours = Math.max(durationInMinutes / 30, 1); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index ff4d9873be..b240120c0a 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -160,7 +160,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { @NonNull @Override 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) { EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId()); 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 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; final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d; @@ -286,7 +286,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { int durationInHalfHours = Math.max(durationInMinutes / 30, 1); // We keep current basal running so need to sub current basal 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 extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet, pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStart.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStart.kt index 0049f5b93e..9bbf49311a 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStart.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStart.kt @@ -12,7 +12,7 @@ class MsgBolusStart( init { setCommand(0x0102) // HARDCODED LIMIT - amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() + amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value() addParamInt((amount * 100).toInt()) aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount") } diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStartWithSpeed.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStartWithSpeed.kt index 3a0c72d41a..fd91ea5cec 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStartWithSpeed.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgBolusStartWithSpeed.kt @@ -13,7 +13,7 @@ class MsgBolusStartWithSpeed( init { setCommand(0x0104) // HARDCODED LIMIT - amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() + amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value() addParamInt((amount * 100).toInt()) addParamByte(speed.toByte()) aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount speed: $speed") diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetExtendedBolusStart.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetExtendedBolusStart.kt index 9c1f1ed0bc..e91d4a1d8b 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetExtendedBolusStart.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetExtendedBolusStart.kt @@ -17,7 +17,7 @@ class MsgSetExtendedBolusStart( // HARDCODED LIMITS if (halfHours < 1) halfHours = 1 if (halfHours > 16) halfHours = 16 - amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, injector)).value() + amount = constraintChecker.applyBolusConstraints(ConstraintObject(amount, aapsLogger)).value() addParamInt((amount * 100).toInt()) addParamByte(halfHours) aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start: " + (amount * 100).toInt() / 100.0 + "U halfHours: " + halfHours.toInt()) diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaR/DanaRPluginTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaR/DanaRPluginTest.kt index 9f3585447a..d481c6797b 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaR/DanaRPluginTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaR/DanaRPluginTest.kt @@ -32,13 +32,7 @@ class DanaRPluginTest : TestBaseWithProfile() { private lateinit var danaRPlugin: DanaRPlugin - val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } + val injector = HasAndroidInjector { AndroidInjector { } } @BeforeEach fun prepareMocks() { @@ -60,7 +54,7 @@ class DanaRPluginTest : TestBaseWithProfile() { danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Double.MAX_VALUE, injector) + val c = ConstraintObject(Double.MAX_VALUE, aapsLogger) danaRPlugin.applyBasalConstraints(c, validProfile) 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()) @@ -72,7 +66,7 @@ class DanaRPluginTest : TestBaseWithProfile() { danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Int.MAX_VALUE, injector) + val c = ConstraintObject(Int.MAX_VALUE, aapsLogger) danaRPlugin.applyBasalPercentConstraints(c, validProfile) Assertions.assertEquals(200, c.value()) Assertions.assertEquals("DanaR: Limiting max percent rate to 200% because of pump limit", c.getReasons()) diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MessageHashTableRTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MessageHashTableRTest.kt index 83ac7c65e1..7b40464bec 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MessageHashTableRTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MessageHashTableRTest.kt @@ -9,7 +9,7 @@ import org.mockito.Mockito class MessageHashTableRTest : DanaRTestBase() { @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 testMessage = messageHashTable.findMessage(0x41f2) Assertions.assertEquals("CMD_HISTORY_ALL", testMessage.messageName) diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartTest.kt index daa4a0fb5a..2369557048 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartTest.kt @@ -9,7 +9,7 @@ import org.mockito.Mockito.`when` class MsgBolusStartTest : DanaRTestBase() { @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) // test message decoding diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartWithSpeedTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartWithSpeedTest.kt index 0493dc8b1e..6bbba7a377 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartWithSpeedTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgBolusStartWithSpeedTest.kt @@ -9,7 +9,7 @@ import org.mockito.Mockito class MsgBolusStartWithSpeedTest : DanaRTestBase() { @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) // test message decoding diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgSetExtendedBolusStartTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgSetExtendedBolusStartTest.kt index d881bd911e..ae76035dd2 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgSetExtendedBolusStartTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaR/comm/MsgSetExtendedBolusStartTest.kt @@ -9,7 +9,7 @@ import org.mockito.Mockito.`when` class MsgSetExtendedBolusStartTest : DanaRTestBase() { @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()) // test message decoding diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/DanaRKoreanPluginTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/DanaRKoreanPluginTest.kt index d843b7e67c..e32940b390 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/DanaRKoreanPluginTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/DanaRKoreanPluginTest.kt @@ -32,13 +32,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { private lateinit var danaRPlugin: DanaRKoreanPlugin - val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } + val injector = HasAndroidInjector { AndroidInjector { } } @BeforeEach fun prepareMocks() { @@ -60,7 +54,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Double.MAX_VALUE, injector) + val c = ConstraintObject(Double.MAX_VALUE, aapsLogger) danaRPlugin.applyBasalConstraints(c, validProfile) 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()) @@ -72,7 +66,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaRPlugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Int.MAX_VALUE, injector) + val c = ConstraintObject(Int.MAX_VALUE, aapsLogger) danaRPlugin.applyBasalPercentConstraints(c, validProfile) Assertions.assertEquals(200, c.value()) Assertions.assertEquals("DanaRKorean: Limiting max percent rate to 200% because of pump limit", c.getReasons()) diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt index 8b43ed6677..1e0b6c756b 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt @@ -10,7 +10,7 @@ import org.mockito.Mockito class MessageHashTableRKoreanTest : DanaRTestBase() { @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 testMessage = messageHashTable.findMessage(0x41f2) Assertions.assertEquals("CMD_HISTORY_ALL", testMessage.messageName) diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaRv2/DanaRv2PluginTest.kt b/pump/danar/src/test/java/info/nightscout/pump/danaRv2/DanaRv2PluginTest.kt index a95b45eef0..6f97ea681a 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaRv2/DanaRv2PluginTest.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaRv2/DanaRv2PluginTest.kt @@ -36,13 +36,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { private lateinit var danaRv2Plugin: DanaRv2Plugin - val injector = HasAndroidInjector { - AndroidInjector { - if (it is ConstraintObject<*>) { - it.aapsLogger = aapsLogger - } - } - } + val injector = HasAndroidInjector { AndroidInjector { } } @BeforeEach fun prepareMocks() { @@ -64,7 +58,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Double.MAX_VALUE, injector) + val c = ConstraintObject(Double.MAX_VALUE, aapsLogger) danaRv2Plugin.applyBasalConstraints(c, validProfile) 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()) @@ -76,7 +70,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Int.MAX_VALUE, injector) + val c = ConstraintObject(Int.MAX_VALUE, aapsLogger) danaRv2Plugin.applyBasalPercentConstraints(c, validProfile) Assertions.assertEquals(200, c.value()) Assertions.assertEquals("DanaRv2: Limiting max percent rate to 200% because of pump limit", c.getReasons()) diff --git a/pump/danar/src/test/java/info/nightscout/pump/danaRv2/comm/MessageHashTableRv2Test.kt b/pump/danar/src/test/java/info/nightscout/pump/danaRv2/comm/MessageHashTableRv2Test.kt index 94bfe539a4..2ac52af714 100644 --- a/pump/danar/src/test/java/info/nightscout/pump/danaRv2/comm/MessageHashTableRv2Test.kt +++ b/pump/danar/src/test/java/info/nightscout/pump/danaRv2/comm/MessageHashTableRv2Test.kt @@ -13,7 +13,7 @@ class MessageHashTableRv2Test : DanaRTestBase() { @Test 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 forTesting: MessageBase = MsgStatusAPS_v2(injector) val testPacket: MessageBase = messageHashTableRv2.findMessage(forTesting.command) diff --git a/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt b/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt index 89ce1b2430..04fb4c4012 100644 --- a/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt +++ b/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt @@ -288,7 +288,7 @@ class DanaRSPlugin @Inject constructor( @Synchronized 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) { val preferencesSpeed = sp.getInt(info.nightscout.pump.dana.R.string.key_danars_bolusspeed, 0) var speed = 12 @@ -343,7 +343,7 @@ class DanaRSPlugin @Inject constructor( // This is called from APS @Synchronized 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 val doLowTemp = absoluteAfterConstrain < baseBasalRate val doHighTemp = absoluteAfterConstrain > baseBasalRate @@ -419,7 +419,7 @@ class DanaRSPlugin @Inject constructor( @Synchronized override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult { 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) { result.isTempCancel = false result.enacted = false @@ -489,7 +489,7 @@ class DanaRSPlugin @Inject constructor( @Synchronized 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 val durationInHalfHours = max(durationInMinutes / 30, 1) insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep) diff --git a/pump/danars/src/main/java/info/nightscout/pump/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt b/pump/danars/src/main/java/info/nightscout/pump/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt index 7ded74eea2..dc9874df49 100644 --- a/pump/danars/src/main/java/info/nightscout/pump/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt +++ b/pump/danars/src/main/java/info/nightscout/pump/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt @@ -21,7 +21,7 @@ class DanaRSPacketBolusSetStepBolusStart( opCode = BleEncryption.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START // Speed 0 => 12 sec/U, 1 => 30 sec/U, 2 => 60 sec/U // 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") } diff --git a/pump/danars/src/test/java/info/nightscout/pump/danars/DanaRSPluginTest.kt b/pump/danars/src/test/java/info/nightscout/pump/danars/DanaRSPluginTest.kt index c2a9d6cc36..96a348c830 100644 --- a/pump/danars/src/test/java/info/nightscout/pump/danars/DanaRSPluginTest.kt +++ b/pump/danars/src/test/java/info/nightscout/pump/danars/DanaRSPluginTest.kt @@ -33,7 +33,7 @@ class DanaRSPluginTest : DanaRSTestBase() { danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Double.MAX_VALUE, injector) + val c = ConstraintObject(Double.MAX_VALUE, aapsLogger) danaRSPlugin.applyBasalConstraints(c, validProfile) Assertions.assertEquals(java.lang.Double.valueOf(0.8), c.value(), 0.0001) Assertions.assertEquals("DanaRS: limitingbasalratio", c.getReasons()) @@ -45,7 +45,7 @@ class DanaRSPluginTest : DanaRSTestBase() { danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) danaPump.maxBasal = 0.8 - val c = ConstraintObject(Int.MAX_VALUE, injector) + val c = ConstraintObject(Int.MAX_VALUE, aapsLogger) danaRSPlugin.applyBasalPercentConstraints(c, validProfile) Assertions.assertEquals(200, c.value()) Assertions.assertEquals("DanaRS: limitingpercentrate", c.getReasons()) diff --git a/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsMessageHashTableTest.kt b/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsMessageHashTableTest.kt index 97a189240c..14a7f30e10 100644 --- a/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsMessageHashTableTest.kt +++ b/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsMessageHashTableTest.kt @@ -36,7 +36,7 @@ class DanaRsMessageHashTableTest : DanaRSTestBase() { @Test 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 forTesting: DanaRSPacket = DanaRSPacketAPSSetEventHistory(packetInjector, DanaPump.HistoryEntry.CARBS.value, 0, 0, 0) diff --git a/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt b/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt index 27a8dcd7cd..af4ac3f1a1 100644 --- a/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt +++ b/pump/danars/src/test/java/info/nightscout/pump/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt @@ -75,6 +75,6 @@ class DanaRsPacketBolusSetStepBolusStartTest : DanaRSTestBase() { danaHistoryDatabase, decimalFormatter ) - Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, injector)) + Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(ConstraintObject(0.0, aapsLogger)) } } \ No newline at end of file diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Plugin.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Plugin.kt index 0ed3187bbb..b0e3937466 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Plugin.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Plugin.kt @@ -271,7 +271,7 @@ class DiaconnG8Plugin @Inject constructor( @Synchronized 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) { val carbs = detailedBolusInfo.carbs detailedBolusInfo.carbs = 0.0 @@ -310,7 +310,7 @@ class DiaconnG8Plugin @Inject constructor( @Synchronized override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult { 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 doLowTemp = absoluteAfterConstrain < baseBasalRate val doHighTemp = absoluteAfterConstrain > baseBasalRate @@ -397,7 +397,7 @@ class DiaconnG8Plugin @Inject constructor( @Synchronized 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 insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep) val result = PumpEnactResult(injector) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt index d4f41f9e74..7d8e090bc9 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt @@ -348,7 +348,7 @@ import kotlin.math.abs override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { aapsLogger.debug(LTag.PUMP, "deliverTreatment: " + detailedBolusInfo.insulin + "U") 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) { aapsLogger.debug(LTag.PUMP, "deliverTreatment: Delivering bolus: " + detailedBolusInfo.insulin + "U") 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") // 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)) val connectionOK = medtrumService?.setTempBasal(pumpRate, durationInMinutes) ?: false return if (connectionOK diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt index 8095e08415..40aa9ce9a8 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt @@ -227,7 +227,7 @@ class CarbsDialog : DialogFragmentWithDate() { override fun submit(): Boolean { if (_binding == null) return false 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 activityTTDuration = defaultValueHelper.determineActivityTTDuration() val activityTT = defaultValueHelper.determineActivityTT() diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/ExtendedBolusDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/ExtendedBolusDialog.kt index 49ecf11135..a946bae2b8 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/ExtendedBolusDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/ExtendedBolusDialog.kt @@ -96,7 +96,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { val insulin = SafeParse.stringToDouble(binding.insulin.text) val durationInMinutes = binding.duration.value.toInt() val actions: LinkedList = 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.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes)) if (abs(insulinAfterConstraint - insulin) > 0.01) diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/FillDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/FillDialog.kt index 7f149d45d6..7affb9e620 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/FillDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/FillDialog.kt @@ -118,7 +118,7 @@ class FillDialog : DialogFragmentWithDate() { val insulin = SafeParse.stringToDouble(binding.fillInsulinAmount.text) val actions: LinkedList = LinkedList() - val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, injector)).value() + val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value() if (insulinAfterConstraints > 0) { actions.add(rh.gs(R.string.fill_warning)) actions.add("") diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt index 9602f779c1..07a9890e27 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt @@ -191,7 +191,7 @@ class InsulinDialog : DialogFragmentWithDate() { if (_binding == null) return false val pumpDescription = activePlugin.activePump.pumpDescription 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 = LinkedList() 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) diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt index 00577a4b11..43559c127e 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt @@ -159,9 +159,9 @@ class LoopDialog : DaggerDialogFragment() { if (_binding == null) return aapsLogger.debug("UpdateGUI from $from") 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 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 pump = activePlugin.activePump diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt index 4cf3cf85d8..072cacdbe1 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt @@ -120,13 +120,13 @@ class TempBasalDialog : DialogFragmentWithDate() { val actions: LinkedList = LinkedList() if (isPercentPump) { 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.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)) } else { 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.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes)) if (abs(absolute - basalAbsoluteInput) > 0.01) diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt index 02099655ce..147ead7fd7 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt @@ -138,8 +138,8 @@ class TreatmentDialog : DialogFragmentWithDate() { val carbs = SafeParse.stringToInt(binding.carbs.text) val recordOnlyChecked = binding.recordOnly.isChecked val actions: LinkedList = LinkedList() - val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, injector)).value() - val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, injector)).value() + val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value() + val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, aapsLogger)).value() if (insulinAfterConstraints > 0) { actions.add( diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt index 31b4c03bd8..b8347e7807 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt @@ -444,7 +444,7 @@ class WizardDialog : DaggerDialogFragment() { SafeParse.stringToDouble(binding.correctionInput.text) } else 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) { binding.carbsInput.value = 0.0 ToastUtils.warnToast(ctx, R.string.carbs_constraint_applied)