Can't Use delayBetween in "configure" or "updated" Methods?

This one is kind of creep because it's either really weird Groovy or really weird platform bug.

I have this driver:

You will notice that it calls setPrefs() from updated() and configure() and test(). Here's the wild thing. Calling it from test() works. When it is called from updated() and configure() it doesn't work. I can see in the trace the formatted Z-Wave messages are identical.

Can you shed any light on this, @chuck.schwer?

Line 852, add an explicit return before delayBetween

1 Like

When the function returns multiple items you have to use "+=" instead of "<<" so it's actually this line that isn't working.

cmds << setPrefs()

1 Like

@mike.maxwell Ah, so delayBetween isn't schedule or performing an action. It's just creating an array with delay commands in between what you pass. I didn't realize it was just returning values that were (in every example I've seen recently) implicitly return. I'll watch that.

@krlaframboise This was the issue. I didn't look close enough at the print outs. The << operator works but it adds the elements as a collection instead of individually. This would also work probably:

def cmds = []
cmds << setPrefs()
delayBetween(cmds.flatten(), 500)

But since the += operator handles adding elements individually from collections I'll rock that instead.

Thanks to both of you.

1 Like

This doesn't work because of "<<"

def cmds = []
cmds << setPrefs()
delayBetween(cmds, 500)

Change it to this and everything will work.

def cmds = []
cmds += setPrefs()
delayBetween(cmds, 500)
2 Likes