How to find object methods?

Dumb question: I have a custom device that has methods available that most others of it’s type do not. One example of this could be a “thermostat” device type that has “present” or “away” status, such as the Nest thermostat. When writing something that may want to make use of this, I’m uncertain how to do feature detection to determine if the .away() or .present() method exist. I’ve found that following Groovy docs, that using thermostat.metaClass.getMetaMethod(“away”) yields the error: “Getting property metaClass on class is not allowed”. However, using a method that simply does not exist, you get the error “Command ‘____’ is not supported. Supported commands: []”.

Is there a way to get_class_methods of a given object so I can use non-standard features if available?


I think capabilities is the proper term here, not methods.

That said, it sounds like you’ll have to define your own device type. The Device Types indicate which capabilities the individual devices have as well as the code involved with reporting it. You can see this a little bit if you play around with the device types. They show all the different capabilities and you check which your type should have.

Of course, just checking the box isn’t enough you have to have the code behind the scenes that handles the capability.

Unfortunately, documentation for device types is VERY minimal-to-nonexistant at this point.

My device type currently does have added capabilities in it’s definition. My big question is - how can I take advantage of these additional methods safely? I can currently just say “termostat.away()” and my Nest will happily go into “Away” mode. However, if someone were to run my app that does not have the “away” method (as it is non-standard for thermostat device types), it’ll encounter an error. What I’d like to do is (basically):

// You probably have a nest, which wants to be "away" instead of "off"
if(thermostat.away) {
// You probably have a normal thermostat, which we should just switch "off"
else {