I created a simple system to enable and disable automatic mode for several things, for example the room temperature. Therefor there are several items in a hierarchical structure:
Switch Automode "Automatik" (All, LogRRDRestore)
Switch AutomodeHeatingmode "Automatik Heizung" (All, LogRRDRestore)
Switch AutomodeHeatingmodeBad "Automatik Heizung Bad" (All, LogRRDRestore)
Switch AutomodeHeatingmodeBesprechung "Automatik Heizung Besprechung" (All, LogRRDRestore)
Switch AutomodeHeatingmodeBuero "Automatik Heizung Büro" (All, LogRRDRestore)
//...
In a rule I do:
//...
if(checkAutomode.apply(AutomodeHeatingmodeBuero)) {
// do something
}
//...
The function is:
val org.eclipse.xtext.xbase.lib.Functions$Function1 checkAutomode = [
SwitchItem item |
var isInAutomode = true
var parts = item.name.split("(?=\\p{Upper})")
logInfo("checkAutomode", "{}: {}", item.name, parts.length)
for(var i=0; i<parts.length; i++) {
// generate current item name
var currentItemName = ""
for(var j=0; j<=i; j++){
currentItemName += parts.get(j)
}
var currentItem = All.members.findFirst[name.equals(currentItemName)]
logInfo("checkAutomode", "{}: {}", item.name, currentItem)
if(currentItem.state != ON) {
isInAutomode = false
}
}
logInfo("checkAutomode", "{} result: {}", item.name, isInAutomode)
isInAutomode
]
What the function should do really simple: It cuts the name on the uppercase letters and checks every item if it is false.
In some cases the function execution is broken. In my opinion it has something to do if the function is executed in parallel. This is the log:
2017-05-14 23:00:00.059 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBesprechung: 3
2017-05-14 23:00:00.062 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeSchlafzimmer: 3
2017-05-14 23:00:00.084 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBad: 3
2017-05-14 23:00:00.098 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeWohnzimmer: 3
2017-05-14 23:00:00.110 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBad result: true
2017-05-14 23:00:00.112 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeSchlafzimmer: Automode (Type=SwitchItem, State=ON, Label=Automatik, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.115 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeKueche: 3
2017-05-14 23:00:00.124 [INFO ] [marthome.model.script.temperatur Bad] - targetTemperature: 17.0
2017-05-14 23:00:00.146 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBesprechung: Automode (Type=SwitchItem, State=ON, Label=Automatik, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.153 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBuero: 3
2017-05-14 23:00:00.180 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeWohnzimmer: Automode (Type=SwitchItem, State=ON, Label=Automatik, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.196 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeKueche: Automode (Type=SwitchItem, State=ON, Label=Automatik, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.199 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeSchlafzimmer: AutomodeHeatingmode (Type=SwitchItem, State=OFF, Label=Automatik Heizung, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.199 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBuero: Automode (Type=SwitchItem, State=ON, Label=Automatik, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.213 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBesprechung: AutomodeHeatingmode (Type=SwitchItem, State=OFF, Label=Automatik Heizung, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.257 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeWohnzimmer: AutomodeHeatingmode (Type=SwitchItem, State=OFF, Label=Automatik Heizung, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.288 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeSchlafzimmer result: false
2017-05-14 23:00:00.300 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeKueche: AutomodeHeatingmode (Type=SwitchItem, State=OFF, Label=Automatik Heizung, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.303 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBuero: AutomodeHeatingmode (Type=SwitchItem, State=OFF, Label=Automatik Heizung, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.315 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBesprechung: AutomodeHeatingmodeBesprechung (Type=SwitchItem, State=OFF, Label=Automatik Heizung Besprechung, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.325 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBesprechung result: false
2017-05-14 23:00:00.353 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeWohnzimmer: AutomodeHeatingmodeWohnzimmer (Type=SwitchItem, State=OFF, Label=Automatik Heizung Wohnzimmer, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.369 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeWohnzimmer result: false
2017-05-14 23:00:00.379 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBuero: AutomodeHeatingmodeBuero (Type=SwitchItem, State=OFF, Label=Automatik Heizung Büro, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.390 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeBuero result: false
2017-05-14 23:00:00.393 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeKueche: AutomodeHeatingmodeKueche (Type=SwitchItem, State=OFF, Label=Automatik Heizung Küche, Category=null, Groups=[All, LogRRDRestore])
2017-05-14 23:00:00.407 [INFO ] [smarthome.model.script.checkAutomode] - AutomodeHeatingmodeKueche result: false
In this case the function is called several times in parallel for different rooms and for AutomodeHeatingmodeBad the execution jumps over the for loop although the logInfo the line before says the length of parts is 3.
Any suggestions?