Skip to content
Snippets Groups Projects
Commit 6fb323d4 authored by dev-manuel's avatar dev-manuel
Browse files

Replaced ControllerItem and ControlledItem w/ ECA

parent 9ad7f6d1
Branches
No related tags found
2 merge requests!19dev to master,!8Partly resolves "Implement state copy in AST"
Pipeline #8688 failed
...@@ -290,7 +290,6 @@ aspect ItemHandling { ...@@ -290,7 +290,6 @@ aspect ItemHandling {
* <li>Send the new state via MQTT</li> * <li>Send the new state via MQTT</li>
* <li>Send the new state to Influx DB</li> * <li>Send the new state to Influx DB</li>
* <li>Notify the attached {@link ItemObserver}, if any</li> * <li>Notify the attached {@link ItemObserver}, if any</li>
* <li>Update state of controlled items</li>
* </ul> * </ul>
* @param shouldSendState whether to send the new state (currently affects MQTT and Influx) * @param shouldSendState whether to send the new state (currently affects MQTT and Influx)
*/ */
...@@ -306,9 +305,6 @@ aspect ItemHandling { ...@@ -306,9 +305,6 @@ aspect ItemHandling {
if (hasItemObserver()) { if (hasItemObserver()) {
getItemObserver().apply(); getItemObserver().apply();
} }
for (Item controlled : getControllingList()) {
doUpdateFor(controlled);
}
} }
//--- sendState --- //--- sendState ---
...@@ -388,22 +384,49 @@ aspect ItemHandling { ...@@ -388,22 +384,49 @@ aspect ItemHandling {
syn DateTimeItem Item.asDateTimeItem() = (DateTimeItem) this; syn DateTimeItem Item.asDateTimeItem() = (DateTimeItem) this;
syn DateTimeItem DateTimeItem.asDateTimeItem() = this; syn DateTimeItem DateTimeItem.asDateTimeItem() = this;
//--- doUpdateFor ---
protected abstract void Item.doUpdateFor(Item controlling); //--- State Copy ---
protected void ItemWithBooleanState.doUpdateFor(Item controlling) { public void Item.addControlling(Item controlledItem) {
controlling.setStateFromBoolean(this.getState()); getRoot().addRule(createControllerRule(this,controlledItem));
}
public void Item.addControlledBy(Item controllerItem) {
getRoot().addRule(createControllerRule(controllerItem,this));
}
private Rule Item.createControllerRule(Item controllerItem, Item controlledItem) {
Rule rule = new Rule();
ItemStateChangeCondition condition = new ItemStateChangeCondition();
condition.setItem(controllerItem);
rule.addCondition(condition);
SetStateFromTriggeringItemAction action = new SetStateFromTriggeringItemAction();
action.setAffectedItem(controlledItem);
rule.addAction(action);
return rule;
}
//--- copyStateTo ---
protected abstract void Item.copyStateTo(Item stateReceiver);
protected void ItemWithBooleanState.copyStateTo(Item stateReceiver) {
stateReceiver.setStateFromBoolean(this.getState());
} }
protected void ItemWithStringState.doUpdateFor(Item controlling) { protected void ItemWithStringState.copyStateTo(Item stateReceiver) {
controlling.setStateFromString(this.getState()); stateReceiver.setStateFromString(this.getState());
} }
protected void ItemWithDoubleState.doUpdateFor(Item controlling) { protected void ItemWithDoubleState.copyStateTo(Item stateReceiver) {
controlling.setStateFromDouble(this.getState()); stateReceiver.setStateFromDouble(this.getState());
} }
protected void ColorItem.doUpdateFor(Item controlling) { protected void ColorItem.copyStateTo(Item stateReceiver) {
controlling.setStateFromColor(this.getState()); stateReceiver.setStateFromColor(this.getState());
} }
protected void DateTimeItem.doUpdateFor(Item controlling) { protected void DateTimeItem.copyStateTo(Item stateReceiver) {
controlling.setStateFromInstant(this.getState()); stateReceiver.setStateFromInstant(this.getState());
} }
private void ColorItem.setBrightness(int value) { private void ColorItem.setBrightness(int value) {
...@@ -415,18 +438,12 @@ aspect ItemHandling { ...@@ -415,18 +438,12 @@ aspect ItemHandling {
public void ItemUpdateColor.apply() { public void ItemUpdateColor.apply() {
getItem().setStateFromColor(getNewHSB()); getItem().setStateFromColor(getNewHSB());
getItem().freeze(); getItem().freeze();
for (Item controller : getItem().getControlledByList()) {
controller.setStateFromColor(getNewHSB());
}
getItem().unfreeze(); getItem().unfreeze();
} }
//--- ItemUpdate.apply --- //--- ItemUpdate.apply ---
public void ItemUpdateDouble.apply() { public void ItemUpdateDouble.apply() {
getItem().setStateFromDouble(getNewValue()); getItem().setStateFromDouble(getNewValue());
getItem().freeze(); getItem().freeze();
for (Item controller : getItem().getControlledByList()) {
controller.setStateFromDouble(getNewValue());
}
getItem().unfreeze(); getItem().unfreeze();
} }
......
...@@ -49,7 +49,7 @@ aspect Printing { ...@@ -49,7 +49,7 @@ aspect Printing {
.build(); .build();
} }
//ITEM_TYPE Item: id="" label="" state="" category="" topic="" controls=["ITEM_ID", "ITEM_ID"]; //ITEM_TYPE Item: id="" label="" state="" category="" topic="";
syn String Item.prettyPrint() { syn String Item.prettyPrint() {
return new MemberPrinter(prettyPrintType()) return new MemberPrinter(prettyPrintType())
.addRequired("id", getID()) .addRequired("id", getID())
...@@ -57,7 +57,6 @@ aspect Printing { ...@@ -57,7 +57,6 @@ aspect Printing {
.addRequired("state", getStateAsString()) .addRequired("state", getStateAsString())
.addOptional("category", hasCategory(), () -> getCategory().getName()) .addOptional("category", hasCategory(), () -> getCategory().getName())
.addOptional("topic", hasTopic(), () -> getTopic().getTopicString()) .addOptional("topic", hasTopic(), () -> getTopic().getTopicString())
.addIds("controls", getControllingList())
.addNodes("metaData", getNumMetaData(), getMetaDataList(), .addNodes("metaData", getNumMetaData(), getMetaDataList(),
md -> "\"" + md.getKey() + "\":\"" + md.getValue() + "\"", md -> "\"" + md.getKey() + "\":\"" + md.getValue() + "\"",
MemberPrinter.ListBracketType.CURLY) MemberPrinter.ListBracketType.CURLY)
...@@ -86,7 +85,6 @@ aspect Printing { ...@@ -86,7 +85,6 @@ aspect Printing {
.addNonDefault("label", getLabel()) .addNonDefault("label", getLabel())
.addOptional("category", hasCategory(), () -> getCategory().getName()) .addOptional("category", hasCategory(), () -> getCategory().getName())
.addOptional("topic", hasTopic(), () -> getTopic().getTopicString()) .addOptional("topic", hasTopic(), () -> getTopic().getTopicString())
.addIds("controls", getControllingList())
.addNodes("metaData", getNumMetaData(), getMetaDataList(), .addNodes("metaData", getNumMetaData(), getMetaDataList(),
md -> "\"" + md.getKey() + "\":\"" + md.getValue() + "\"", md -> "\"" + md.getKey() + "\":\"" + md.getValue() + "\"",
MemberPrinter.ListBracketType.CURLY) MemberPrinter.ListBracketType.CURLY)
......
...@@ -79,6 +79,7 @@ aspect Rules { ...@@ -79,6 +79,7 @@ aspect Rules {
syn boolean Condition.holdsFor(Item item); syn boolean Condition.holdsFor(Item item);
eq ItemStateCheckCondition.holdsFor(Item item) = getItemStateCheck().holdsFor(item); eq ItemStateCheckCondition.holdsFor(Item item) = getItemStateCheck().holdsFor(item);
eq ExpressionCondition.holdsFor(Item item) = getLogicalExpression().eval(); eq ExpressionCondition.holdsFor(Item item) = getLogicalExpression().eval();
eq ItemStateChangeCondition.holdsFor(Item item) = getItem() == item;
// --- Action.applyFor --- // --- Action.applyFor ---
public abstract void Action.applyFor(Item item); public abstract void Action.applyFor(Item item);
...@@ -101,7 +102,7 @@ aspect Rules { ...@@ -101,7 +102,7 @@ aspect Rules {
getAffectedItem().setStateFromString(getNewStateProvider().get()); getAffectedItem().setStateFromString(getNewStateProvider().get());
} }
public void SetStateFromTriggeringItemAction.applyFor(Item item) { public void SetStateFromTriggeringItemAction.applyFor(Item item) {
item.doUpdateFor(getAffectedItem()); item.copyStateTo(getAffectedItem());
} }
public void SetStateFromItemsAction.applyFor(Item item) { public void SetStateFromItemsAction.applyFor(Item item) {
getAffectedItem().setStateFromString(getCombinator().apply(getSourceItems())); getAffectedItem().setStateFromString(getCombinator().apply(getSourceItems()));
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Rule ::= Condition* Action* ; Rule ::= Condition* Action* ;
abstract Condition ; abstract Condition ;
ItemStateCheckCondition : Condition ::= ItemStateCheck ; ItemStateCheckCondition : Condition ::= ItemStateCheck ;
ItemStateChangeCondition : Condition ::= Item;
ExpressionCondition : Condition ::= LogicalExpression ; ExpressionCondition : Condition ::= LogicalExpression ;
abstract Action ; abstract Action ;
NoopAction : Action ; NoopAction : Action ;
......
...@@ -77,7 +77,6 @@ Comment = "//" [^\n\r]+ ...@@ -77,7 +77,6 @@ Comment = "//" [^\n\r]+
"channels" { return sym(Terminals.CHANNELS); } "channels" { return sym(Terminals.CHANNELS); }
"channelTypes" { return sym(Terminals.CHANNEL_TYPES); } "channelTypes" { return sym(Terminals.CHANNEL_TYPES); }
"context" { return sym(Terminals.CONTEXT); } "context" { return sym(Terminals.CONTEXT); }
"controls" { return sym(Terminals.CONTROLS); }
"dbName" { return sym(Terminals.DB_NAME); } "dbName" { return sym(Terminals.DB_NAME); }
"default" { return sym(Terminals.DEFAULT); } "default" { return sym(Terminals.DEFAULT); }
"description" { return sym(Terminals.DESCRIPTION); } "description" { return sym(Terminals.DESCRIPTION); }
......
...@@ -125,15 +125,13 @@ Item item = ...@@ -125,15 +125,13 @@ Item item =
| ITEM COLON item_body.ib SEMICOLON {: return eph.retype(new DefaultItem(), ib); :} | ITEM COLON item_body.ib SEMICOLON {: return eph.retype(new DefaultItem(), ib); :}
; ;
// ITEM_TYPE Item: id="" label="" state="" category="" topic="" controls=["ITEM_ID"] metaData={"key":"value"} ; // ITEM_TYPE Item: id="" label="" state="" category="" topic="" metaData={"key":"value"} ;
Item item_body = Item item_body =
ID EQUALS TEXT.n item_body.i {: return eph.setID(i, n); :} ID EQUALS TEXT.n item_body.i {: return eph.setID(i, n); :}
| LABEL EQUALS TEXT.n item_body.i {: i.setLabel(n); return i; :} | LABEL EQUALS TEXT.n item_body.i {: i.setLabel(n); return i; :}
| STATE EQUALS TEXT.n item_body.i {: i.setStateFromString(n); return i; :} | STATE EQUALS TEXT.n item_body.i {: i.setStateFromString(n); return i; :}
| TOPIC EQUALS TEXT.n item_body.i {: return eph.setTopic(i, n); :} | TOPIC EQUALS TEXT.n item_body.i {: return eph.setTopic(i, n); :}
| CATEGORY EQUALS TEXT.n item_body.i {: return eph.setCategory(i, n); :} | CATEGORY EQUALS TEXT.n item_body.i {: return eph.setCategory(i, n); :}
| CONTROLS EQUALS string_list.controlling item_body.i
{: return eph.setControlling(i, controlling); :}
| META_DATA EQUALS string_map.md item_body.i | META_DATA EQUALS string_map.md item_body.i
{: return eph.setMetaData(i, md); :} {: return eph.setMetaData(i, md); :}
| {: return eph.createItem(); :} | {: return eph.createItem(); :}
......
...@@ -27,7 +27,6 @@ ParameterDefaultValue ::= <Value:String> ; ...@@ -27,7 +27,6 @@ ParameterDefaultValue ::= <Value:String> ;
abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] ; abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] ;
rel Item.Category? -> ItemCategory ; rel Item.Category? -> ItemCategory ;
rel Item.Controlling* <-> Item.ControlledBy* ;
abstract ItemWithBooleanState : Item ::= <_state:boolean> ; abstract ItemWithBooleanState : Item ::= <_state:boolean> ;
abstract ItemWithStringState : Item ::= <_state:String> ; abstract ItemWithStringState : Item ::= <_state:String> ;
......
...@@ -243,7 +243,6 @@ public class Application { ...@@ -243,7 +243,6 @@ public class Application {
item.getTopic() != null ? item.getTopic().getTopicString() : null, item.getTopic() != null ? item.getTopic().getTopicString() : null,
item.isFrozen(), item.isFrozen(),
item.isSendState(), item.isSendState(),
item.getControllingList().stream().map(Item::getID).collect(Collectors.toList()),
wrapMetaData(item.getMetaDataList())); wrapMetaData(item.getMetaDataList()));
} }
......
...@@ -17,6 +17,5 @@ public class SimpleItem { ...@@ -17,6 +17,5 @@ public class SimpleItem {
public final String topic; public final String topic;
public final boolean frozen; public final boolean frozen;
public final boolean sendState; public final boolean sendState;
public final List<String> controlling;
public final Map<String, String> metaData; public final Map<String, String> metaData;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment