Command object methods

Stupid question time!

Are there any methods on the command object? The developer docs page for this is blank/no documentation.

Stepping back... Specifically I'm trying to see if there is any way to query a device command from an app and see if it accepts parameters, and if so how many/type?

I know I can do a device.getSupportedCommands() to get the list of commands on a device (and I do), but I would really like to be able to see if any of those commands accept parameters, too...

From Groovy metaclass inspection in a test app (just something like myDevice.supportedCommands.each { cmd -> log.trace "$cmd"; cmd.metaClass.methods.name.unique().each {log.warn "method = $it"} }, I see that there is a getParameters() method, so you can do something like this:

myDevice.supportedCommands.each { cmd -> log.trace "command = $cmd"; cmd.parameters?.each {log.warn "parameters = $ it"}}`)

It looks like getParameters() returns a List of Maps, just like how you can specify them for a custom command. You'll have to tease that apart, I suppose, for the type key, to get what you're really after.

But this is obviously all quite unofficial, so take staff's word instead should they reply. :slight_smile: Just doing what I can see given that the documentation for this class is entirely nonexistent...

2 Likes

I'll check that out.

I'm not a professional developer. Heck, I'm barely a functional hobbyist (otherwise I would have known how to do the metaclass inspection :flushed:).

So it helps a lot when those more capable take the time to guide us lesser capable people. :slight_smile: Very appreciated.

Edit: That works perfectly for what I'm trying to do! Thanks.

This was super helpful to me guys. I know it has been a long time since you posted this, but I am just now getting to this and the Command object is still not documented. I might try to add some documentation to the Wiki. Thanks again.

You'd probably be better off just posting feedback here; there is so much spam submitted for moderation to the MediaWiki platform that it's nearly impossible to wade through and find legitimate contributions, and this ability will likely not be a part of the documentation platform at all at some point in the future. I've been told that the developer docs in particular will also be regenerated (at least the ones that are just docs for objects/methods/etc.), presumably with missing notes added in, though I don't know the timeline for that. All this to say: I probably wouldn't spend much time on this, though the thought is appreciated!

If there are any glaring omissions in the meantime, posting here may be the best way to get something addressed. I'm not sure things like a getAllX() method that returns a List<X> is necessarily "glaring" (a lot of the technically "to be documented" methods are pretty straightforward, IMHO, though I know I'm biased given some familiarity with the platform...), but since I don't have a timeline for any of the above, I suppose it can't hurt. :smiley:

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.