OK, I was confused. I could have deleted my post, but maybe the answer will help someone else.
There’s only one set of handlers for a given capability. You have to key off command.component
in the handler.
To set an initial value, use:
device:emit_component_event(device.profile.components['component_name'], capabilities.<capability>.<attribute>(<value>))
In your handler, you can use a generic format like:
device:emit_component_event(device.profile.components[command.component], capabilities[command.capability].<attribute>(command.args.<varies>))
The component is an object-- not a string. That’s why it needs to be indexed off the device. Everything you need to execute the command is contained in the call. You could actually use a single handler for everything and use if’s to differentiate. This could be considered inefficient and sloppy or you might find it useful. In most cases, you care about state-- not the discrete values. Here’s a single switch handler
function command_setState(driver, device, command)
device:emit_event(capabilities[command.capability].switch(command.command))
end
that can be assigned to both
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = command_setState,
[capabilities.switch.commands.off.NAME] = command_setState
}
In this case, the command is the state.
I’ve been doing a lot of visual mock-ups and you just want to keep the controls moving. If you don’t assign initial values or handlers, you’ll likely see spinning dots followed by a timeout error.