Hi everyone,
I tried out the new Ntfy binding from OH5.2.0 and I’m a little frustrated. Installing Bridge and Token-Thing via a things file went smoothly, but I can’t seem to generate a notification using a DSL rule as described in documentation.
Environment
- openHAB version: 5.2.0 (Release Version)
- Binding:
org.openhab.binding.ntfy - Rule type: Rules DSL (Xtend), executed via a UI Script Action
Description
The Rule Actions exposed by the ntfy binding (NtfyActions) cannot be used from Rules DSL as documented in the binding’s README. Calling the builder-style methods (withMessage, withPriority, send, etc.) fails with type errors, even when following the exact example shown in the documentation and even after casting explicitly to NtfyActions.
Steps to Reproduce
- Configure a
ntfy:serverbridge and antfy:ntfy-topicThing. - Create a DSL rule with the following script, exactly as shown in the binding’s README:
val bindingActions = getActions("ntfy", "ntfy:ntfy-topic:SMH-Events")
if (bindingActions !== null) {
val msgId = bindingActions.withMessage("Someone is at the door").withPriority(4).send()
}
Result:
Script execution of rule with UID ‘ntfy-1’ failed: ‘withMessage’ is not a member of ‘org.openhab.core.thing.binding.ThingActions’; line 3, column 17, length 26 in ntfy
- Add an explicit cast to
NtfyActions(importingorg.openhab.binding.ntfy.internal.action.NtfyActions):
import org.openhab.binding.ntfy.internal.action.NtfyActions
val bindingActions = getActions("ntfy", "ntfy:ntfy-topic:SMH-Events")
if (bindingActions !== null) {
val NtfyActions ntfyActions = bindingActions as NtfyActions
ntfyActions.withMessage("Someone is at the door").withPriority(4).send()
}
Result:
Script execution of rule with UID ‘ntfy-1’ failed: Could not cast org.openhab.binding.ntfy.internal.action.NtfyActions@6e9512e0 to void; line 5, column 35, length 29 in ntfy
- Even breaking the fluent chain into individual, explicitly-cast statements still fails, and the error now occurs on the very first cast expression itself (
bindingActions as NtfyActions):
var NtfyActions ntfyActions = bindingActions as NtfyActions
ntfyActions = ntfyActions.withMessage("Someone is at the door") as NtfyActions
ntfyActions = ntfyActions.withPriority(4) as NtfyActions
val String msgId = ntfyActions.send()
Script execution of rule with UID ‘ntfy-1’ failed: Could not cast org.openhab.binding.ntfy.internal.action.NtfyActions@6e9512e0 to void; line 2, column 15, length 64 in ntfy
Expected behavior
The Rules DSL usage documented in the README (calling withMessage(...).withPriority(...).send() directly on the object returned by getActions(), without any cast) should work without errors, as it does for other bindings using fluent Thing Action APIs.
Suspected cause
The NtfyActions builder methods appear to use a generic self-referencing return type pattern (e.g. <T extends X> T withMessage(...)), which the Rules DSL / Xbase interpreter seems unable to resolve correctly at runtime. The interpreter’s type inference for the cast/chain expression appears to incorrectly resolve the expected type to void, causing a ClassCastException-style failure even though the runtime object is a valid NtfyActions instance.
Request
Could the return types of the builder methods in NtfyActions be reviewed to avoid the generic self-type pattern (using a concrete NtfyActions return type instead), or could the README be updated to reflect a working Rules DSL example? Happy to provide further logs/debug output if needed.