fix RunningConfiguration.kt

This commit is contained in:
Milos Kozak 2021-01-18 11:41:29 +01:00
parent 270b6623ea
commit 3f18f94c79

View file

@ -51,33 +51,40 @@ class RunningConfiguration @Inject constructor(
// called in NSClient mode only // called in NSClient mode only
fun apply(configuration: JSONObject) { fun apply(configuration: JSONObject) {
val insulin = InsulinInterface.InsulinType.fromInt(JsonHelper.safeGetInt(configuration, "insulin", InsulinInterface.InsulinType.UNKNOWN.value)) if (configuration.has("insulin")) {
for (p in activePlugin.getSpecificPluginsListByInterface(InsulinInterface::class.java)) { val insulin = InsulinInterface.InsulinType.fromInt(JsonHelper.safeGetInt(configuration, "insulin", InsulinInterface.InsulinType.UNKNOWN.value))
val insulinPlugin = p as InsulinInterface for (p in activePlugin.getSpecificPluginsListByInterface(InsulinInterface::class.java)) {
if (insulinPlugin.id == insulin) { val insulinPlugin = p as InsulinInterface
if (!p.isEnabled()) { if (insulinPlugin.id == insulin) {
aapsLogger.debug(LTag.CORE, "Changing insulin plugin to ${insulin.name}") if (!p.isEnabled()) {
configBuilder.performPluginSwitch(p, true, PluginType.INSULIN) aapsLogger.debug(LTag.CORE, "Changing insulin plugin to ${insulin.name}")
configBuilder.performPluginSwitch(p, true, PluginType.INSULIN)
}
insulinPlugin.applyConfiguration(configuration.getJSONObject("insulinConfiguration"))
} }
insulinPlugin.applyConfiguration(configuration.getJSONObject("insulinConfiguration"))
} }
} }
val sensitivity = SensitivityInterface.SensitivityType.fromInt(JsonHelper.safeGetInt(configuration, "sensitivity", SensitivityInterface.SensitivityType.UNKNOWN.value)) if (configuration.has("sensitivity")) {
for (p in activePlugin.getSpecificPluginsListByInterface(SensitivityInterface::class.java)) { val sensitivity = SensitivityInterface.SensitivityType.fromInt(JsonHelper.safeGetInt(configuration, "sensitivity", SensitivityInterface.SensitivityType.UNKNOWN.value))
val sensitivityPlugin = p as SensitivityInterface for (p in activePlugin.getSpecificPluginsListByInterface(SensitivityInterface::class.java)) {
if (sensitivityPlugin.id == sensitivity) { val sensitivityPlugin = p as SensitivityInterface
if (!p.isEnabled()) { if (sensitivityPlugin.id == sensitivity) {
aapsLogger.debug(LTag.CORE, "Changing sensitivity plugin to ${sensitivity.name}") if (!p.isEnabled()) {
configBuilder.performPluginSwitch(p, true, PluginType.SENSITIVITY) aapsLogger.debug(LTag.CORE, "Changing sensitivity plugin to ${sensitivity.name}")
configBuilder.performPluginSwitch(p, true, PluginType.SENSITIVITY)
}
sensitivityPlugin.applyConfiguration(configuration.getJSONObject("sensitivityConfiguration"))
} }
sensitivityPlugin.applyConfiguration(configuration.getJSONObject("sensitivityConfiguration"))
} }
} }
val pumpType = JsonHelper.safeGetString(configuration, "pump", PumpType.GenericAAPS.description) if (configuration.has("pump")) {
sp.putString(R.string.key_virtualpump_type, pumpType) val pumpType = JsonHelper.safeGetString(configuration, "pump", PumpType.GenericAAPS.description)
activePlugin.activePump.pumpDescription.setPumpDescription(PumpType.getByDescription(pumpType)) sp.putString(R.string.key_virtualpump_type, pumpType)
activePlugin.activePump.pumpDescription.setPumpDescription(PumpType.getByDescription(pumpType))
aapsLogger.debug(LTag.CORE, "Changing pump type to ${pumpType}")
}
if (configuration.has("overviewConfiguration")) if (configuration.has("overviewConfiguration"))
activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration")) activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration"))