I am looking for a way to read a value from an existing variable in a DSL rule, where the name of the variable to read is generated dynamically by the rule. I have found plenty of discussions talking about dynamically generated item names, but could not find something comparable for variables.
So basically what I have is the following:
I have a number of items in an .items file which I want to act as constants for my system. Eg to determine default temperatures for heating / warm water:
Number WarmwasserTempNormal "Warmwasser Temperatur normal" (persistenceMap) Number WarmwasserTempAbgesenkt "Warmwasser Temperatur abgesenkt" (persistenceMap)
Secondly I have a corresponding .rules file, in which I set the default values for those items. The idea is that on
System started the default values are set for the above items. For better clarity and editability of the .rules file I first want to have a block with val declarations at the top of the file, eg
val Number WarmwasserTempNormal = 42 val Number WarmwasserTempAbgesenkt = 35
(not sure at this stage whether having the same names for the items and the variables is a good idea or even doable, but that is not really the topic here and can easily be fixed by adding pre- or suffixes to the variable names)
And then second, further down in the actual rule, I want to do something like
WarmwasserTempNormal.postUpdate(WarmwasserTempNormal), ie post the value of the variable to the item.
So far so good, that should all work.
But as I am looking to have perhaps a dozen or more items to be set this way, I would not want to write a dozen times two lines for each item in the rules file, ie first the variable declaration and then second the postUpdate for that item. Instead, I was thinking to create a group for all these items, and then to use
MyGroup.members.forEach[ i | <code> ] to cycle through each group item.
But what do I put for
<code>? While every variable name can be deduced from the item name, something like
i.postUpdate(i.name) will obviously not work here, as that will send the name string to the item, not the value of the variable of the same name.
Is there a function that will return a variable value from indirect reference? Eg something like
readVar(i.name). Or some sort of equivalent to the
var Number myValue = eval(i.name) i.postUpdate(myValue)
Any help would be greatly appreciated.