Skip to content

Commit

Permalink
[basicprofiles] Fix handling of multiple $DELTA conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Jan 11, 2025
1 parent a1fc363 commit c21d429
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ private State checkCondition(State state) {
}

if (conditions.stream().allMatch(c -> c.check(state))) {
acceptedState = state;
return state;
} else {
return configMismatchState;
Expand Down Expand Up @@ -344,7 +345,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();
Expand All @@ -366,7 +366,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();
Expand Down Expand Up @@ -439,10 +438,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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ public static Stream<Arguments> 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), //
Expand Down

0 comments on commit c21d429

Please sign in to comment.