Skip to content
Snippets Groups Projects
Commit ab67f9f4 authored by Manuel Krombholz's avatar Manuel Krombholz
Browse files

Added rule frontend to wiki

parent 3b405c89
No related branches found
No related tags found
1 merge request!17Resolve "Add frontend for rules"
Pipeline #10199 passed
......@@ -296,12 +296,12 @@ aspect Printing {
//TriggerRuleAction
eq TriggerRuleAction.prettyPrint() {
return "Action: TriggerRuleAction " + getRule().getID();
return "Action: TriggerRule " + getRule().getID();
}
//NoopAction
eq NoopAction.prettyPrint() {
return "Action: NoopAction";
return "Action: Noop";
}
//SetStateFromConstantStringAction
......
......@@ -74,8 +74,8 @@ Comment = "//" [^\n\r]+
// actions and conditions
"ItemStateCheck" { return sym(Terminals.ITEM_STATE_CHECK); }
"ItemStateChange" { return sym(Terminals.ITEM_STATE_CHANGE); }
"NoopAction" { return sym(Terminals.NOOP_ACTION); }
"TriggerRuleAction" { return sym(Terminals.TRIGGER_RULE_ACTION); }
"Noop" { return sym(Terminals.NOOP_ACTION); }
"TriggerRule" { return sym(Terminals.TRIGGER_RULE_ACTION); }
"SetStateFromConstant" { return sym(Terminals.STATE_FROM_CONST_ACTION); }
"SetStateFromTrigger" { return sym(Terminals.STATE_FROM_TRIGGER_ACTION); }
// within specification
......
......@@ -597,44 +597,6 @@ public class RulesTest {
}
}
@Test
public void testSetStateFromLambdaAction() {
ValuedStateProvider provider = new ValuedStateProvider();
TestUtils.ModelAndItem modelAndItem = createModelAndItem(0);
Root root = modelAndItem.model.getRoot();
NumberItem item = modelAndItem.item;
NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 3, true);
Rule rule = new Rule();
rule.addAction(new SetStateFromLambdaAction().setNewStateProvider(provider).setAffectedItem(item2));
CountingAction counter = new CountingAction();
rule.addAction(counter);
root.addRule(rule);
rule.activateFor(item);
assertEquals(3, item2.asItemWithDoubleState().getState(), DELTA, "Affected item not initialized correctly");
provider.value = 4;
setState(item, 1);
assertEquals(1, counter.get(item), "Change of item state should trigger the rule");
assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item");
provider.value = 4;
setState(item, 2);
assertEquals(2, counter.get(item), "Change of item state should trigger the rule");
assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item");
provider.value = 5;
setState(item, 2);
assertEquals(2, counter.get(item), "Change of item to same state should not trigger the rule");
assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Change of item to same state should not set the state of the affected item");
provider.value = 5;
setState(item, 3);
assertEquals(3, counter.get(item), "Change of item state should trigger the rule");
assertEquals(5, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item");
}
@Test
public void testSetStateFromTriggeringItemAction() {
TestUtils.ModelAndItem modelAndItem = createModelAndItem(3);
......
......@@ -3,9 +3,9 @@ Color Item: id="iris2_item" label="Iris 2" state="121,88,68" topic="iris1_item/s
Group: id="Unknown" items=["iris1_item", "iris2_item"] ;
Rule: name="testRule2" items=["iris1_item"] [Condition: ItemStateCheck < 6.0] ;
Rule: name="eqfff" items=["iris1_item"] [Condition: ItemStateCheck < "Yeah" ] ;
Rule: name="testRule1" items=["iris1_item"] [Condition: ItemStateCheck < 4.0, Action: TriggerRuleAction testRule2] ;
Rule: name="testRule1" items=["iris1_item"] [Condition: ItemStateCheck < 4.0, Action: TriggerRule testRule2] ;
Rule: name="testRule416" items=["iris1_item"] [Condition: ItemStateChange iris1_item] ;
Rule: name="testRule456" items=["iris1_item"] [Action: NoopAction] ;
Rule: name="testRule456" items=["iris1_item"] [Action: Noop] ;
Rule: name="testRule46" items=["iris1_item"] [Action: SetStateFromConstant iris1_item "K"] ;
Rule: name="testRule8" items=["iris1_item"] [Action: SetStateFromTrigger iris2_item] ;
Rule: name="testRul118" items=["iris1_item"] [Action: SetStateFromTrigger iris2_item 2.0] ;
......@@ -4,8 +4,8 @@ Group: id="Unknown" items=["iris1_item", "iris2_item"] ;
Rule: name="testRul118" items=["iris1_item"] [Action: SetStateFromTrigger iris2_item 2.0] ;
Rule: name="testRule8" items=["iris1_item"] [Action: SetStateFromTrigger iris2_item] ;
Rule: name="testRule46" items=["iris1_item"] [Action: SetStateFromConstant iris1_item "K"] ;
Rule: name="testRule456" items=["iris1_item"] [Action: NoopAction] ;
Rule: name="testRule456" items=["iris1_item"] [Action: Noop] ;
Rule: name="testRule416" items=["iris1_item"] [Condition: ItemStateChange iris1_item] ;
Rule: name="testRule1" items=["iris1_item"] [Condition: ItemStateCheck < 4.0, Action: TriggerRuleAction testRule2] ;
Rule: name="testRule1" items=["iris1_item"] [Condition: ItemStateCheck < 4.0, Action: TriggerRule testRule2] ;
Rule: name="eqfff" items=["iris1_item"] [Condition: ItemStateCheck < "Yeah"] ;
Rule: name="testRule2" items=["iris1_item"] [Condition: ItemStateCheck < 6.0] ;
......@@ -116,13 +116,20 @@ Rule: name="" items=["ITEM_ID", "ITEM_ID"] [Condition: CONDITION_CONSTRUCTOR, Co
| Name | Description | Structure | Example |
| ---------------------- |--------------------------------------------------| ------------------------------------| -------------------------|
| ItemStateNumberCheck | compares the state with VALUE using the OPERATOR | ItemStateNumberCheck OPERATOR VALUE | ItemStateNumberCheck < 5 |
| ItemStateNumberCheck | compares the state with NUMBER using the OPERATOR | ItemStateCheck OPERATOR NUMBER | ItemStateCheck < 5 |
| ItemStateTextCheck | compares the state with TEXT using the OPERATOR | ItemStateCheck OPERATOR TEXT | ItemStateCheck < "abc" |
| ItemStateChange | triggers if specified ITEM changed its value | ItemStateChange ITEM ItemStateChange | ItemStateChange item1 |
#### Actions
| Name | Description | Structure | Example |
| -------------------- |----------------------------------------------------------------------------------------------| -------------------------------| ------------------------------|
| TriggerRuleAction | triggers the rule with with specified RULE_NAME (conditions of RULE are still being checked) | ItemStateNumberCheck RULE_NAME | ItemStateNumberCheck testRule |
| TriggerRuleAction | triggers the rule with with specified RULE_NAME (conditions of RULE are still being checked) | TriggerRuleAction RULE_NAME | TriggerRuleAction testRule |
| NoopAction | no operation (just for testing) | NoopAction | NoopAction |
| SetStateFromConstantStringAction | apply specified VALUE to the ITEM | SetStateFromConstant ITEM VALUE | SetStateFromConstant item1 "LMNOP" |
| SetStateFromTriggeringItemAction | copies state from triggering device to specified ITEM | SetStateFromTrigger ITEM | SetStateFromTrigger item1 |
| MultiplyDoubleToStateAction | copies state multiplied by MULTIPLIER from triggering item to specified ITEM | SetStateFromTrigger ITEM MULTIPLIER | SetStateFromTrigger item1 2.0 |
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment