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
|
override val activeOverview: Overview
|
||||||
get() = getSpecificPluginsListByInterface(Overview::class.java).first() as 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)
|
override fun getPluginsList(): ArrayList<PluginBase> = ArrayList(plugins)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.constraints.safety
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.interfaces.Config
|
import info.nightscout.androidaps.interfaces.Config
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.extensions.*
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
import info.nightscout.androidaps.interfaces.*
|
import info.nightscout.androidaps.interfaces.*
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
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.buildHelper.BuildHelper
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
@ -49,7 +51,7 @@ class SafetyPlugin @Inject constructor(
|
||||||
.pluginName(R.string.safety)
|
.pluginName(R.string.safety)
|
||||||
.preferencesId(R.xml.pref_safety),
|
.preferencesId(R.xml.pref_safety),
|
||||||
aapsLogger, resourceHelper, injector
|
aapsLogger, resourceHelper, injector
|
||||||
), Constraints {
|
), Constraints, Safety {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraints interface
|
* 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)
|
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
|
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 =
|
override fun configuration(): JSONObject =
|
||||||
JSONObject()
|
JSONObject()
|
||||||
|
.putInt(R.string.key_units, sp, resourceHelper)
|
||||||
.putString(R.string.key_quickwizard, sp, resourceHelper)
|
.putString(R.string.key_quickwizard, sp, resourceHelper)
|
||||||
.putInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
.putInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
||||||
.putDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
.putDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
||||||
|
@ -202,6 +203,7 @@ class OverviewPlugin @Inject constructor(
|
||||||
|
|
||||||
override fun applyConfiguration(configuration: JSONObject) {
|
override fun applyConfiguration(configuration: JSONObject) {
|
||||||
configuration
|
configuration
|
||||||
|
.storeInt(R.string.key_units, sp, resourceHelper)
|
||||||
.storeString(R.string.key_quickwizard, sp, resourceHelper)
|
.storeString(R.string.key_quickwizard, sp, resourceHelper)
|
||||||
.storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
.storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
||||||
.storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
.storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
||||||
|
|
|
@ -46,6 +46,12 @@ interface ActivePlugin {
|
||||||
*/
|
*/
|
||||||
val activeOverview: Overview
|
val activeOverview: Overview
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently selected Safety plugin
|
||||||
|
* Always SafetyPlugin
|
||||||
|
*/
|
||||||
|
val activeSafety: Safety
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of all registered plugins
|
* 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 sensitivityInterface = activePlugin.activeSensitivity
|
||||||
val pumpInterface = activePlugin.activePump
|
val pumpInterface = activePlugin.activePump
|
||||||
val overviewInterface = activePlugin.activeOverview
|
val overviewInterface = activePlugin.activeOverview
|
||||||
|
val safetyInterface = activePlugin.activeSafety
|
||||||
|
|
||||||
json.put("insulin", insulinInterface.id.value)
|
json.put("insulin", insulinInterface.id.value)
|
||||||
json.put("insulinConfiguration", insulinInterface.configuration())
|
json.put("insulinConfiguration", insulinInterface.configuration())
|
||||||
json.put("sensitivity", sensitivityInterface.id.value)
|
json.put("sensitivity", sensitivityInterface.id.value)
|
||||||
json.put("sensitivityConfiguration", sensitivityInterface.configuration())
|
json.put("sensitivityConfiguration", sensitivityInterface.configuration())
|
||||||
json.put("overviewConfiguration", overviewInterface.configuration())
|
json.put("overviewConfiguration", overviewInterface.configuration())
|
||||||
|
json.put("safetyConfiguration", safetyInterface.configuration())
|
||||||
json.put("pump", pumpInterface.model().description)
|
json.put("pump", pumpInterface.model().description)
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
aapsLogger.error("Unhandled exception", e)
|
aapsLogger.error("Unhandled exception", e)
|
||||||
|
@ -88,5 +90,8 @@ class RunningConfiguration @Inject constructor(
|
||||||
|
|
||||||
if (configuration.has("overviewConfiguration"))
|
if (configuration.has("overviewConfiguration"))
|
||||||
activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration"))
|
activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration"))
|
||||||
|
|
||||||
|
if (configuration.has("safetyConfiguration"))
|
||||||
|
activePlugin.activeSafety.applyConfiguration(configuration.getJSONObject("safetyConfiguration"))
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue