While I am new to programming in Groovy, I’m not new to programming in general. Give me some code examples and an API and I’m good to go. I’ve programmed a couple apps now, and the process is so frustrating due to a lack of documentation. I’ve tried using the SmartThings API but there is so much undocumented functionality I’ve found in other apps.
The particular issue I just had that prompted this post is to do with device lists. I wanted to check two device lists to see if there were any devices found in both lists. A google search shows the .intersect() property of lists, easy enough. I try outputting the following lines:
log.debug “Switch list 1: ${mySwitch}”
log.debug “Switch list 2: ${mySwitch2}”
log.debug “Switch intersect: ${mySwitch.intersect(mySwitch2)}”
which gives me the following output:
Switch list 1: [mySwitch[0], Bedroom Flood, Bedroom Jim, Bedroom Michelle]
Switch list 2: [mySwitch2, Bedroom Jim, Bedroom Michelle]
Switch intersect:
Well that didn’t work! Maybe SmartThings doesn’t support the .intersect function with lists? Lets test that out.
def ListA = [‘Hi’,‘bye’,‘yo’]
def ListB = [‘me’,‘you’,‘yo’]
log.debug “Intersection: ${ListA.intersect(ListB)}”
will give you
Intersection: [yo]
Huh, it worked. So I guess you can intersect lists, so why isn’t the list of devices working? Is it not an actual list? Another Google search teaches me the .getClass() function, so I give that a try on the variable mySwitch.
error java.lang.SecurityException: Invoking class physicalgraph.app.DeviceWrapperList.getClass() is not allowed @ line 75
Oh. So it isn’t a list, it’s a class called DeviceWrapperList. Does it not inherit the List class (and thus the function intersect)? Frustrating. Well, let me read up on that class to find out what I can do.
We have finally come to the SmartThings API. Using Google to search it is more likely to return what you’re looking for than the search built into the API. For this issue, the best I could find was this section. And all it does is tell you that a list of devices will be returned if multiple is set to true. But not a real list apparently.
There’s so much of the API hidden, some of which you can access and some you can’t, but no documentation about it. So if your Google searches don’t turn up someone else’s program that’s doing what you want, you’re kind of SOL.
Anyways, I can of course write my own .intersect function to loop through the lists looking for values in both lists. It’s an expensive operation, but minuscule considering the probably size of both lists. The point of this post is more to vent about the lack of documentation which makes programming for SmartThings difficult. (Though if there is a function to do what I want, please let me know!)