From 087a51112046bf168f563b04d3bb78adde66cecf Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Fri, 24 Jan 2025 05:02:09 +1000 Subject: [PATCH] [basicprofiles] Fix handling of multiple `$DELTA` conditions (#18088) Signed-off-by: Jimmy Tanagra --- .../internal/profiles/StateFilterProfile.java | 7 +------ .../internal/profiles/StateFilterProfileTest.java | 4 ++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfile.java b/bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfile.java index bbb483c6f50ef..12d8442093398 100644 --- a/bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfile.java +++ b/bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfile.java @@ -230,6 +230,7 @@ private State checkCondition(State state) { } if (conditions.stream().allMatch(c -> c.check(state))) { + acceptedState = state; return state; } else { return configMismatchState; @@ -349,7 +350,6 @@ public boolean check(State input) { } else if (rhsState instanceof FunctionType rhsFunction) { if (acceptedState == UnDefType.UNDEF && (rhsFunction.getType() == FunctionType.Function.DELTA || rhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) { - acceptedState = input; return true; } rhsItem = getLinkedItem(); @@ -371,7 +371,6 @@ public boolean check(State input) { } else if (lhsState instanceof FunctionType lhsFunction) { if (acceptedState == UnDefType.UNDEF && (lhsFunction.getType() == FunctionType.Function.DELTA || lhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) { - acceptedState = input; return true; } lhsItem = getLinkedItem(); @@ -444,10 +443,6 @@ public boolean check(State input) { case LTE -> ((Comparable) lhs).compareTo(rhs) <= 0; }; - if (result) { - acceptedState = input; - } - return result; } catch (IllegalArgumentException | ClassCastException e) { logger.warn("Error evaluating condition: {} in link '{}': {}", this, callback.getItemChannelLink(), diff --git a/bundles/org.openhab.transform.basicprofiles/src/test/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfileTest.java b/bundles/org.openhab.transform.basicprofiles/src/test/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfileTest.java index ee781be0f49d6..ef1660a765508 100644 --- a/bundles/org.openhab.transform.basicprofiles/src/test/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfileTest.java +++ b/bundles/org.openhab.transform.basicprofiles/src/test/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfileTest.java @@ -690,6 +690,10 @@ public static Stream testFunctions() { Arguments.of(decimalItem, "$DELTA >= 1", decimals, DecimalType.valueOf("10"), true), // Arguments.of(decimalItem, "$DELTA >= 1", decimals, DecimalType.valueOf("5.5"), false), // + // Multiple delta conditions + Arguments.of(decimalItem, "$DELTA >= 1, $DELTA <= 10", decimals, DecimalType.valueOf("15"), true), // + Arguments.of(decimalItem, "$DELTA >= 1, $DELTA <= 10", decimals, DecimalType.valueOf("16"), false), // + Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("4.6"), false), // Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("4.5"), true), // Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("5.4"), false), //