Skip to content

Commit 087a511

Browse files
authored
[basicprofiles] Fix handling of multiple $DELTA conditions (openhab#18088)
Signed-off-by: Jimmy Tanagra <[email protected]>
1 parent 28b2509 commit 087a511

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfile.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ private State checkCondition(State state) {
230230
}
231231

232232
if (conditions.stream().allMatch(c -> c.check(state))) {
233+
acceptedState = state;
233234
return state;
234235
} else {
235236
return configMismatchState;
@@ -349,7 +350,6 @@ public boolean check(State input) {
349350
} else if (rhsState instanceof FunctionType rhsFunction) {
350351
if (acceptedState == UnDefType.UNDEF && (rhsFunction.getType() == FunctionType.Function.DELTA
351352
|| rhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) {
352-
acceptedState = input;
353353
return true;
354354
}
355355
rhsItem = getLinkedItem();
@@ -371,7 +371,6 @@ public boolean check(State input) {
371371
} else if (lhsState instanceof FunctionType lhsFunction) {
372372
if (acceptedState == UnDefType.UNDEF && (lhsFunction.getType() == FunctionType.Function.DELTA
373373
|| lhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) {
374-
acceptedState = input;
375374
return true;
376375
}
377376
lhsItem = getLinkedItem();
@@ -444,10 +443,6 @@ public boolean check(State input) {
444443
case LTE -> ((Comparable) lhs).compareTo(rhs) <= 0;
445444
};
446445

447-
if (result) {
448-
acceptedState = input;
449-
}
450-
451446
return result;
452447
} catch (IllegalArgumentException | ClassCastException e) {
453448
logger.warn("Error evaluating condition: {} in link '{}': {}", this, callback.getItemChannelLink(),

bundles/org.openhab.transform.basicprofiles/src/test/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfileTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ public static Stream<Arguments> testFunctions() {
690690
Arguments.of(decimalItem, "$DELTA >= 1", decimals, DecimalType.valueOf("10"), true), //
691691
Arguments.of(decimalItem, "$DELTA >= 1", decimals, DecimalType.valueOf("5.5"), false), //
692692

693+
// Multiple delta conditions
694+
Arguments.of(decimalItem, "$DELTA >= 1, $DELTA <= 10", decimals, DecimalType.valueOf("15"), true), //
695+
Arguments.of(decimalItem, "$DELTA >= 1, $DELTA <= 10", decimals, DecimalType.valueOf("16"), false), //
696+
693697
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("4.6"), false), //
694698
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("4.5"), true), //
695699
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("5.4"), false), //

0 commit comments

Comments
 (0)