I am trying to write a JSR223 script in a statically typed language. In particular I want to use Java as language and this plugin https://community.openhab.org/t/java223-scripting-script-with-java-on-openhab-4-3-0-0-5-0-0-0/ . I want to send a message over MQTT.
@InjectBinding org.openhab.core.automation.module.script.defaultscope.ScriptThingActions actions;
ThingActions mqtt_broker = actions.get("mqtt", "mqtt:broker:b1");
logger.debug(mqtt_broker.toString());
The last line prints org.openhab.binding.mqtt.internal.action.MQTTActions@141b70e. I cannot execute mqtt_broker.publishMQTT as the ThingActions has no such method. At the same time I cannot import org.openhab.binding.mqtt.internal.action.MQTTActions, and cast to it, as on OH 4.3 in org.openhab.binding.mqtt:META-INF/MANIFEST.MF contains
Export-Package: org.openhab.binding.mqtt;uses:="org.openhab.core.thing";
version="4.`3.8",org.openhab.binding.mqtt.discovery;uses:="org.openhab.c
ore.config.discovery,org.openhab.core.io.transport.mqtt,org.openhab.cor
e.thing";version="4.3.8",org.openhab.binding.mqtt.handler;uses:="org.op
enhab.binding.mqtt.discovery,org.openhab.core.io.transport.mqtt,org.ope
nhab.core.thing,org.openhab.core.thing.binding,org.openhab.core.types";
version="4.3.8"
However this works in Groovy/JSR223, as it is not so statically typed:
@Field var mqtt_broker = actions.get("mqtt", "mqtt:broker:b1")
mqtt_broker.publishMQTT("a", "bcd")
```
How in a statically typed JSR223 language one can call actions.get(“mqtt”, “mqtt:broker:b1”) and then on the result publishMQTT()?