mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +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
@ -230,6 +230,7 @@ public class StateFilterProfile implements StateProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conditions.stream().allMatch(c -> c.check(state))) {
|
if (conditions.stream().allMatch(c -> c.check(state))) {
|
||||||
|
acceptedState = state;
|
||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
return configMismatchState;
|
return configMismatchState;
|
||||||
@ -344,7 +345,6 @@ public class StateFilterProfile implements StateProfile {
|
|||||||
} else if (rhsState instanceof FunctionType rhsFunction) {
|
} else if (rhsState instanceof FunctionType rhsFunction) {
|
||||||
if (acceptedState == UnDefType.UNDEF && (rhsFunction.getType() == FunctionType.Function.DELTA
|
if (acceptedState == UnDefType.UNDEF && (rhsFunction.getType() == FunctionType.Function.DELTA
|
||||||
|| rhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) {
|
|| rhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) {
|
||||||
acceptedState = input;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
rhsItem = getLinkedItem();
|
rhsItem = getLinkedItem();
|
||||||
@ -366,7 +366,6 @@ public class StateFilterProfile implements StateProfile {
|
|||||||
} else if (lhsState instanceof FunctionType lhsFunction) {
|
} else if (lhsState instanceof FunctionType lhsFunction) {
|
||||||
if (acceptedState == UnDefType.UNDEF && (lhsFunction.getType() == FunctionType.Function.DELTA
|
if (acceptedState == UnDefType.UNDEF && (lhsFunction.getType() == FunctionType.Function.DELTA
|
||||||
|| lhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) {
|
|| lhsFunction.getType() == FunctionType.Function.DELTA_PERCENT)) {
|
||||||
acceptedState = input;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
lhsItem = getLinkedItem();
|
lhsItem = getLinkedItem();
|
||||||
@ -439,10 +438,6 @@ public class StateFilterProfile implements StateProfile {
|
|||||||
case LTE -> ((Comparable) lhs).compareTo(rhs) <= 0;
|
case LTE -> ((Comparable) lhs).compareTo(rhs) <= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (result) {
|
|
||||||
acceptedState = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (IllegalArgumentException | ClassCastException e) {
|
} catch (IllegalArgumentException | ClassCastException e) {
|
||||||
logger.warn("Error evaluating condition: {} in link '{}': {}", this, callback.getItemChannelLink(),
|
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("10"), true), //
|
||||||
Arguments.of(decimalItem, "$DELTA >= 1", decimals, DecimalType.valueOf("5.5"), false), //
|
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.6"), false), //
|
||||||
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("4.5"), true), //
|
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("4.5"), true), //
|
||||||
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("5.4"), false), //
|
Arguments.of(decimalItem, "$DELTA_PERCENT >= 10", decimals, DecimalType.valueOf("5.4"), false), //
|
||||||
|
Loading…
Reference in New Issue
Block a user