Stuffing a list: *ALL


@ady624: while i was in there doing the *CLEAR

thought i might as well add a stuff method for lists. so, added a stuff method for use like this

set variable lightNames[*ALL] = “0:light 1,1:light 2,2:light 3”

which gives:

lightNames = {“0”:“light 1”, “1”:“light 2”, “2”:“light 3”}

seems to be working as desired. not sure if there might an unwanted side effect from replacing the entire variable value instead of just a single indexed value in the list?


/*** stuff returns a map used to initialize a list variable. called from	***/
/*** setvariable when set variable list[*ALL] = "idx:value,idx:value"		***/
private stuff(rtData, variable, value) {
	if (!value)
    	return [t: "error", v: "Invalid value. Expecting value in form 'idx:value,idx:value'"];
	def list = value.split(',').toList()
	if (list.size() <= 0)
		return [t: "error", v: "Invalid value. To clear the list use set variable list[*CLEAR] = ''"];
	def mappedValue = [:]
	list.each	{
        def splitIt = it.indexOf(':')
        def listIDX = it.substring(0, splitIt)
        def listValue = it.substring(splitIt+1, it.size())
		if (listIDX.size() < 1)
			mappedValue << [t: "error", v: "Invalid value. Each list item must be in form 'idx:value'"];
			mappedValue.put(listIDX, cast(rtData, listValue, variable.t.replace('[]', '')));
	return mappedValue

EDIT: updated to use cast(…)

Lists & Arrays - documentation?
Clearing a list?
Creating and Accessing a WebCore String List (Text)
Date Countdown
Need your feedback on a new key-value piston input type in webCoRE

Uh… what is this?


heres an example to show the basic functionality of this

remember to update the testString accordingly after selecting the devices, order does not matter.

Variable loops in notification piston
Monitor Switch/Contact Sensors Status - need help


I can see this being useful!


thanks. just need one more thing a $firstRun flag so, the lists can get initialized only if its first run for the piston. rest of the runs for the piston the list values should be just directly accessed via IDX.


Couldn’t you just create a variable called firstRun and set it to false at the end of the piston? Then for every other run it will be false?


that works unless you edit the piston. so, say i did that in the example piston above. it would work till i needed to edit the piston to add some more devices. once i add the devices and updated testString the strings[] list will not get updated on the next run because firstRun is already false.

also, might have to use an is true check instead of a is false check because null might be evaluated as false in groovy … havent checked this one.


Good point… So it is the first run for the piston, since it was last edited…?

And yeah - I would probably do it as firstRunCompleted and set it to true.


yes, since it was last saved.

or if the empty variables get initialized when a piston is saved that would work too.


and while i am on reminders … @ady624 or @ipaterson?


Does this work anymore? I tried it and I get a new item with “*ALL” as the key. Same with *CLEAR.


the webcore code has probably changed since then … i will take a look tomorrow and see if i can provide an updated version.


Any news on this? Any ways of clearing a list on current version?


@tyron thanks for the pull request, this will be in the next release!


Thank @bangali. He created the solution. I just delivered the message :wink:


Any luck with clearing lists?


Is there a way to do this in the current version? Entering the index *ALL doesn’t appear to work. the variable remains blank


How to cleaning a list?


I tried this piston and got…


I don’t see this code in the webCoRE code base (from ST)…

I don’t think this was accepted in as near as I can tell