- Platform information:
- Hardware: x86_64
- OS: Ubuntu 18.04
- Java Runtime Environment: OpenJDK 64-Bit Server VM Zulu11.60+19-CA (build 11.0.17+8-LTS, mixed mode)
- openHAB version: 3.3
Hi, first thank you all for the great work you did with OpenHAB, it’s great fun using it
I’m currently upgrading the lighting control in my home using UI based Javascript rules (the ECMAScript 2021+ version) and while I generally have no problems achieving what I want with the information available, no matter what I do, I don’t seem to be able to get the script to dump me all the available members of the event object.
Why would I want to do that? The docs (github .com/openhab/openhab-js#ui-event-object) hint at some available properties, but only talk about items. Because my event is a channel trigger the list is probably not complete and my first idea was to print all available members (Javascript is interpreted, so introspection shouldn’t be a problem, right). Surprisingly, I got a very different list:
[
"getEvent",
"toString",
"getType",
"getChannel",
"getTopic",
"getPayload",
"getSource",
"equals",
"hashCode"
]
All of these are functions. Yet the properties mentioned in the docs are in fact available, even the editor seems to know about them. I tried all sorts (medium .com/swlh/javascript-iterate-over-object-properties-b20fe67b5b9b) of ways (stackoverflow .com/questions/8024149/is-it-possible-to-get-the-non-enumerable-inherited-property-names-of-an-object) to dump the members without success and eventually found out that event is of type object, but does not inherit from Object, hence cannot have inherited properties, which may be difficult to traverse. This and the mention of the docs that the properties are Java-properties brought me to the GraalVM docs (www.graalvm .org/22.1/reference-manual/js/JavaInteroperability/#iterating-properties) which state that a javascript for…in loop is supposed to work, yet it doesn’t, except for the mentioned functions.
I also found the older helper-libraries docs (openhab-scripters.github .io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html#event-object-attributes) which are helpful in listing some more properties. Funnily they suggest to do what I was trying, and while there seems to be a solution for Python (openhab-scripters.github .io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html#view-the-names-of-an-object-s-attributes) on how to print the properties, the Javascript variant unfortunately only states TODO.
The functions I can iterate have so far been sufficient for all my needs, so the question stems more from my surprise and interest in why this seemingly trivial task seems to elude my abilities, rather than from actual need, if you get my meaning
But if anybody knows how to do this I’d be very happy (but if you tell me that what I’m asking is technically impossible, then I’d be happy, too. Even more if you could add why ^^).
Thanks, Martin
(sorry, I had to to add a space before the TLD in the links, because of some new-user limit)