ConstriantsInterface rename

This commit is contained in:
Milos Kozak 2021-04-14 19:01:49 +02:00
parent 8ecc02c994
commit 176fc4bb47
17 changed files with 71 additions and 58 deletions

View file

@ -55,7 +55,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
.description(R.string.description_smb)
.setDefault(),
aapsLogger, resourceHelper, injector
), APS, ConstraintsInterface {
), APS, Constraints {
// last values
override var lastAPSRun: Long = 0

View file

@ -33,7 +33,7 @@ class DstHelperPlugin @Inject constructor(
.showInList(false)
.pluginName(R.string.dst_plugin_name),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
companion object {
private const val DISABLE_TIME_FRAME_HOURS = -3

View file

@ -41,7 +41,7 @@ class ObjectivesPlugin @Inject constructor(
.shortName(R.string.objectives_shortname)
.description(R.string.description_objectives),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
var objectives: MutableList<Objective> = ArrayList()

View file

@ -5,7 +5,7 @@ import android.os.Build
import com.scottyab.rootbeer.RootBeer
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.ConstraintsInterface
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
@ -27,7 +27,7 @@ class PhoneCheckerPlugin @Inject constructor(
.showInList(false)
.pluginName(R.string.phonechecker),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
var phoneRooted: Boolean = false
var devMode: Boolean = false

View file

@ -49,7 +49,7 @@ class SafetyPlugin @Inject constructor(
.pluginName(R.string.safety)
.preferencesId(R.xml.pref_safety),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
/**
* Constraints interface

View file

@ -5,7 +5,7 @@ import android.content.pm.PackageManager
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.ConstraintsInterface
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
@ -46,7 +46,7 @@ class SignatureVerifierPlugin @Inject constructor(
.showInList(false)
.pluginName(R.string.signature_verifier),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
private val REVOKED_CERTS_URL = "https://raw.githubusercontent.com/nightscout/AndroidAPS/master/app/src/main/assets/revoked_certs.txt"
private val UPDATE_INTERVAL = TimeUnit.DAYS.toMillis(1)

View file

@ -6,7 +6,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.ConstraintsInterface
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
@ -33,7 +33,7 @@ open class StorageConstraintPlugin @Inject constructor(
.showInList(false)
.pluginName(R.string.storage),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val diskFree = availableInternalMemorySize()

View file

@ -4,7 +4,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.ConstraintsInterface
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
@ -35,7 +35,7 @@ class VersionCheckerPlugin @Inject constructor(
.showInList(false)
.pluginName(R.string.versionChecker),
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
), Constraints {
enum class GracePeriod(val warning: Long, val old: Long, val veryOld: Long) {
RELEASE(30, 60, 90),

View file

@ -156,7 +156,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
constraintsPluginsList.add(danaRSPlugin)
constraintsPluginsList.add(insightPlugin)
constraintsPluginsList.add(openAPSSMBPlugin)
`when`(activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)).thenReturn(constraintsPluginsList)
`when`(activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)).thenReturn(constraintsPluginsList)
objectivesPlugin.onStart()
}

View file

@ -31,7 +31,7 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.Constraints;
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
@ -72,7 +72,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
* Created by mike on 05.08.2016.
*/
@Singleton
public class ComboPlugin extends PumpPluginBase implements PumpInterface, ConstraintsInterface {
public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constraints {
static final String COMBO_TBRS_SET = "combo_tbrs_set";
static final String COMBO_BOLUSES_DELIVERED = "combo_boluses_delivered";

View file

@ -3,9 +3,17 @@ package info.nightscout.androidaps.interfaces
import info.nightscout.androidaps.data.Profile
/**
* Created by mike on 15.06.2016.
* Constraints interface
*
* Every function has a param from previous chained call
* Function can limit the value even more and add another reason of restriction
*
* see [info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker]
* which iterates over all registered plugins with [Constraints] implemented
*
* @return updated parameter
*/
interface ConstraintsInterface {
interface Constraints {
@JvmDefault fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> = value
@JvmDefault fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> = value

View file

@ -1,5 +1,10 @@
package info.nightscout.androidaps.interfaces
/**
* Main plugin type
*
* set by [info.nightscout.androidaps.interfaces.PluginDescription.mainType]
*/
enum class PluginType {
GENERAL, TREATMENT, SENSITIVITY, PROFILE, APS, PUMP, CONSTRAINTS, LOOP, BGSOURCE, INSULIN
}

View file

@ -4,13 +4,13 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.ConstraintsInterface
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginType
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlugin) : ConstraintsInterface {
class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlugin) : Constraints {
fun isLoopInvocationAllowed(): Constraint<Boolean> =
isLoopInvocationAllowed(Constraint(true))
@ -61,9 +61,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
isAutomationEnabled(Constraint(true))
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isLoopInvocationAllowed(value)
}
@ -71,9 +71,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isClosedLoopAllowed(value)
}
@ -81,9 +81,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isLgsAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isLgsAllowed(value)
}
@ -91,9 +91,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isAutosensModeEnabled(value)
}
@ -101,9 +101,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constrain = p as ConstraintsInterface
val constrain = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constrain.isAMAModeEnabled(value)
}
@ -111,9 +111,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isSMBModeEnabled(value)
}
@ -121,9 +121,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isUAMEnabled(value)
}
@ -131,9 +131,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isAdvancedFilteringEnabled(value)
}
@ -141,9 +141,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isSuperBolusEnabled(value)
}
@ -151,9 +151,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun applyBasalConstraints(absoluteRate: Constraint<Double>, profile: Profile): Constraint<Double> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.applyBasalConstraints(absoluteRate, profile)
}
@ -161,9 +161,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun applyBasalPercentConstraints(percentRate: Constraint<Int>, profile: Profile): Constraint<Int> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constrain = p as ConstraintsInterface
val constrain = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constrain.applyBasalPercentConstraints(percentRate, profile)
}
@ -171,9 +171,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun applyBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constrain = p as ConstraintsInterface
val constrain = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constrain.applyBolusConstraints(insulin)
}
@ -181,9 +181,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun applyExtendedBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constrain = p as ConstraintsInterface
val constrain = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constrain.applyExtendedBolusConstraints(insulin)
}
@ -191,9 +191,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun applyCarbsConstraints(carbs: Constraint<Int>): Constraint<Int> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constrain = p as ConstraintsInterface
val constrain = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constrain.applyCarbsConstraints(carbs)
}
@ -201,9 +201,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constrain = p as ConstraintsInterface
val constrain = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constrain.applyMaxIOBConstraints(maxIob)
}
@ -211,9 +211,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
override fun isAutomationEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
val constraint = p as Constraints
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isAutomationEnabled(value)
}

View file

@ -18,7 +18,7 @@ import info.nightscout.androidaps.extensions.PumpStateExtensionKt;
import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.Constraints;
import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
@ -46,7 +46,7 @@ import io.reactivex.disposables.CompositeDisposable;
* Created by mike on 28.01.2018.
*/
public abstract class AbstractDanaRPlugin extends PumpPluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface {
public abstract class AbstractDanaRPlugin extends PumpPluginBase implements PumpInterface, DanaRInterface, Constraints {
protected AbstractDanaRExecutionService sExecutionService;
protected CompositeDisposable disposable = new CompositeDisposable();

View file

@ -71,7 +71,7 @@ class DanaRSPlugin @Inject constructor(
.preferencesId(R.xml.pref_danars)
.description(R.string.description_pump_dana_rs),
injector, aapsLogger, resourceHelper, commandQueue
), PumpInterface, DanaRInterface, ConstraintsInterface {
), PumpInterface, DanaRInterface, Constraints {
private val disposable = CompositeDisposable()
private var danaRSService: DanaRSService? = null

View file

@ -46,7 +46,7 @@ import info.nightscout.androidaps.insight.R;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Config;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.Constraints;
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
@ -138,7 +138,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@Singleton
public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, ConstraintsInterface, InsightConnectionService.StateCallback {
public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, Constraints, InsightConnectionService.StateCallback {
private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.events.EventCustomActionsChanged;
import info.nightscout.androidaps.extensions.PumpStateExtensionKt;
import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.Constraints;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
@ -50,7 +50,7 @@ import io.reactivex.disposables.CompositeDisposable;
// When using this class, make sure that your first step is to create mConnection (see MedtronicPumpPlugin)
public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpInterface, ConstraintsInterface {
public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpInterface, Constraints {
private final CompositeDisposable disposable = new CompositeDisposable();
protected HasAndroidInjector injector;