fix injection crash
This commit is contained in:
parent
7cb27fced0
commit
26a07f2477
|
@ -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<T : Comparable<T>>(private var value: T, injector: HasAndroidInjector) : Constraint<T> {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
class ConstraintObject<T : Comparable<T>>(private var value: T, private val aapsLogger: AAPSLogger) : Constraint<T> {
|
||||
|
||||
private var originalValue: T
|
||||
private val reasons: MutableList<String> = ArrayList()
|
||||
|
@ -115,7 +111,6 @@ class ConstraintObject<T : Comparable<T>>(private var value: T, injector: HasAnd
|
|||
}
|
||||
|
||||
init {
|
||||
injector.androidInjector().inject(this)
|
||||
originalValue = value
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -79,7 +79,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
|
|||
var tddLast24H: Double? = null
|
||||
var tddLast4H: Double? = null
|
||||
var tddLast8to4H: Double? = null
|
||||
var dynIsfEnabled: Constraint<Boolean> = ConstraintObject(false, injector)
|
||||
var dynIsfEnabled: Constraint<Boolean> = 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) }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Boolean>
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -40,7 +40,7 @@ ActionsTestBase : TestBaseWithProfile() {
|
|||
|
||||
private var suspended = false
|
||||
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 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Boolean> = isLoopInvocationAllowed(ConstraintObject(true, injector))
|
||||
override fun isLoopInvocationAllowed(): Constraint<Boolean> = isLoopInvocationAllowed(ConstraintObject(true, aapsLogger))
|
||||
|
||||
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -28,7 +28,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -40,7 +40,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -52,7 +52,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -64,7 +64,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -76,7 +76,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -88,7 +88,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -100,7 +100,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -112,7 +112,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -124,7 +124,7 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
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> {
|
||||
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(PluginConstraints::class.java)
|
||||
|
@ -201,20 +201,20 @@ class ConstraintsCheckerImpl @Inject constructor(
|
|||
*/
|
||||
|
||||
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> =
|
||||
applyBasalPercentConstraints(ConstraintObject(Int.MAX_VALUE, injector), profile)
|
||||
applyBasalPercentConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger), profile)
|
||||
|
||||
override fun getMaxBolusAllowed(): Constraint<Double> =
|
||||
applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector))
|
||||
applyBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
|
||||
|
||||
override fun getMaxExtendedBolusAllowed(): Constraint<Double> =
|
||||
applyExtendedBolusConstraints(ConstraintObject(Double.MAX_VALUE, injector))
|
||||
applyExtendedBolusConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
|
||||
|
||||
override fun getMaxCarbsAllowed(): Constraint<Int> =
|
||||
applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, injector))
|
||||
applyCarbsConstraints(ConstraintObject(Int.MAX_VALUE, aapsLogger))
|
||||
|
||||
override fun getMaxIOBAllowed(): Constraint<Double> =
|
||||
applyMaxIOBConstraints(ConstraintObject(Double.MAX_VALUE, injector))
|
||||
applyMaxIOBConstraints(ConstraintObject(Double.MAX_VALUE, aapsLogger))
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
|
@ -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())
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
|
|
|
@ -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<String>, 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()
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -96,7 +96,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
|
|||
val insulin = SafeParse.stringToDouble(binding.insulin.text)
|
||||
val durationInMinutes = binding.duration.value.toInt()
|
||||
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.duration) + ": " + rh.gs(info.nightscout.core.ui.R.string.format_mins, durationInMinutes))
|
||||
if (abs(insulinAfterConstraint - insulin) > 0.01)
|
||||
|
|
|
@ -118,7 +118,7 @@ class FillDialog : DialogFragmentWithDate() {
|
|||
val insulin = SafeParse.stringToDouble(binding.fillInsulinAmount.text)
|
||||
val actions: LinkedList<String?> = 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("")
|
||||
|
|
|
@ -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<String?> = 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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -120,13 +120,13 @@ class TempBasalDialog : DialogFragmentWithDate() {
|
|||
val actions: LinkedList<String> = 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)
|
||||
|
|
|
@ -138,8 +138,8 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
|||
val carbs = SafeParse.stringToInt(binding.carbs.text)
|
||||
val recordOnlyChecked = binding.recordOnly.isChecked
|
||||
val actions: LinkedList<String?> = 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(
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue