Purpose of numberOfButtons in button capability?

What is the purpose of the numberOfButtons attribute in the button capability? If you have multiple buttons on a device, you still need to create different components for each. Setting the number doesn’t seem to have any effect. The UI and behavior are unchanged. It looks like nothing more than a place to save the count so you know how many components to look for. You can always use device:set_field() for that, so there isn’t much of a point.

Multiple buttons used to be supported by adding a buttonNumber in the event data.

When components came along the usual approach was to have a component for each button, each with numberOfButtons set to 1, plus a main component that had a composite button that still supported the old buttonNumber approach. This one had numberOfButtons set to the number of buttons it was representing so the apps/automations using the device could see what was going on.

Edge drivers still use this approach because the legacy apps haven’t gone yet and because a composite button is handy for the dashboard.

Just for completeness it should be mentioned that the original button capability just supported pushed and held (and didn’t have numberOfButtons). So something like a double press was implemented as pushed on a different button number.


Thanks for the thorough answer. If you have both a composite button and a component button, I assume you emit events to both for each button press. Do you see much point in maintaining the composite button going forward? Which legacy apps are you referring to?

The only reason I can think of for having a composite button is if you want to see the button pushes register on a single dashboard tile. Otherwise I think you are well rid of it.

1 Like