pass safety values to NSClient
This commit is contained in:
parent
1b45d4fe31
commit
a4aae47b8b
6 changed files with 34 additions and 1 deletions
|
@ -166,6 +166,9 @@ class PluginStore @Inject constructor(
|
|||
override val activeOverview: Overview
|
||||
get() = getSpecificPluginsListByInterface(Overview::class.java).first() as Overview
|
||||
|
||||
override val activeSafety: Safety
|
||||
get() = getSpecificPluginsListByInterface(Safety::class.java).first() as Safety
|
||||
|
||||
override fun getPluginsList(): ArrayList<PluginBase> = ArrayList(plugins)
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.constraints.safety
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.extensions.*
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -20,6 +21,7 @@ import info.nightscout.androidaps.utils.Round
|
|||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.math.floor
|
||||
|
@ -49,7 +51,7 @@ class SafetyPlugin @Inject constructor(
|
|||
.pluginName(R.string.safety)
|
||||
.preferencesId(R.xml.pref_safety),
|
||||
aapsLogger, resourceHelper, injector
|
||||
), Constraints {
|
||||
), Constraints, Safety {
|
||||
|
||||
/**
|
||||
* Constraints interface
|
||||
|
@ -193,4 +195,16 @@ class SafetyPlugin @Inject constructor(
|
|||
if (apsMode == "lgs") maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.MAX_IOB_LGS, resourceHelper.gs(R.string.lowglucosesuspend)), this)
|
||||
return maxIob
|
||||
}
|
||||
|
||||
override fun configuration(): JSONObject =
|
||||
JSONObject()
|
||||
.putString(R.string.key_age, sp, resourceHelper)
|
||||
.putDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper)
|
||||
.putDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper)
|
||||
|
||||
override fun applyConfiguration(configuration: JSONObject) {
|
||||
configuration.storeString(R.string.key_age, sp, resourceHelper)
|
||||
configuration.storeDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper)
|
||||
configuration.storeDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper)
|
||||
}
|
||||
}
|
|
@ -176,6 +176,7 @@ class OverviewPlugin @Inject constructor(
|
|||
|
||||
override fun configuration(): JSONObject =
|
||||
JSONObject()
|
||||
.putInt(R.string.key_units, sp, resourceHelper)
|
||||
.putString(R.string.key_quickwizard, sp, resourceHelper)
|
||||
.putInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
||||
.putDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
||||
|
@ -202,6 +203,7 @@ class OverviewPlugin @Inject constructor(
|
|||
|
||||
override fun applyConfiguration(configuration: JSONObject) {
|
||||
configuration
|
||||
.storeInt(R.string.key_units, sp, resourceHelper)
|
||||
.storeString(R.string.key_quickwizard, sp, resourceHelper)
|
||||
.storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
||||
|
|
|
@ -46,6 +46,12 @@ interface ActivePlugin {
|
|||
*/
|
||||
val activeOverview: Overview
|
||||
|
||||
/**
|
||||
* Currently selected Safety plugin
|
||||
* Always SafetyPlugin
|
||||
*/
|
||||
val activeSafety: Safety
|
||||
|
||||
/**
|
||||
* List of all registered plugins
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
interface Safety : ConfigExportImport
|
|
@ -36,12 +36,14 @@ class RunningConfiguration @Inject constructor(
|
|||
val sensitivityInterface = activePlugin.activeSensitivity
|
||||
val pumpInterface = activePlugin.activePump
|
||||
val overviewInterface = activePlugin.activeOverview
|
||||
val safetyInterface = activePlugin.activeSafety
|
||||
|
||||
json.put("insulin", insulinInterface.id.value)
|
||||
json.put("insulinConfiguration", insulinInterface.configuration())
|
||||
json.put("sensitivity", sensitivityInterface.id.value)
|
||||
json.put("sensitivityConfiguration", sensitivityInterface.configuration())
|
||||
json.put("overviewConfiguration", overviewInterface.configuration())
|
||||
json.put("safetyConfiguration", safetyInterface.configuration())
|
||||
json.put("pump", pumpInterface.model().description)
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
|
@ -88,5 +90,8 @@ class RunningConfiguration @Inject constructor(
|
|||
|
||||
if (configuration.has("overviewConfiguration"))
|
||||
activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration"))
|
||||
|
||||
if (configuration.has("safetyConfiguration"))
|
||||
activePlugin.activeSafety.applyConfiguration(configuration.getJSONObject("safetyConfiguration"))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue