I’m moving my DSL rules into openHAB3 and I’d like to also move to EMCAscript while I’m at it.
first of all: there’s no GUI way to add map Transformations in openHAB3 yet, correct? You must copy the files to /etc/openhab/transform?
so, the main question: how can I migrate that DSL line to Javascript - and what do I need to import for that?
var String name = transform("MAP","mynames.map",Userid.state.toString())
You can do it without rule if it’s just an item you want to transform:
Just go to Things -> Channel -> Select Item. At the bottom you can choose a profile, select MAP and type the file name: mynames.map (this file is inside your /etc/openhab/transform)
It is possible to create your own solution and possibly adapt it to your needs:
this.maptransform = function(filename, parameter)
{
var TypeMap = Java.type("java.util.HashMap");
var TypeReader = Java.type("java.io.BufferedReader");
var TypeFile = Java.type("java.io.FileReader");
var file = new TypeFile(Java.type("java.lang.System").getenv("OPENHAB_CONF") + "/transform/" + filename);
var reader = new TypeReader(file);
var map = new TypeMap();
var line = new String();
var delimiter = "=";
while ((line = reader.readLine()) != null)
{
if (line.trim().length()==0) continue;
if (line.charAt(0)=='#') continue;
var delimPosition = line.indexOf(delimiter);
var key = line.substring(0, delimPosition).trim();
var value = line.substring(delimPosition+1).trim();
map.put(key, value);
}
reader.close();
return map.get(parameter);
}
and calling: var mapping = maptransform("config.map", "email");
I’m migration all my rules from DSL to JS and wondering that a function like this isn’t available out of the box. @rlkoshak Rich, Can you give perhaps some background information?