padStart & padEnd support in Rules

  • Hardware: _Raspberry Pi3
  • OS: OpenHabian 1.41

Hi,

Is there a way to use padStart & padEnd in Rules?
I have this error in Frontail:
‘padStart’ is not a member of ‘java.lang.String’;
Should I add an import in the beginning of the rules file?

Thanks

1 Like

As far as i know padStart is Java Script and openHAB rules are not Javascript. The DSl ist based on xtend and Java

If you explain what padStart and padEnd does (I’m not a JS expert) there might be a way to do the equivalent in Rules.

Thanks for your reply.

I have nothing too hard to do.
I just have a thing that send me « hexadecimal word » in string type.
If it send me the word ‘4F’ it’s ok but if it send me the word ‘D’, it’s not ok.
I want to transform it to ‘0D’
I know it’s not difficult but padStart can do that in no time.

By the way, the rule language is not very clear for me. Not exactly Java, not exactly JS, not exactly nothing!
I progress by try and error but it is very obscur compared to php that I know very well.

Anyway, thank for your help

String.format("%2s", hexStr).replace(' ', '0');

From the docs

Note: The rule syntax is based on Xbase and as a result it is sharing many details with Xtend, which is built on top of Xbase as well. As a result, we will often point to the Xtend documentation for details.

It is a Rule that runs on the Java Virtual Machine so it has access to all the standard Java Library stuff but it is it’s own language, the docs for which are in the links in that quote from the OH Rules docs page.