diff --git a/bundles/org.smarthomej.transform.basicprofiles/README.md b/bundles/org.smarthomej.transform.basicprofiles/README.md index 6da4462631..7b5e4ee074 100644 --- a/bundles/org.smarthomej.transform.basicprofiles/README.md +++ b/bundles/org.smarthomej.transform.basicprofiles/README.md @@ -189,16 +189,18 @@ Use case: Ignore values from a binding unless some other item(s) have a specific ### Configuration -| Configuration Parameter | Type | Description | -|-------------------------|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `conditions` | text | Comma separated list of expressions on the format `ITEM_NAME OPERATOR ITEM_STATE`, ie `MyItem EQ OFF`. Use quotes around `ITEM_STATE` to treat value as string ie `'OFF`' | -| `mismatchState` | text | Optional state to pass instead if conditions are NOT met. Use quotes to treat as `StringType`. Defaults to `UNDEF` | +| Configuration Parameter | Type | Description | +|-------------------------|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `conditions` | text | Comma separated list of expressions on the format `ITEM_NAME OPERATOR ITEM_STATE`, ie `MyItem EQ OFF`. Use quotes around `ITEM_STATE` to treat value as string ie `'OFF'` and not `OnOffType.OFF` | +| `mismatchState` | text | Optional state to pass instead if conditions are NOT met. Use single quotes to treat as `StringType`. Defaults to `UNDEF` | +| `separator` | text | Optional separator string to separate expressions when using multiple. Defaults to `,` | Possible values for token `OPERATOR` in `conditions`: - `EQ` - Equals - `NEQ` - Not equals + ### Full Example ```Java diff --git a/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/config/StateFilterProfileConfig.java b/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/config/StateFilterProfileConfig.java index 006438f9b3..77f1c81f0c 100644 --- a/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/config/StateFilterProfileConfig.java +++ b/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/config/StateFilterProfileConfig.java @@ -27,4 +27,6 @@ public class StateFilterProfileConfig { public String conditions = ""; public String mismatchState = UnDefType.UNDEF.toString(); + + public String separator = ","; } diff --git a/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/profiles/StateFilterProfile.java b/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/profiles/StateFilterProfile.java index 8cfc753268..0e5eb83890 100644 --- a/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/profiles/StateFilterProfile.java +++ b/bundles/org.smarthomej.transform.basicprofiles/src/main/java/org/smarthomej/transform/basicprofiles/internal/profiles/StateFilterProfile.java @@ -62,18 +62,18 @@ public StateFilterProfile(ProfileCallback callback, ProfileContext context, Item StateFilterProfileConfig config = context.getConfiguration().as(StateFilterProfileConfig.class); if (config != null) { - conditions.addAll(parseConditions(config.conditions)); + conditions.addAll(parseConditions(config.conditions, config.separator)); configMismatchState = parseState(config.mismatchState); } } - private List parseConditions(String config) { + private List parseConditions(@Nullable String config, String separator) { if (config == null) return List.of(); List parsedConditions = new ArrayList<>(); try { - String[] expressions = config.split(","); + String[] expressions = config.split(separator); for (String expression : expressions) { String[] parts = expression.trim().split("\s"); if (parts.length == 3) { @@ -193,15 +193,9 @@ public StateCondition(String itemName, ComparisonType comparisonType, String val public boolean matches(String state) { switch (comparisonType) { case EQ: - if (!state.equals(value)) { - return false; - } - break; + return state.equals(value); case NEQ: { - if (state.equals(value)) { - return false; - } - break; + return !state.equals(value); } default: logger.warn("Unknown condition type {}. Expected 'eq' or 'neq' - skipping state update", @@ -209,7 +203,6 @@ public boolean matches(String state) { return false; } - return true; } enum ComparisonType { @@ -219,8 +212,8 @@ enum ComparisonType { @Override public String toString() { - return "StateCondition{" + "itemName='" + itemName + '\'' + ", comparisonType=" + comparisonType + ", value='" - + value + '\'' + '}'; + return "Condition{itemName='" + itemName + "', comparisonType=" + comparisonType + ", value='" + + value + "'}'"; } } }