device.hasCapability(String) fails -- possible bug?

I have an app that checks the capabilities of a child device:

child.hasCapability('ColorControl')

This call is always returning false, even when the child device is a device that implements the capability.

Furthermore, if I call child.getCapabilities(), it does report back the ColorControl capability as one of the supported capabilities.

child.getCapabilities().each { log.info "${it.name} = ${it.toString()}" }

It would seem this is a bug. Though I wouldn't rule out that I am passing the wrong values.

Have you tried colorControl instead of ColorControl?

I have tried colorControl, ColorControl, colorcontrol, Capability.ColorControl, Capability.colorcontrol and Capability.colorControl

I see no reason why it would be anything other than ColorControl though, since the argument is a strong, and should be the name of the capability, and the snippet of code to print all capabilities for the device prints ColorControl for both the Capability’s name property, and the toString() method.

Not saying it isn’t what I am passing in, but that I can figure out what it could possibly be that I need to pass in

checking into this...

Wasn't where I could check, but when I dump the properties it is reported as ColorControl. I always have to check as I tend to use a lower case start with camel case.

Running this in an app:

        def cd = getChildDevices()[0]
        if (cd == null) {
            log.trace "add device here"
            cd = addChildDevice("hubitat", "Virtual RGBW Light", "vss1", null, [label: "appCD", name: "appCD"])
        }
        log.trace cd.getCapabilities()
        log.trace cd.hasCapability("ColorControl")

I get this in the logs:
[trace] true
[trace] [Actuator, ColorTemperature, ColorMode, ColorControl, SwitchLevel, Light, Switch]

2 Likes

Thank you for confirming this works. And I am truly stumped now. I provided the code, that I was using (sans the if block) and it was failing to process correctly. I added the logging that you showed, and it worked, so I uncommented my if, and it is working now. I have no idea what was going on last night. Maybe I was just too tired.

Sorry to waste your time just to confirm this works. I should have done better.

No worries man!

I marked your answer as the solution so if anyone else finds this, they will see it does work, and the supplied example.

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