Skip to content

Commit

Permalink
Rename condition to statecondition
Browse files Browse the repository at this point in the history
Signed-off-by: Arne Seime <[email protected]>
  • Loading branch information
seime committed Dec 3, 2023
1 parent 280d428 commit 0136882
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bundles/org.smarthomej.transform.basicprofiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Use case: Ignore values from a binding unless some other item(s) have a specific
| 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` |
| `mismatchState` | text | Optional state to pass instead if conditions are NOT met. Use quotes to treat as `StringType`. Defaults to `UNDEF` |

Possible values for token `OPERATOR` in `conditions`:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class StateFilterProfile implements StateProfile {
private final ProfileCallback callback;
private List<Class<? extends State>> acceptedDataTypes;

private List<StateFilterProfile.Condition> conditions = new ArrayList<>();
private List<StateCondition> conditions = new ArrayList<>();

@Nullable
private State configMismatchState = null;
Expand All @@ -71,17 +71,17 @@ private List parseConditions(String config) {
if (config == null)
return List.of();

List<StateFilterProfile.Condition> parsedConditions = new ArrayList<>();
List<StateCondition> parsedConditions = new ArrayList<>();
try {
String[] expressions = config.split(",");
for (String expression : expressions) {
String[] parts = expression.trim().split("\s");
if (parts.length == 3) {
String itemName = parts[0];
Condition.ComparisonType conditionType = Condition.ComparisonType
StateCondition.ComparisonType conditionType = StateCondition.ComparisonType
.valueOf(parts[1].toUpperCase(Locale.ROOT));
String value = parts[2];
parsedConditions.add(new Condition(itemName, conditionType, value));
parsedConditions.add(new StateCondition(itemName, conditionType, value));
} else {
logger.warn("Malformed condition expression: '{}'", expression);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public void onStateUpdateFromHandler(State state) {
private State checkCondition(State state) {
if (!conditions.isEmpty()) {
boolean allConditionsMet = true;
for (Condition condition : conditions) {
for (StateCondition condition : conditions) {
logger.debug("Evaluting condition: {}", condition);
try {
Item item = itemRegistry.getItem(condition.itemName);
Expand Down Expand Up @@ -172,15 +172,15 @@ State parseState(@Nullable String stateString) {
}
}

class Condition {
class StateCondition {
String itemName;

ComparisonType comparisonType;
String value;

boolean quoted = false;

public Condition(String itemName, ComparisonType comparisonType, String value) {
public StateCondition(String itemName, ComparisonType comparisonType, String value) {
this.itemName = itemName;
this.comparisonType = comparisonType;
this.value = value;
Expand Down Expand Up @@ -219,7 +219,7 @@ enum ComparisonType {

@Override
public String toString() {
return "Condition{" + "itemName='" + itemName + '\'' + ", comparisonType=" + comparisonType + ", value='"
return "StateCondition{" + "itemName='" + itemName + '\'' + ", comparisonType=" + comparisonType + ", value='"
+ value + '\'' + '}';
}
}
Expand Down

0 comments on commit 0136882

Please sign in to comment.