openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

[jsscripting] Documentation of event object manually run from GUI is wrong #316

Open FSeidinger opened 6 months ago

FSeidinger commented 6 months ago

Documentation of event object manually run from GUI is wrong

Expected behavior

The documentation states that this.event has the value undefined if manually run from the openHAB GUI.

Actual behavior

If run manually from the GUI (e.g. from the Run Now (CTRL-R button inside the script editor, this.event is not undefined but set to an instance of org.openhab.core.automation.events.ExecutionEvent.

Take for example the following script:

for (var prop in this.event) {
  console.log(prop);
}

console.log("toString: %s", this.event.toString());
console.log("getType: %s", this.event.getType());
console.log("getSource: %s", this.event.getSource());
console.log("getTopic: %s", this.event.getTopic());
console.log("getPayload: %s", this.event.getPayload());

It will produce the following output:

2023-12-29 22:00:49.888 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - toString
2023-12-29 22:00:49.889 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getType
2023-12-29 22:00:49.889 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getSource
2023-12-29 22:00:49.889 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getTopic
2023-12-29 22:00:49.889 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - equals
2023-12-29 22:00:49.889 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - hashCode
2023-12-29 22:00:49.889 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getPayload
2023-12-29 22:00:49.890 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - toString: Execution triggered by manual
2023-12-29 22:00:49.890 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getType: ExecutionEvent
2023-12-29 22:00:49.894 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getSource: manual
2023-12-29 22:00:49.894 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getTopic: openhab/execution/ea7175a2f9/triggered
2023-12-29 22:00:49.894 [INFO ] [nhab.automation.script.ui.ea7175a2f9] - getPayload: {}
florian-h05 commented 4 months ago

Since the documentation has been written, there were changes and it seems I forgot to update the UI event object docs (I never use the UI event object, all my JS rules are file-based).

I'm happy to accept a PR with a doc update!