diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index 74fa37901d..224a89a888 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -54,9 +54,8 @@ class ObjectivesPlugin @Inject constructor( const val MAXIOB_ZERO_CL_OBJECTIVE = 5 @Suppress("unused") const val MAXIOB_OBJECTIVE = 6 const val AUTOSENS_OBJECTIVE = 7 - const val AMA_OBJECTIVE = 8 - const val SMB_OBJECTIVE = 9 - const val AUTO_OBJECTIVE = 10 + const val SMB_OBJECTIVE = 8 + const val AUTO_OBJECTIVE = 9 } public override fun onStart() { @@ -64,9 +63,8 @@ class ObjectivesPlugin @Inject constructor( setupObjectives() } - override fun specialEnableCondition(): Boolean { - return activePlugin.activePump.pumpDescription.isTempBasalCapable - } + override fun specialEnableCondition(): Boolean = + activePlugin.activePump.pumpDescription.isTempBasalCapable private fun setupObjectives() { objectives.clear() @@ -80,6 +78,7 @@ class ObjectivesPlugin @Inject constructor( objectives.add(Objective7(injector)) objectives.add(Objective9(injector)) objectives.add(Objective10(injector)) + // edit companion object if you remove/add Objective } fun reset() { @@ -115,8 +114,6 @@ class ObjectivesPlugin @Inject constructor( sp.putLong("Objectives_" + "maxiob" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "autosens" + "_started", dateUtil.now()) sp.putLong("Objectives_" + "autosens" + "_accomplished", dateUtil.now()) - sp.putLong("Objectives_" + "ama" + "_started", dateUtil.now()) - sp.putLong("Objectives_" + "ama" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "smb" + "_started", dateUtil.now()) sp.putLong("Objectives_" + "smb" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "auto" + "_started", dateUtil.now()) @@ -142,49 +139,43 @@ class ObjectivesPlugin @Inject constructor( */ override fun isLoopInvocationAllowed(value: Constraint): Constraint { if (!objectives[FIRST_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, FIRST_OBJECTIVE + 1), this) return value } override fun isLgsAllowed(value: Constraint): Constraint { if (!objectives[MAXBASAL_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXBASAL_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXBASAL_OBJECTIVE + 1), this) return value } override fun isClosedLoopAllowed(value: Constraint): Constraint { if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXIOB_ZERO_CL_OBJECTIVE + 1), this) return value } override fun isAutosensModeEnabled(value: Constraint): Constraint { if (!objectives[AUTOSENS_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this) - return value - } - - override fun isAMAModeEnabled(value: Constraint): Constraint { - if (!objectives[AMA_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTOSENS_OBJECTIVE + 1), this) return value } override fun isSMBModeEnabled(value: Constraint): Constraint { if (!objectives[SMB_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, SMB_OBJECTIVE + 1), this) return value } override fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { if (objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted && !objectives[MAXIOB_ZERO_CL_OBJECTIVE].isAccomplished) - maxIob.set(aapsLogger, 0.0, String.format(resourceHelper.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this) + maxIob.set(aapsLogger, 0.0, resourceHelper.gs(R.string.objectivenotfinished, MAXIOB_ZERO_CL_OBJECTIVE + 1), this) return maxIob } override fun isAutomationEnabled(value: Constraint): Constraint { if (!objectives[AUTO_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTO_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTO_OBJECTIVE + 1), this) return value } } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 3235a110c0..874175a2be 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -198,16 +198,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { Assert.assertEquals(java.lang.Boolean.FALSE, c.value()) } - // Objectives - @Test - fun isAMAModeEnabledTest() { - objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0 - val c = constraintChecker.isAMAModeEnabled() - Assert.assertEquals(true, c.reasonList.size == 1) // Objectives - Assert.assertEquals(true, c.mostLimitedReasonList.size == 1) // Objectives - Assert.assertEquals(java.lang.Boolean.FALSE, c.value()) - } - // Safety @Test fun isAdvancedFilteringEnabledTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt index 270753e9a4..c08f4c9033 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt @@ -74,14 +74,6 @@ class ObjectivesPluginTest : TestBase() { Assert.assertEquals(false, c.value()) } - @Test fun notStartedObjective9ShouldLimitAMAMode() { - objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0 - var c = Constraint(true) - c = objectivesPlugin.isAMAModeEnabled(c) - Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 9 not started")) - Assert.assertEquals(false, c.value()) - } - @Test fun notStartedObjective10ShouldLimitSMBMode() { objectivesPlugin.objectives[ObjectivesPlugin.SMB_OBJECTIVE].startedOn = 0 var c = Constraint(true) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt index f0e8bffd89..b02dfb0dd3 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt @@ -72,7 +72,6 @@ class AutomationEvent(private val injector: HasAndroidInjector) { readOnly = d.optBoolean("readOnly", false) autoRemove = d.optBoolean("autoRemove", false) trigger = TriggerDummy(injector).instantiate(JSONObject(d.getString("trigger"))) - ?: TriggerConnector(injector) val array = d.getJSONArray("actions") actions.clear() for (i in 0 until array.length()) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt index 105f91fe3b..91311a84da 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt @@ -95,7 +95,7 @@ class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) { val array = d.getJSONArray("triggerList") list.clear() for (i in 0 until array.length()) { - instantiate(JSONObject(array.getString(i)))?.let { + instantiate(JSONObject(array.getString(i))).let { list.add(it) } } diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt index 95a901f626..709b4c037b 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt @@ -17,7 +17,6 @@ interface Constraints { fun isClosedLoopAllowed(value: Constraint): Constraint = value fun isLgsAllowed(value: Constraint): Constraint = value fun isAutosensModeEnabled(value: Constraint): Constraint = value - fun isAMAModeEnabled(value: Constraint): Constraint = value fun isSMBModeEnabled(value: Constraint): Constraint = value fun isUAMEnabled(value: Constraint): Constraint = value fun isAdvancedFilteringEnabled(value: Constraint): Constraint = value diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt index 99476dff8f..718956c90b 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt @@ -24,9 +24,6 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug fun isAutosensModeEnabled(): Constraint = isAutosensModeEnabled(Constraint(true)) - fun isAMAModeEnabled(): Constraint = - isAMAModeEnabled(Constraint(true)) - fun isSMBModeEnabled(): Constraint = isSMBModeEnabled(Constraint(true)) @@ -100,16 +97,6 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug return value } - override fun isAMAModeEnabled(value: Constraint): Constraint { - val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java) - for (p in constraintsPlugins) { - val constrain = p as Constraints - if (!p.isEnabled(PluginType.CONSTRAINTS)) continue - constrain.isAMAModeEnabled(value) - } - return value - } - override fun isSMBModeEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java) for (p in constraintsPlugins) {