mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-03 19:04:04 +01:00
[basicprofiles] Fix handling of multiple $DELTA
conditions (#18088)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
parent
eadf63fa17
commit
783bcce165
bundles/org.openhab.transform.basicprofiles/src
main/java/org/openhab/transform/basicprofiles/internal/profiles
test/java/org/openhab/transform/basicprofiles/internal/profiles
@ -230,6 +230,7 @@ public class StateFilterProfile implements StateProfile {
|
||||
}
|
||||
|
||||
if (conditions.stream().allMatch(c -> c.check(state))) {
|
||||
acceptedState = state;
|
||||
return state;
|
||||
} else {
|
||||
return configMismatchState;
|
||||
@ -344,7 +345,6 @@ public class StateFilterProfile implements StateProfile {
|
||||
} 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();
|
||||
@ -366,7 +366,6 @@ public class StateFilterProfile implements StateProfile {
|
||||
} 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();
|
||||
@ -439,10 +438,6 @@ public class StateFilterProfile implements StateProfile {
|
||||
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(),
|
||||
|
@ -677,6 +677,10 @@ public class StateFilterProfileTest {
|
||||
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), //
|
||||
|
Loading…
Reference in New Issue
Block a user