Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automations specific to AutoISF #3854

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/data/src/main/kotlin/app/aaps/core/data/ue/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ enum class Action(val colorGroup: ColorGroup) {
EXIT_AAPS(ColorGroup.Aaps),
PLUGIN_ENABLED(ColorGroup.Aaps),
PLUGIN_DISABLED(ColorGroup.Aaps),
AUTOISF_ENABLED (ColorGroup.Aaps),
AUTOISF_DISABLED (ColorGroup.Aaps),
IOB_TH_SET (ColorGroup.Aaps),
ACCE_WEIGHT_SET (ColorGroup.Aaps),
UNKNOWN(ColorGroup.Aaps)
;

Expand Down
5 changes: 5 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@
<string name="autotune_tune_days">Tune days :</string>
<string name="autotune_select_profile">Select profile to tune</string>

<!-- AutoISF -->
<string name="uel_autoisf_enabled">AUTOISF ENABLED</string>
<string name="uel_autoisf_disabled">AUTOISF DISABLED</string>
<string name="uel_iobth_set">IOBTH SET</string>
<string name="uel_acce_weight_set">ACCE WeIGHT SET</string>

<!-- Alerts -->
<string name="key_raise_notifications_as_android_notifications" translatable="false">raise_urgent_alarms_as_android_notification</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ data class UserEntry(
EXIT_AAPS,
PLUGIN_ENABLED,
PLUGIN_DISABLED,
AUTOISF_ENABLED,
AUTOISF_DISABLED,
IOB_TH_SET,
ACCE_WEIGHT_SET,
UNKNOWN
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ fun UserEntry.Action.fromDb(): Action =
UserEntry.Action.EXIT_AAPS -> Action.EXIT_AAPS
UserEntry.Action.PLUGIN_ENABLED -> Action.PLUGIN_ENABLED
UserEntry.Action.PLUGIN_DISABLED -> Action.PLUGIN_DISABLED
UserEntry.Action.AUTOISF_ENABLED -> Action.AUTOISF_ENABLED
UserEntry.Action.AUTOISF_DISABLED -> Action.AUTOISF_DISABLED
UserEntry.Action.IOB_TH_SET -> Action.IOB_TH_SET
UserEntry.Action.ACCE_WEIGHT_SET -> Action.ACCE_WEIGHT_SET
UserEntry.Action.UNKNOWN -> Action.UNKNOWN
}

Expand Down Expand Up @@ -184,6 +188,10 @@ fun Action.toDb(): UserEntry.Action =
Action.EXIT_AAPS -> UserEntry.Action.EXIT_AAPS
Action.PLUGIN_ENABLED -> UserEntry.Action.PLUGIN_ENABLED
Action.PLUGIN_DISABLED -> UserEntry.Action.PLUGIN_DISABLED
Action.AUTOISF_ENABLED -> UserEntry.Action.AUTOISF_ENABLED
Action.AUTOISF_DISABLED -> UserEntry.Action.AUTOISF_DISABLED
Action.IOB_TH_SET -> UserEntry.Action.IOB_TH_SET
Action.ACCE_WEIGHT_SET -> UserEntry.Action.ACCE_WEIGHT_SET
Action.UNKNOWN -> UserEntry.Action.UNKNOWN
}

Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class TranslatorImpl @Inject internal constructor(
Action.PLUGIN_DISABLED -> rh.gs(app.aaps.core.ui.R.string.uel_plugin_disabled)
Action.LOOP_CHANGE -> rh.gs(app.aaps.core.ui.R.string.uel_loop_change)
Action.LOOP_REMOVED -> rh.gs(app.aaps.core.ui.R.string.uel_loop_removed)
Action.AUTOISF_ENABLED -> rh.gs(app.aaps.core.ui.R.string.uel_autoisf_enabled)
Action.AUTOISF_DISABLED -> rh.gs(app.aaps.core.ui.R.string.uel_autoisf_disabled)
Action.IOB_TH_SET -> rh.gs(app.aaps.core.ui.R.string.uel_iobth_set)
Action.ACCE_WEIGHT_SET -> rh.gs(app.aaps.core.ui.R.string.uel_acce_weight_set)
Action.UNKNOWN -> rh.gs(app.aaps.core.ui.R.string.unknown)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ import app.aaps.core.keys.StringKey
import app.aaps.core.validators.preferences.AdaptiveListPreference
import app.aaps.plugins.automation.actions.Action
import app.aaps.plugins.automation.actions.ActionAlarm
import app.aaps.plugins.automation.actions.ActionAutoisfDisable
import app.aaps.plugins.automation.actions.ActionAutoisfEnable
import app.aaps.plugins.automation.actions.ActionCarePortalEvent
import app.aaps.plugins.automation.actions.ActionNotification
import app.aaps.plugins.automation.actions.ActionProfileSwitch
import app.aaps.plugins.automation.actions.ActionProfileSwitchPercent
import app.aaps.plugins.automation.actions.ActionRunAutotune
import app.aaps.plugins.automation.actions.ActionSendSMS
import app.aaps.plugins.automation.actions.ActionSetAcceWeight
import app.aaps.plugins.automation.actions.ActionSetIobTH
import app.aaps.plugins.automation.actions.ActionSettingsExport
import app.aaps.plugins.automation.actions.ActionStartTempTarget
import app.aaps.plugins.automation.actions.ActionStopProcessing
Expand All @@ -57,6 +61,7 @@ import app.aaps.plugins.automation.triggers.Trigger
import app.aaps.plugins.automation.triggers.TriggerAutosensValue
import app.aaps.plugins.automation.triggers.TriggerBTDevice
import app.aaps.plugins.automation.triggers.TriggerBg
import app.aaps.plugins.automation.triggers.TriggerBgAcceWeight
import app.aaps.plugins.automation.triggers.TriggerBolusAgo
import app.aaps.plugins.automation.triggers.TriggerCOB
import app.aaps.plugins.automation.triggers.TriggerCannulaAge
Expand All @@ -65,6 +70,7 @@ import app.aaps.plugins.automation.triggers.TriggerDelta
import app.aaps.plugins.automation.triggers.TriggerHeartRate
import app.aaps.plugins.automation.triggers.TriggerInsulinAge
import app.aaps.plugins.automation.triggers.TriggerIob
import app.aaps.plugins.automation.triggers.TriggerIobTH
import app.aaps.plugins.automation.triggers.TriggerLocation
import app.aaps.plugins.automation.triggers.TriggerPodChange
import app.aaps.plugins.automation.triggers.TriggerProfilePercent
Expand Down Expand Up @@ -397,9 +403,13 @@ class AutomationPlugin @Inject constructor(
ActionProfileSwitch(injector),
ActionSendSMS(injector)
)
if (config.isEngineeringMode() && config.isDev())
if (config.isEngineeringMode() && config.isDev()) {
actions.add(ActionRunAutotune(injector))

actions.add(ActionAutoisfEnable(injector))
actions.add(ActionAutoisfDisable(injector))
actions.add(ActionSetAcceWeight(injector))
actions.add(ActionSetIobTH(injector))
}
return actions.toList()
}

Expand Down Expand Up @@ -428,6 +438,10 @@ class AutomationPlugin @Inject constructor(
TriggerReservoirLevel(injector),
TriggerStepsCount(injector)
)
if (config.isEngineeringMode() && config.isDev()) {
triggers.add(TriggerBgAcceWeight(injector))
triggers.add(TriggerIobTH(injector))
}

val pump = activePlugin.activePump

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ abstract class Action(val injector: HasAndroidInjector) {
ActionNotification::class.java.simpleName -> ActionNotification(injector).fromJSON(data.toString())
ActionProfileSwitch::class.java.simpleName -> ActionProfileSwitch(injector).fromJSON(data.toString())
ActionProfileSwitchPercent::class.java.simpleName -> ActionProfileSwitchPercent(injector).fromJSON(data.toString())
ActionAutoisfEnable::class.java.simpleName -> ActionAutoisfEnable(injector).fromJSON(data.toString())
ActionAutoisfDisable::class.java.simpleName -> ActionAutoisfDisable(injector).fromJSON(data.toString())
ActionSetAcceWeight::class.java.simpleName -> ActionSetAcceWeight(injector).fromJSON(data.toString())
ActionSetIobTH::class.java.simpleName -> ActionSetIobTH(injector).fromJSON(data.toString())
ActionRunAutotune::class.java.simpleName -> ActionRunAutotune(injector).fromJSON(data.toString())
ActionSendSMS::class.java.simpleName -> ActionSendSMS(injector).fromJSON(data.toString())
ActionStartTempTarget::class.java.simpleName -> ActionStartTempTarget(injector).fromJSON(data.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package app.aaps.plugins.automation.actions

import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector
import app.aaps.core.data.ue.Sources
import app.aaps.core.interfaces.logging.UserEntryLogger
import app.aaps.core.interfaces.queue.Callback
import app.aaps.core.interfaces.sharedPreferences.SP
import app.aaps.plugins.automation.R
import javax.inject.Inject

class ActionAutoisfDisable(injector: HasAndroidInjector) : Action(injector) {

@Inject lateinit var uel: UserEntryLogger
@Inject lateinit var sp: SP

override fun friendlyName(): Int = R.string.disableautoisf
override fun shortDescription(): String = rh.gs(R.string.disableautoisf)
@DrawableRes override fun icon(): Int = R.drawable.ic_autoisf_disabled

override fun doAction(callback: Callback) {
val currentAutoisfStatus: Boolean = sp.getBoolean(R.string.enable_autoISF, false)
if (currentAutoisfStatus) {
uel.log(app.aaps.core.data.ue.Action.AUTOISF_DISABLED, Sources.Automation, title)
sp.putBoolean(R.string.enable_autoISF, false)
callback.result(instantiator.providePumpEnactResult().success(true).comment(R.string.autoisf_disabled)).run()
} else {
callback.result(instantiator.providePumpEnactResult().success(true).comment(R.string.autoisf_alreadydisabled)).run()
}
}

override fun isValid(): Boolean = true

override fun hasDialog(): Boolean = false

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package app.aaps.plugins.automation.actions

import android.widget.LinearLayout
import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector
import app.aaps.core.data.ue.Sources
import app.aaps.core.interfaces.logging.UserEntryLogger
import app.aaps.core.interfaces.queue.Callback
import app.aaps.core.interfaces.sharedPreferences.SP
import app.aaps.core.utils.JsonHelper
import app.aaps.plugins.automation.elements.InputWeight
import app.aaps.plugins.automation.elements.LabelWithElement
import app.aaps.plugins.automation.elements.LayoutBuilder
import app.aaps.plugins.automation.R
import org.json.JSONObject
import javax.inject.Inject

class ActionSetAcceWeight(injector: HasAndroidInjector) : Action(injector) {

@Inject lateinit var uel: UserEntryLogger
@Inject lateinit var sp: SP

override fun friendlyName(): Int = R.string.autoisf_acce_weight
override fun shortDescription(): String = rh.gs(R.string.automate_set_acce_weight, new_weight.value)
@DrawableRes override fun icon(): Int = R.drawable.ic_acce_weight

var new_weight = InputWeight( )

override fun doAction(callback: Callback) {
val currentAcceWeight:Double = sp.getDouble(R.string.bgAccel_ISF_weight, 0.0)
if (currentAcceWeight != new_weight.value) {
uel.log(
app.aaps.core.data.ue.Action.ACCE_WEIGHT_SET,
Sources.Automation,
title + ": " + rh.gs(R.string.automate_set_acce_weight, new_weight.value)
)
sp.putDouble(R.string.bgAccel_ISF_weight, new_weight.value)
callback.result(instantiator.providePumpEnactResult().success(true).comment(R.string.weight_new)).run()
} else {
callback.result(instantiator.providePumpEnactResult().success(false).comment(R.string.weight_old)).run()
}
}

override fun hasDialog(): Boolean {
return true
}

override fun generateDialog(root: LinearLayout) {
LayoutBuilder()
.add(LabelWithElement(rh, rh.gs(R.string.autoisf_acce_weight), "", new_weight))
.build(root)
}

override fun toJSON(): String {
val data = JSONObject()
.put("weight", new_weight.value)
return JSONObject()
.put("type", this.javaClass.name)
.put("data", data)
.toString()
}

override fun fromJSON(data: String): Action {
val o = JSONObject(data)
new_weight.value = JsonHelper.safeGetDouble(o, "weight")
return this
}
override fun isValid(): Boolean = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package app.aaps.plugins.automation.actions

import android.widget.LinearLayout
import androidx.annotation.DrawableRes
import dagger.android.HasAndroidInjector
import app.aaps.core.data.ue.Sources
import app.aaps.core.data.ue.ValueWithUnit
import app.aaps.core.interfaces.logging.UserEntryLogger
import app.aaps.core.interfaces.queue.Callback
import app.aaps.core.interfaces.sharedPreferences.SP
import app.aaps.core.utils.JsonHelper
import app.aaps.plugins.automation.elements.InputIobTH
import app.aaps.plugins.automation.elements.LabelWithElement
import app.aaps.plugins.automation.elements.LayoutBuilder
import app.aaps.plugins.automation.R
import org.json.JSONObject
import javax.inject.Inject

class ActionSetIobTH(injector: HasAndroidInjector) : Action(injector) {

@Inject lateinit var uel: UserEntryLogger
@Inject lateinit var sp: SP

var new_iobTH = InputIobTH ( )
// new_weight.value = 1

override fun friendlyName(): Int = R.string.autoisf_iobTH_percent
override fun shortDescription(): String = rh.gs(R.string.automate_set_iobTH_percent, new_iobTH.value.toInt())
@DrawableRes override fun icon(): Int = R.drawable.ic_iobth

override fun doAction(callback: Callback) {
val currentIobTH:Int = sp.getInt(R.string.iob_threshold_percent, 100)
if (currentIobTH != new_iobTH.value) {
uel.log(
app.aaps.core.data.ue.Action.IOB_TH_SET,
Sources.Automation,
title + ": " + rh.gs(R.string.automate_set_iobTH_percent, new_iobTH.value.toInt()),
ValueWithUnit.Percent(new_iobTH.value.toInt())
)
sp.putInt(R.string.iob_threshold_percent, new_iobTH.value)
callback.result(instantiator.providePumpEnactResult().success(true).comment(R.string.weight_new)).run()
} else {
callback.result(instantiator.providePumpEnactResult().success(false).comment(R.string.weight_old)).run()
}
}

override fun hasDialog(): Boolean {
return true
}

override fun generateDialog(root: LinearLayout) {
LayoutBuilder()
.add(LabelWithElement(rh, rh.gs(R.string.autoisf_iobTH_percent), "%", new_iobTH))
.build(root)
}

override fun toJSON(): String {
val data = JSONObject()
.put("percentage", new_iobTH.value)
return JSONObject()
.put("type", this.javaClass.name)
.put("data", data)
.toString()
}

override fun fromJSON(data: String): Action {
val o = JSONObject(data)
new_iobTH.value = JsonHelper.safeGetInt(o, "percentage")
return this
}

override fun isValid(): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import app.aaps.plugins.automation.AutomationFragment
import app.aaps.plugins.automation.AutomationPlugin
import app.aaps.plugins.automation.actions.Action
import app.aaps.plugins.automation.actions.ActionAlarm
import app.aaps.plugins.automation.actions.ActionAutoisfDisable
import app.aaps.plugins.automation.actions.ActionAutoisfEnable
import app.aaps.plugins.automation.actions.ActionSettingsExport
import app.aaps.plugins.automation.actions.ActionCarePortalEvent
import app.aaps.plugins.automation.actions.ActionDummy
Expand All @@ -18,6 +20,8 @@ import app.aaps.plugins.automation.actions.ActionProfileSwitch
import app.aaps.plugins.automation.actions.ActionProfileSwitchPercent
import app.aaps.plugins.automation.actions.ActionRunAutotune
import app.aaps.plugins.automation.actions.ActionSendSMS
import app.aaps.plugins.automation.actions.ActionSetAcceWeight
import app.aaps.plugins.automation.actions.ActionSetIobTH
import app.aaps.plugins.automation.actions.ActionStartTempTarget
import app.aaps.plugins.automation.actions.ActionStopProcessing
import app.aaps.plugins.automation.actions.ActionStopTempTarget
Expand All @@ -32,6 +36,7 @@ import app.aaps.plugins.automation.triggers.Trigger
import app.aaps.plugins.automation.triggers.TriggerAutosensValue
import app.aaps.plugins.automation.triggers.TriggerBTDevice
import app.aaps.plugins.automation.triggers.TriggerBg
import app.aaps.plugins.automation.triggers.TriggerBgAcceWeight
import app.aaps.plugins.automation.triggers.TriggerBolusAgo
import app.aaps.plugins.automation.triggers.TriggerCOB
import app.aaps.plugins.automation.triggers.TriggerCannulaAge
Expand All @@ -41,6 +46,7 @@ import app.aaps.plugins.automation.triggers.TriggerDummy
import app.aaps.plugins.automation.triggers.TriggerHeartRate
import app.aaps.plugins.automation.triggers.TriggerInsulinAge
import app.aaps.plugins.automation.triggers.TriggerIob
import app.aaps.plugins.automation.triggers.TriggerIobTH
import app.aaps.plugins.automation.triggers.TriggerLocation
import app.aaps.plugins.automation.triggers.TriggerPodChange
import app.aaps.plugins.automation.triggers.TriggerProfilePercent
Expand Down Expand Up @@ -105,6 +111,8 @@ abstract class AutomationModule {
@ContributesAndroidInjector abstract fun triggerTimeRangeInjector(): TriggerTimeRange
@ContributesAndroidInjector abstract fun triggerWifiSsidInjector(): TriggerWifiSsid
@ContributesAndroidInjector abstract fun triggerStepsCountInjector(): TriggerStepsCount
@ContributesAndroidInjector abstract fun triggerBgAcceWeightInjector(): TriggerBgAcceWeight
@ContributesAndroidInjector abstract fun triggerIonTHWeightInjector(): TriggerIobTH

@ContributesAndroidInjector abstract fun actionInjector(): Action
@ContributesAndroidInjector abstract fun actionStopProcessingInjector(): ActionStopProcessing
Expand All @@ -119,6 +127,10 @@ abstract class AutomationModule {
@ContributesAndroidInjector abstract fun actionProfileSwitchInjector(): ActionProfileSwitch
@ContributesAndroidInjector abstract fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent
@ContributesAndroidInjector abstract fun actionRunAutotuneInjector(): ActionRunAutotune
@ContributesAndroidInjector abstract fun actionAutoisfEnableInjector(): ActionAutoisfEnable
@ContributesAndroidInjector abstract fun actionAutoisfDisableInjector(): ActionAutoisfDisable
@ContributesAndroidInjector abstract fun actionSetAcceWeightInjector(): ActionSetAcceWeight
@ContributesAndroidInjector abstract fun actionSetIobTHInjector(): ActionSetIobTH
@ContributesAndroidInjector abstract fun actionSendSMSInjector(): ActionSendSMS
@ContributesAndroidInjector abstract fun actionStartTempTargetInjector(): ActionStartTempTarget
@ContributesAndroidInjector abstract fun actionStopTempTargetInjector(): ActionStopTempTarget
Expand Down
Loading