AUTOMATION: detect pending profile change

This commit is contained in:
Milos Kozak 2021-12-30 18:03:43 +01:00
parent aee036e200
commit 40864620e0
3 changed files with 17 additions and 0 deletions

View file

@ -136,6 +136,12 @@ class ProfileFunctionImplementation @Inject constructor(
override fun getRequestedProfile(): ProfileSwitch? = repository.getActiveProfileSwitch(dateUtil.now())
override fun isProfileChangePending(): Boolean {
val requested = getRequestedProfile() ?: return false
val running = getProfile() ?: return true
return !ProfileSealed.PS(requested).isEqual(running)
}
override fun getUnits(): GlucoseUnit =
if (sp.getString(R.string.key_units, Constants.MGDL) == Constants.MGDL) GlucoseUnit.MGDL
else GlucoseUnit.MMOL

View file

@ -41,6 +41,10 @@ class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) {
override fun shouldRun(): Boolean {
val profile = profileFunction.getProfile()
if (profileFunction.isProfileChangePending()) {
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + "Profile change is already pending: " + friendlyDescription())
return false
}
if (profile == null && comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
return true

View file

@ -46,6 +46,13 @@ interface ProfileFunction {
*/
fun getRequestedProfile(): ProfileSwitch?
/**
* Get requested profile by user (profile must not be active yet)
*
* @return true if ProfileSwitch != EffectiveProfileSwitch
*/
fun isProfileChangePending(): Boolean
/**
* Build a new circadian profile switch request based on provided profile
*