Rule Errors with OpenHab2

Hi,

I have the following lambda rule which ran fine with openhab 1:

        org.openhab.core.items.GenericItem out_name,
        org.openhab.core.items.GenericItem text,
        org.openhab.core.items.GenericItem min,
        org.openhab.core.items.GenericItem max,
        java.util.HashMap<String, String> mapping |
return false
]
        ````

What is the correct import for the GenericItem with Openhab2.

http://docs.openhab.org/tutorials/migration.html#rules

All references to org.openhab.core.* in imports and class references should be removed. All of these classes are automatically included and have moved.

1 Like

Yea - I have read the docs.
I still have to reference the data type in the lambda though.
What is the correct new name?

Sorry, I’m not familiar with lambdas …

But I’m pretty sure you will find your answer in the posts from lambda guru @rlkoshak :grinning:

Yes - thank you very much for the link!
I changed it to

val org.eclipse.xtext.xbase.lib.Functions$Function5 WetterFormat = [
        GenericItem  out_name,
        GenericItem  text,
        GenericItem  min,
        GenericItem  max,
        java.util.HashMap<String, String> mapping |
        return false
]
1 Like

Alternatively you can specify the types of the arguments and the return value using Java style generics notation:

val org.eclipse.xtext.xbase.lib.Functions$Function5 <GenericItem, GenericItem, GenericItem,
 java.util.HashMap<String,String>, Boolean> WetterFormat = [
        out_name,
        text,
        min,
        max,
        mapping |
        return false
]

Also, the return is optional. The result of last line executed in the lambda becomes the return value. This is why you cannot have something like a logInfo as the last line of a lambda; it returns void.

I like this notation primarily because you can direct the return type. It also eliminates the warnings in Designer.