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

Fixed tests for ControllingItem

parent 6fb323d4
No related branches found
No related tags found
2 merge requests!19dev to master,!8Partly resolves "Implement state copy in AST"
Pipeline #8751 failed
aspect ItemHandling { aspect ItemHandling {
protected boolean Item.isFrozen = false;
public void Item.freeze() { isFrozen = true; }
public void Item.unfreeze() { isFrozen = false; }
public final boolean Item.isFrozen() { return isFrozen; }
protected boolean Item.sendState = true; protected boolean Item.sendState = true;
public void Item.disableSendState() { sendState = false; } public void Item.disableSendState() { sendState = false; }
public void Item.enableSendState() { sendState = true; } public void Item.enableSendState() { sendState = true; }
...@@ -254,31 +249,31 @@ aspect ItemHandling { ...@@ -254,31 +249,31 @@ aspect ItemHandling {
//--- setState(value,shouldSendState) --- //--- setState(value,shouldSendState) ---
public void ItemWithBooleanState.setState(boolean value, boolean shouldSendState) { public void ItemWithBooleanState.setState(boolean value, boolean shouldSendState) {
if (isFrozen || stateEquals(value)) { return; } if (stateEquals(value)) { return; }
set_state(value); set_state(value);
stateUpdated(shouldSendState); stateUpdated(shouldSendState);
} }
public void ItemWithStringState.setState(String value, boolean shouldSendState) { public void ItemWithStringState.setState(String value, boolean shouldSendState) {
if (isFrozen || stateEquals(value)) { return; } if (stateEquals(value)) { return; }
set_state(value); set_state(value);
stateUpdated(shouldSendState); stateUpdated(shouldSendState);
} }
public void ItemWithDoubleState.setState(double value, boolean shouldSendState) { public void ItemWithDoubleState.setState(double value, boolean shouldSendState) {
if (isFrozen || stateEquals(value)) { return; } if (stateEquals(value)) { return; }
set_state(value); set_state(value);
stateUpdated(shouldSendState); stateUpdated(shouldSendState);
} }
public void ColorItem.setState(TupleHSB value, boolean shouldSendState) { public void ColorItem.setState(TupleHSB value, boolean shouldSendState) {
if (isFrozen || stateEquals(value)) { return; } if (stateEquals(value)) { return; }
set_state(value); set_state(value);
stateUpdated(shouldSendState); stateUpdated(shouldSendState);
} }
public void DateTimeItem.setState(Instant value, boolean shouldSendState) { public void DateTimeItem.setState(Instant value, boolean shouldSendState) {
if (isFrozen || stateEquals(value)) { return; } if (stateEquals(value)) { return; }
set_state(value); set_state(value);
stateUpdated(shouldSendState); stateUpdated(shouldSendState);
} }
...@@ -405,6 +400,7 @@ aspect ItemHandling { ...@@ -405,6 +400,7 @@ aspect ItemHandling {
SetStateFromTriggeringItemAction action = new SetStateFromTriggeringItemAction(); SetStateFromTriggeringItemAction action = new SetStateFromTriggeringItemAction();
action.setAffectedItem(controlledItem); action.setAffectedItem(controlledItem);
rule.addAction(action); rule.addAction(action);
rule.activateFor(controllerItem);
return rule; return rule;
...@@ -437,14 +433,10 @@ aspect ItemHandling { ...@@ -437,14 +433,10 @@ aspect ItemHandling {
public abstract void ItemUpdate.apply(); public abstract void ItemUpdate.apply();
public void ItemUpdateColor.apply() { public void ItemUpdateColor.apply() {
getItem().setStateFromColor(getNewHSB()); getItem().setStateFromColor(getNewHSB());
getItem().freeze();
getItem().unfreeze();
} }
//--- ItemUpdate.apply --- //--- ItemUpdate.apply ---
public void ItemUpdateDouble.apply() { public void ItemUpdateDouble.apply() {
getItem().setStateFromDouble(getNewValue()); getItem().setStateFromDouble(getNewValue());
getItem().freeze();
getItem().unfreeze();
} }
//--- ItemUpdate.describe --- //--- ItemUpdate.describe ---
......
...@@ -125,4 +125,21 @@ public class ControllingItemTest { ...@@ -125,4 +125,21 @@ public class ControllingItemTest {
item.enableSendState(); item.enableSendState();
return item; return item;
} }
@Test
public void testCircularControlling() {
ModelAndItem mai = TestUtils.createModelAndItem(0, true);
NumberItem item1 = mai.item;
NumberItem item2 = TestUtils.addItemTo(mai.model, 4, true);
item1.addControlling(item2);
item2.addControlling(item1);
assertEquals(0, item1.getState(), DELTA);
assertEquals(4, item2.getState(), DELTA);
item1.setState(5);
assertEquals(5, item1.getState(), DELTA);
assertEquals(5, item2.getState(), DELTA, "Item was not controlled correctly");
}
} }
...@@ -9,14 +9,14 @@ Group: id="my-empty-group" ; ...@@ -9,14 +9,14 @@ Group: id="my-empty-group" ;
Color Item : id="color1" label="a Color Item" state="1,2,3" topic="item/hsb/color1/state"; Color Item : id="color1" label="a Color Item" state="1,2,3" topic="item/hsb/color1/state";
DateTime Item : id="datetime1" label="a DateTime Item" state="1543415826" topic="item/date/datetime1/state"; DateTime Item : id="datetime1" label="a DateTime Item" state="1543415826" topic="item/date/datetime1/state";
Contact Item : id="contact1" label="a Contact Item" state="CLOSED" topic="item/bool/contact1/state"; Contact Item : id="contact1" label="a Contact Item" state="CLOSED" topic="item/bool/contact1/state";
Dimmer Item : id="dimmer1" label="a Dimmer Item" state="123" topic="item/double/dimmer1/state" controls=["color1", "datetime1"]; Dimmer Item : id="dimmer1" label="a Dimmer Item" state="123" topic="item/double/dimmer1/state";
Image Item : id="image1" label="an Image Item" state="def" topic="item/str/image1/state" controls=[]; Image Item : id="image1" label="an Image Item" state="def" topic="item/str/image1/state" ;
Location Item : id="location1" label="a Location Item" state="ghi" topic="item/str/location1/state"; Location Item : id="location1" label="a Location Item" state="ghi" topic="item/str/location1/state";
Number Item : id="number1" label="a Number Item" state="456" topic="item/double/number1/state" controls=["string1"]; Number Item : id="number1" label="a Number Item" state="456" topic="item/double/number1/state" ;
Player Item : id="player1" label="a Player Item" state="jkl" topic="item/str/player1/state"; Player Item : id="player1" label="a Player Item" state="jkl" topic="item/str/player1/state";
RollerShutter Item : id="rollerShutter1" label="a RollerShutter Item" state="0" topic="item/str/rs1/state"; RollerShutter Item : id="rollerShutter1" label="a RollerShutter Item" state="0" topic="item/str/rs1/state";
Activity Item: id="activity"; Activity Item: id="activity";
String Item : id="string1" label="a String Item" state="mno" topic="item/str/string1/state"; String Item : id="string1" label="a String Item" state="mno" topic="item/str/string1/state";
Switch Item : id="switch1" label="a Switch Item" state="true" topic="item/bool/switch1/state" controls=["rollerShutter1"]; Switch Item : id="switch1" label="a Switch Item" state="true" topic="item/bool/switch1/state";
Item : id="default1" label="a Default Item" state="pqr" topic="item/str/default1/state"; Item : id="default1" label="a Default Item" state="pqr" topic="item/str/default1/state";
Influx: host="localhost" ; Influx: host="localhost" ;
...@@ -4,13 +4,13 @@ Image Item: id="image1" label="an Image Item" state="def" topic="item/str/image1 ...@@ -4,13 +4,13 @@ Image Item: id="image1" label="an Image Item" state="def" topic="item/str/image1
Location Item: id="location1" label="a Location Item" state="ghi" topic="item/str/location1/state" ; Location Item: id="location1" label="a Location Item" state="ghi" topic="item/str/location1/state" ;
DateTime Item: id="datetime1" label="a DateTime Item" state="1970-01-18T20:43:35.826Z" topic="item/date/datetime1/state" ; DateTime Item: id="datetime1" label="a DateTime Item" state="1970-01-18T20:43:35.826Z" topic="item/date/datetime1/state" ;
Item: id="default1" label="a Default Item" state="pqr" topic="item/str/default1/state" ; Item: id="default1" label="a Default Item" state="pqr" topic="item/str/default1/state" ;
Dimmer Item: id="dimmer1" label="a Dimmer Item" state="123.0" topic="item/double/dimmer1/state" controls=["color1", "datetime1"] ; Dimmer Item: id="dimmer1" label="a Dimmer Item" state="123.0" topic="item/double/dimmer1/state" ;
Player Item: id="player1" label="a Player Item" state="jkl" topic="item/str/player1/state" ; Player Item: id="player1" label="a Player Item" state="jkl" topic="item/str/player1/state" ;
Number Item: id="number1" label="a Number Item" state="456.0" topic="item/double/number1/state" controls=["string1"] ; Number Item: id="number1" label="a Number Item" state="456.0" topic="item/double/number1/state" ;
RollerShutter Item: id="rollerShutter1" label="a RollerShutter Item" state="0.0" topic="item/str/rs1/state" ; RollerShutter Item: id="rollerShutter1" label="a RollerShutter Item" state="0.0" topic="item/str/rs1/state" ;
Activity Item: id="activity" ; Activity Item: id="activity" ;
String Item: id="string1" label="a String Item" state="mno" topic="item/str/string1/state" ; String Item: id="string1" label="a String Item" state="mno" topic="item/str/string1/state" ;
Switch Item: id="switch1" label="a Switch Item" state="ON" topic="item/bool/switch1/state" controls=["rollerShutter1"] ; Switch Item: id="switch1" label="a Switch Item" state="ON" topic="item/bool/switch1/state" ;
Group: id="my-first-group" items=["color1", "contact1", "image1", "location1"] aggregation="AND" ("ON", "OFF") ; Group: id="my-first-group" items=["color1", "contact1", "image1", "location1"] aggregation="AND" ("ON", "OFF") ;
Group: id="my-second-group" items=["datetime1", "default1"] ; Group: id="my-second-group" items=["datetime1", "default1"] ;
Group: id="my-third-group" items=["dimmer1", "player1"] ; Group: id="my-third-group" items=["dimmer1", "player1"] ;
......
...@@ -11,7 +11,7 @@ Group: items=["min-item", "max-item"] id="max-group" groups=["min-group"] aggreg ...@@ -11,7 +11,7 @@ Group: items=["min-item", "max-item"] id="max-group" groups=["min-group"] aggreg
Number Item: id="min-item" ; // state will be set to default value Number Item: id="min-item" ; // state will be set to default value
Switch Item: topic="items/max" Switch Item: topic="items/max"
controls=["min-item"] id="max-item" state="true" label="Item with all members set" category="not used" id="max-item" state="true" label="Item with all members set" category="not used"
metaData={"one":"true", "zero":"false"} ; metaData={"one":"true", "zero":"false"} ;
// Parameters will get sorted alphabetically in output // Parameters will get sorted alphabetically in output
......
Thing: id="min-thing" type="min-thing-type" ; Thing: id="min-thing" type="min-thing-type" ;
Thing: id="max-thing" label="Max Thing" type="max-thing-type" channels=["min-channel", "max-channel"] ; Thing: id="max-thing" label="Max Thing" type="max-thing-type" channels=["min-channel", "max-channel"] ;
Number Item: id="min-item" state="0.0" ; Number Item: id="min-item" state="0.0" ;
Switch Item: id="max-item" label="Item with all members set" state="ON" category="not used" topic="items/max" controls=["min-item"] metaData={"one":"true", "zero":"false"} ; Switch Item: id="max-item" label="Item with all members set" state="ON" category="not used" topic="items/max" metaData={"one":"true", "zero":"false"} ;
Group: id="min-group" ; Group: id="min-group" ;
Group: id="max-group" groups=["min-group"] items=["min-item", "max-item"] aggregation="AND" ("one", "two") ; Group: id="max-group" groups=["min-group"] items=["min-item", "max-item"] aggregation="AND" ("one", "two") ;
ThingType: id="min-thing-type" ; ThingType: id="min-thing-type" ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment