Okay… I think I’m kinda understanding. Looking at the bit of code again:
def open = doors.findAll { it?.latestValue(“contact”) == “open” }
My set that I’m working with is doors, which is my collection of open/close sensors.
When I do .findall it’s more or less saying: On this set of values (doors), I want to find any that fit the parameter that I’m about to indicate.
Next I’ll specific the parameter in the {}. ‘it’ is a pronoun that takes the place of my set, doors. The ? is uses because doors can contain multiple items, so it’s it1, it2, it3… until I complete looking through the set. Then of course we’re looking for the .latestValue of the parameter (“contact”). I’m asking for a positive returns on those instances where that value is equal to “open”.
Am I good so far? (I hope!)
Now’s the part where I’m not sure if I’m getting it. What does the variable open (from the beginning of the equation) equal now? I think maybe it is now a subset of doors, right? Specifically, it’s the collection of doors who have a latest value of “open” as for contact.
For example, when installing the program the user specifies frontDoor, sideDoor, and backDoor as the doors this program should look at. So the variable ‘doors’ = frontDoor, sideDoor, backDoor. Now the back door and side door are open when we run the bit of code above. So after this it should populate the variable ‘open’ with: “sideDoor, backDoor”.
Does that sound right? If so, then I’m sort stuck on this last part. The conditional I’m using is this:
if(open) { [insert action here] }
So what is this conditional asking? If ??what?? then do the action… What does ‘if(open)’ test? Is it merely asking if open exists? That is… If open equals something… anything… then proceed with action? So in my example above because open is populated with sideDoor and backDoor then we run the action, but if no doors were open, then the variable open = null, and if it equal null, then we don’t run the action?