Lambda problem

I have a string
String NP60_4_Animation “Animaties” (All) {mqtt=">[mosquitto:164ARD/OpenColor/animation:command:*:default]"}

that I can call using
sendCommand( NP60_4_Animation, color )

I’m trying to replicate that call in a function I can reuse on multiple arduino’s.

val org.eclipse.xtext.xbase.lib.Functions$Function2 belVoordeur = [
String neopixelMessage,
int color
|
sendCommand( NP60_4_Animation, color )
sendCommand( neopixelMessage, color)

]

Which I call with

belVoordeur.apply(NP60_4_Animation,0)

The first line
sendCommand( NP60_4_Animation, color )
Works, yet it does not use a parameter for the arduino.

I had hoped the second line would do that, yet it doesn’t.

Any idea what I’m doing wrong?
5I never wrote any lambda’s so Im’ probably screwing up big time
yet the int parameter does work…
so I assume I’m close…

NP60_4_Animation isn’t a string as such, it is an Item.
So …

val org.eclipse.xtext.xbase.lib.Functions$Function2 belVoordeur = [
String neopixelMessage,
should I think be
val org.eclipse.xtext.xbase.lib.Functions$Function2 belVoordeur = [
StringItem neopixelMessage,

You can extract the .name of the passed-in item within the lambda
sendCommand( neopixelMessage.name, color)

Now, int color …
but you try to send that as a command to a stringy Item? It may need typecasting as a string, not sure

1 Like

thanks
the solution was

val org.eclipse.xtext.xbase.lib.Functions$Function2 belVoordeur = [
org.openhab.core.library.items.SwitchItem neopixelMessage,
int color
|
sendCommand( neopixelMessage, color )

]