From 1f4b75a30db080663e70a1085402fc0ef9801ce2 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 3 Apr 2021 13:35:15 +0200 Subject: [PATCH] Add Rule Title in UserEntry for Automation (as note) --- .../androidaps/plugins/general/automation/AutomationPlugin.kt | 1 + .../androidaps/plugins/general/automation/actions/Action.kt | 2 ++ .../plugins/general/automation/actions/ActionLoopDisable.kt | 2 +- .../plugins/general/automation/actions/ActionLoopEnable.kt | 2 +- .../plugins/general/automation/actions/ActionLoopResume.kt | 2 +- .../plugins/general/automation/actions/ActionLoopSuspend.kt | 2 +- .../plugins/general/automation/actions/ActionProfileSwitch.kt | 2 +- .../general/automation/actions/ActionProfileSwitchPercent.kt | 2 +- .../plugins/general/automation/actions/ActionStartTempTarget.kt | 2 +- .../plugins/general/automation/actions/ActionStopTempTarget.kt | 2 +- 10 files changed, 11 insertions(+), 8 deletions(-) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index 1b72161a43..5fefdddeca 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -203,6 +203,7 @@ class AutomationPlugin @Inject constructor( if (event.systemAction || userEventsEnabled) { val actions = event.actions for (action in actions) { + action.title = event.title if (action.isValid()) action.doAction(object : Callback() { override fun run() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt index a7fe565e58..9d3b86e875 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt @@ -23,6 +23,8 @@ abstract class Action(val injector: HasAndroidInjector) { abstract fun isValid(): Boolean @DrawableRes abstract fun icon(): Int + var title = "" + init { injector.androidInjector().inject(this) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt index 2f1775c070..21da41d170 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt @@ -34,7 +34,7 @@ class ActionLoopDisable(injector: HasAndroidInjector) : Action(injector) { if ((loopPlugin as PluginBase).isEnabled()) { (loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, false) configBuilderPlugin.storeSettings("ActionLoopDisable") - uel.log(UserEntry.Action.LOOP_DISABLED, Sources.Automation) + uel.log(UserEntry.Action.LOOP_DISABLED, Sources.Automation, title) commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { rxBus.send(EventRefreshOverview("ActionLoopDisable")) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt index 21de11bda6..438911d7e1 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt @@ -34,7 +34,7 @@ class ActionLoopEnable(injector: HasAndroidInjector) : Action(injector) { (loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, true) configBuilderPlugin.storeSettings("ActionLoopEnable") rxBus.send(EventRefreshOverview("ActionLoopEnable")) - uel.log(UserEntry.Action.LOOP_ENABLED, Sources.Automation) + uel.log(UserEntry.Action.LOOP_ENABLED, Sources.Automation, title) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } else { callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadyenabled))?.run() diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt index 09281bd2c0..1957bd2beb 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt @@ -32,7 +32,7 @@ class ActionLoopResume(injector: HasAndroidInjector) : Action(injector) { configBuilderPlugin.storeSettings("ActionLoopResume") loopPlugin.createOfflineEvent(0) rxBus.send(EventRefreshOverview("ActionLoopResume")) - uel.log(UserEntry.Action.RESUME, Sources.Automation) + uel.log(UserEntry.Action.RESUME, Sources.Automation, title) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } else { callback.result(PumpEnactResult(injector).success(true).comment(R.string.notsuspended))?.run() diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt index 0a83baf15a..c69e5d002c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt @@ -37,7 +37,7 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) { if (!loopPlugin.isSuspended) { loopPlugin.suspendLoop(minutes.getMinutes()) rxBus.send(EventRefreshOverview("ActionLoopSuspend")) - uel.log(UserEntry.Action.SUSPEND, Sources.Automation, + uel.log(UserEntry.Action.SUSPEND, Sources.Automation, title, XXXValueWithUnit.StringResource(R.string.suspendloopforXmin, listOf(XXXValueWithUnit.Minute(minutes.getMinutes())))) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } else { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt index 8c0cb10925..2017578531 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt @@ -58,7 +58,7 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) { callback.result(PumpEnactResult(injector).success(false).comment(R.string.notexists))?.run() return } - uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, + uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title, XXXValueWithUnit.SimpleString(inputProfileName.value), XXXValueWithUnit.Percent(100)) activePlugin.activeTreatments.doProfileSwitch(profileStore, inputProfileName.value, 0, 100, 0, DateUtil.now()) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt index 193e9fb5ea..71c9e8aef6 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt @@ -42,7 +42,7 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector } override fun doAction(callback: Callback) { - uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, + uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title, if (duration.value == 0) XXXValueWithUnit.StringResource( R.string.startprofileforever, listOf(XXXValueWithUnit.Percent(pct.value.toInt()))) else XXXValueWithUnit.StringResource( R.string.startprofile, listOf(XXXValueWithUnit.Percent(pct.value.toInt()), XXXValueWithUnit.Minute(duration.value)))) activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt index 270f44f216..f73950e5e8 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt @@ -61,7 +61,7 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) { .subscribe({ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") } result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } - uel.log(UserEntry.Action.TT, Sources.Automation, + uel.log(UserEntry.Action.TT, Sources.Automation, title, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.AUTOMATION), XXXValueWithUnit.fromGlucoseUnit(tt().lowTarget, Constants.MGDL), XXXValueWithUnit.fromGlucoseUnit(tt().highTarget, Constants.MGDL).takeIf { tt().lowTarget != tt().highTarget }, diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt index 4c59101ceb..932d7d9d0a 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt @@ -32,7 +32,7 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) { override fun doAction(callback: Callback) { disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(dateUtil._now())) .subscribe({ result -> - uel.log(UserEntry.Action.CANCEL_TT, Sources.Automation) + uel.log(UserEntry.Action.CANCEL_TT, Sources.Automation, title) result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } }, { aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)