Using a NumberItem in a Rule Function

Hi all,

I’m trying to get callable functions from within rules to work (Openhab 2 beta 4), from the description at https://github.com/openhab/openhab/wiki/Reusable-Rules-via-Functions

A basic function with a simple String argument works fine, but when I pass something like a NumberItem I can’t get access to its members.

val org.eclipse.xtext.xbase.lib.Functions$Function1 myFunction = [
  org.openhab.core.library.items.NumberItem item |
        logInfo("Test", String::format("Item: %s", item))
        logInfo("Test", String::format("Item: %s", item.state))
]

When I call my function, my NumberItem gets passed in fine, but accessing any of its members gives me an error.
The above code produces the following in the logs:

2017-01-16 21:11:30.011 [INFO ] [lipse.smarthome.model.script.Test] - Item: MyItem (Type=NumberItem, State=3.20, Label=Some Item Category=temperature, Groups=[gTest])
2017-01-16 21:11:30.016 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Battery Monitor: The name ‘.state’ cannot be resolved to an item or type.

The examples that I found simple access the item.state member, but I always get this error. Anyone an idea how to access the state?

try using item.state.toString. The String::format may be having problems converting the State to a String.