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 a5e9777c09..206ddafa79 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -430,7 +430,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { @Test fun iobAMAShouldBeLimited() { // No limit by default - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.CLOSED.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name) `when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5) `when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("teenage") openAPSAMAPlugin.setPluginEnabled(PluginType.APS, true) @@ -446,7 +446,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { @Test fun iobSMBShouldBeLimited() { // No limit by default - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.CLOSED.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name) `when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapssmb_max_iob, 3.0)).thenReturn(3.0) `when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("teenage") openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt index 2aa4fe5aec..fefb05d9b3 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt @@ -71,7 +71,7 @@ class LoopPluginTest : TestBase() { fun testPluginInterface() { `when`(rh.gs(info.nightscout.core.ui.R.string.loop)).thenReturn("Loop") `when`(rh.gs(info.nightscout.plugins.aps.R.string.loop_shortname)).thenReturn("LOOP") - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.CLOSED.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name) val pumpDescription = PumpDescription() `when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription) Assert.assertEquals(LoopFragment::class.java.name, loopPlugin.pluginDescription.fragmentClass) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt index 800ff1b8ca..852eb5a0b2 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt @@ -98,7 +98,7 @@ class SafetyPluginTest : TestBaseWithProfile() { @Test fun disabledEngineeringModeShouldLimitClosedLoop() { - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.CLOSED.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name) `when`(config.isEngineeringModeOrRelease()).thenReturn(false) var c = Constraint(true) c = safetyPlugin.isClosedLoopAllowed(c) @@ -108,7 +108,7 @@ class SafetyPluginTest : TestBaseWithProfile() { @Test fun setOpenLoopInPreferencesShouldLimitClosedLoop() { - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.OPEN.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.OPEN.name) var c = Constraint(true) c = safetyPlugin.isClosedLoopAllowed(c) Assertions.assertTrue(c.getReasons(aapsLogger).contains("Closed loop mode disabled in preferences")) @@ -278,7 +278,7 @@ Safety: Limiting max basal rate to 500.00 U/h because of pump limit openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true) //`when`(openAPSSMBPlugin.isEnabled()).thenReturn(true) //`when`(openAPSAMAPlugin.isEnabled()).thenReturn(false) - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.LGS.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.LGS.name) `when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5) `when`(sp.getDouble(info.nightscout.plugins.aps.R.string.key_openapssmb_max_iob, 3.0)).thenReturn(3.0) `when`(sp.getString(info.nightscout.core.utils.R.string.key_age, "")).thenReturn("teenage") diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/ApsMode.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/ApsMode.kt index ed8dbe818a..11634c8356 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/ApsMode.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/ApsMode.kt @@ -1,10 +1,10 @@ package info.nightscout.interfaces -enum class ApsMode(val lowercase: String) { - OPEN("open"), - CLOSED("closed"), - LGS("lgs"), - UNDEFINED("undefined"); +enum class ApsMode() { + OPEN, + CLOSED, + LGS, + UNDEFINED; companion object { diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt index 6eb7d2bfce..91930bfbe7 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt @@ -183,7 +183,7 @@ class LoopPlugin @Inject constructor( get() { val closedLoopEnabled = constraintChecker.isClosedLoopAllowed() val maxIobAllowed = constraintChecker.getMaxIOBAllowed().value() - val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)) + val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) val pump = activePlugin.activePump var isLGS = false if (!isSuspended && !pump.isSuspended()) if (closedLoopEnabled.value()) if (maxIobAllowed == HardLimits.MAX_IOB_LGS || apsMode == ApsMode.LGS) isLGS = true diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective6.kt b/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective6.kt index 2cac3333d9..6e170a93aa 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective6.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective6.kt @@ -16,7 +16,7 @@ class Objective6(injector: HasAndroidInjector) : Objective(injector, "maxiob", R tasks.add(MinimumDurationTask(this, T.days(1).msecs())) tasks.add( object : Task(this, R.string.closedmodeenabled) { - override fun isCompleted(): Boolean = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)) == ApsMode.CLOSED + override fun isCompleted(): Boolean = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) == ApsMode.CLOSED }) tasks.add( object : Task(this, R.string.maxiobset) { diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt index 930fe307c7..7d5d20cb0c 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt @@ -67,7 +67,7 @@ class SafetyPlugin @Inject constructor( } override fun isClosedLoopAllowed(value: Constraint): Constraint { - val mode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)) + val mode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) if (mode == ApsMode.OPEN) value.set(aapsLogger, false, rh.gs(R.string.closedmodedisabledinpreferences), this) if (!config.isEngineeringModeOrRelease()) { if (value.value()) { @@ -160,7 +160,7 @@ class SafetyPlugin @Inject constructor( } override fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { - val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)) + val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) if (apsMode == ApsMode.LGS) maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, rh.gs(info.nightscout.core.ui.R.string.limiting_iob, HardLimits.MAX_IOB_LGS, rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend)), this) return maxIob } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 92b5e61a2d..f4a408362f 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -510,7 +510,7 @@ class SmsCommunicatorPlugin @Inject constructor( messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(pumpCommand = false) { override fun run() { uel.log(Action.LGS_LOOP_MODE, Sources.SMS) - sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.LGS.lowercase) + sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.LGS.name) rxBus.send(EventPreferenceChange(rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend))) val replyText = rh.gs(R.string.smscommunicator_current_loop_mode, getApsModeText()) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) @@ -525,7 +525,7 @@ class SmsCommunicatorPlugin @Inject constructor( messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(pumpCommand = false) { override fun run() { uel.log(Action.CLOSED_LOOP_MODE, Sources.SMS) - sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.CLOSED.lowercase) + sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.CLOSED.name) rxBus.send(EventPreferenceChange(rh.gs(info.nightscout.core.ui.R.string.closedloop))) val replyText = rh.gs(R.string.smscommunicator_current_loop_mode, getApsModeText()) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) @@ -1284,7 +1284,7 @@ class SmsCommunicatorPlugin @Inject constructor( } private fun getApsModeText(): String = - when (ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase))) { + when (ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))) { ApsMode.OPEN -> rh.gs(info.nightscout.core.ui.R.string.openloop) ApsMode.CLOSED -> rh.gs(info.nightscout.core.ui.R.string.closedloop) ApsMode.LGS -> rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend) diff --git a/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index 43491557c0..dd44bc7b56 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/plugins/main/src/test/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -343,7 +343,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP STATUS : enabled - APS mode - Closed `when`(loop.enabled).thenReturn(true) `when`(loop.isSuspended).thenReturn(false) - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.CLOSED.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -352,7 +352,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assertions.assertEquals("Loop is enabled - $modeClosed", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : enabled - APS mode - Open - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.OPEN.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.OPEN.name) smsCommunicatorPlugin.messages = ArrayList() smsCommunicatorPlugin.processSms(sms) Assertions.assertFalse(sms.ignored) @@ -360,7 +360,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assertions.assertEquals("Loop is enabled - $modeOpen", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : enabled - APS mode - LGS - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.LGS.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.LGS.name) smsCommunicatorPlugin.messages = ArrayList() smsCommunicatorPlugin.processSms(sms) Assertions.assertFalse(sms.ignored) @@ -368,7 +368,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assertions.assertEquals("Loop is enabled - $modeLgs", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : enabled - APS mode - unknown - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn("some wrong value") + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn("some wrong value") smsCommunicatorPlugin.messages = ArrayList() smsCommunicatorPlugin.processSms(sms) Assertions.assertFalse(sms.ignored) @@ -520,7 +520,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { var smsCommand = "LOOP CLOSED" val replyClosed = "In order to switch Loop mode to Closed loop reply with code " `when`(loop.enabled).thenReturn(true) - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.CLOSED.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.CLOSED.name) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", smsCommand) smsCommunicatorPlugin.processSms(sms) @@ -535,7 +535,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP LGS smsCommand = "LOOP LGS" val replyLgs = "In order to switch Loop mode to LGS (Low Glucose Suspend) reply with code " - `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)).thenReturn(ApsMode.LGS.lowercase) + `when`(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)).thenReturn(ApsMode.LGS.name) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", smsCommand) smsCommunicatorPlugin.processSms(sms) diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt index 99b865dbdb..b1a30052ac 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt @@ -162,7 +162,7 @@ class LoopDialog : DaggerDialogFragment() { val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(Constraint(true)) val closedLoopAllowed2 = activePlugin.activeObjectives?.isAccomplished(Objectives.MAXIOB_OBJECTIVE) ?: false val lgsEnabled = constraintChecker.isLgsAllowed(Constraint(true)) - val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase)) + val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) val pump = activePlugin.activePump binding.overviewDisconnect15m.visibility = pumpDescription.tempDurationStep15mAllowed.toVisibility() @@ -211,27 +211,27 @@ class LoopDialog : DaggerDialogFragment() { else -> { binding.overviewLoop.visibility = View.VISIBLE binding.overviewEnable.visibility = View.GONE - when { - apsMode == ApsMode.CLOSED -> { + when (apsMode) { + ApsMode.CLOSED -> { binding.overviewCloseloop.visibility = View.GONE binding.overviewLgsloop.visibility = View.VISIBLE binding.overviewOpenloop.visibility = View.VISIBLE } - apsMode == ApsMode.LGS -> { + ApsMode.LGS -> { binding.overviewCloseloop.visibility = closedLoopAllowed.value().toVisibility() //show Close loop button only if Close loop allowed binding.overviewLgsloop.visibility = View.GONE binding.overviewOpenloop.visibility = View.VISIBLE } - apsMode == ApsMode.OPEN -> { + ApsMode.OPEN -> { binding.overviewCloseloop.visibility = closedLoopAllowed2.toVisibility() //show CloseLoop button only if Objective 6 is completed (closedLoopAllowed always false in open loop mode) binding.overviewLgsloop.visibility = lgsEnabled.value().toVisibility() binding.overviewOpenloop.visibility = View.GONE } - else -> { + else -> { binding.overviewCloseloop.visibility = View.GONE binding.overviewLgsloop.visibility = View.GONE binding.overviewOpenloop.visibility = View.GONE @@ -283,21 +283,21 @@ class LoopDialog : DaggerDialogFragment() { when (v.id) { R.id.overview_closeloop -> { uel.log(UserEntry.Action.CLOSED_LOOP_MODE, UserEntry.Sources.LoopDialog) - sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.CLOSED.lowercase) + sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.CLOSED.name) rxBus.send(EventPreferenceChange(rh.gs(info.nightscout.core.ui.R.string.closedloop))) return true } R.id.overview_lgsloop -> { uel.log(UserEntry.Action.LGS_LOOP_MODE, UserEntry.Sources.LoopDialog) - sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.LGS.lowercase) + sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.LGS.name) rxBus.send(EventPreferenceChange(rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend))) return true } R.id.overview_openloop -> { uel.log(UserEntry.Action.OPEN_LOOP_MODE, UserEntry.Sources.LoopDialog) - sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.lowercase) + sp.putString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name) rxBus.send(EventPreferenceChange(rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend))) return true }