Methods of custom class unknown in rules, but works from JSR223

Tags: #<Tag:0x00007efed85b2bf0> #<Tag:0x00007efed85b2830> #<Tag:0x00007efed85b2678>

Hello,

I’ve implemented a binding that contains an action class with static methods. They return a custom builder to create a configuration and apply it.

Now I’m facing problems when I try to use it from rules. The static method is called and returns the builder (verified in debugger), but I can’t call any method of the builder in the rule.

import org.openhab.binding.tado.TadoActions
import org.openhab.binding.tado.internal.TadoHvacChange

rule "Back to schedule"
    when
        Item BackToScheduleRule received command ON
    then
       TadoActions.tadoHvacChange("tado:zone:demo:heating").followSchedule().apply()
       BackToScheduleRule.postUpdate(OFF)
end

fails with error message

Rule 'Back to schedule': An error occurred during the script execution: The name '<XMemberFeatureCallImplCustom>.followSchedule()' cannot be resolved to an item or type.

But everything is working fine in JSR223 with a Javascript rule

'use strict';

scriptExtension.importPreset("RuleSupport");
scriptExtension.importPreset("RuleSimple");

var tadoActions = Java.type("org.openhab.binding.tado.TadoActions");

var sRule = new SimpleRule() {
    execute: function( module, input) {
        tadoActions.tadoHvacChange("tado:zone:demo:heating").followSchedule().apply();
        events.postUpdate("BackToScheduleJS", "OFF");
    }
};

sRule.setTriggers([
        new Trigger(
            "backToScheduleTrigger", 
            "core.ItemCommandTrigger", 
            new Configuration({
                "itemName": "BackToScheduleJS",
                "command": "ON"
            })
        )
    ]);

automationManager.addRule(sRule);

It looks like the rule knows the action class, but not the returned class org.openhab.binding.tado.internal.TadoHvacChange.

Can you please help me resolving the issue?
I’d be fine with using JSR223, but it’s a public binding, so both ways should work.

Thanks you very much!

1 Like

I’ve just answered you on https://github.com/dfrommi/openhab-tado/issues/4#issuecomment-386282804.

Note that the rule action definition is planned to be reworked at ESH to make the solution available in the old and new rule engine likewise - so I won’t go into the analysis of your specific problem as this anyhow will become deprecated.