I figure someone has asked this before but couldn’t seem to quite find the answer. Maybe it’s just a mental block of mine and the answer is obvious, dunno.
Anyhow, what I am trying to do is interrogate devices to make sure that they support a command before my app calls the command. I’m dealing with some thermostats but I figure that there are probably lots of potential devices that are similar but don’t support the same command set or the DTH wasn’t written to a suggested spec. The reason is that if you try and execute a command on say a group of devices then you get an error saying that device X doesn’t support the command and then app execution stops.
I couldn’t figure out any way to do something similar to the Elvis operator “?”. Given that its a group of devices, I wanted to find a way to do this on all the devices without going through each one but I didn’t find anything helpful there either. However, I did find in the docs that you could of course list the commands supported:
https://docs.smartthings.com/en/latest/ref-docs/command-ref.html
I then created some simple code to look at each device:
thermostats.each {
cmds = it.supportedCommands
log.debug "\nCommands: ${it.supportedCommands}\nResult: ${cmds.contains("resumeProgram")}\nFind: ${cmds.find {element -> element == "resumeProgram"}}"
}
But this seems to fail always, for instance the logs for the above on one of the devices that does support the desired functionality:
Commands: [refresh, setHeatingSetpoint, setCoolingSetpoint, off, heat, emergencyHeat, cool, setThermostatMode, fanOn, fanAuto, fanCirculate, setThermostatFanMode, auto, setSchedule, ping, generateEvent, resumeProgram, switchMode, switchFanMode, lowerHeatingSetpoint, raiseHeatingSetpoint, lowerCoolSetpoint, raiseCoolSetpoint, poll]
Result: false
Find: null
My questions are basically:
- Any ideas to do this in a more elegant fashion?
- If not, what groovy oddity am I forgetting about that makes the search always fail above?
Thanks!