Button Coding

I have a doubleTappableButton. In a custom app I want to subscribe to the button and then determine whether its pushed, held, doubletapped.

I know I can subscribe to each of those separately, but is there a way to just have one subscribe then in the handler determine which it was?

No, they are different events. You'll need to,subscribe to each one (or to everything, but I would not recommend that approach since you'll likely also get things like battery events that are not necessary for your app).

I kinda figured that, but wanted to check.

When you say you can subscribe to everything, how would you do that? Not going to, but wondering how it would be done.

All the subscribe() signatures are documented:

You would want to (or again my suggetion to not :smiley: ) use the one without an attribute name on the device.

As I stated, I am not going to do that. But wondering how it would be done. There doesn't appear to be any atribute to subscribe to that would subscribe to any event from the button device. Just leaving the atribute blank throws an error.

EDIT:
According to the docs, this is aceptable:
void subscribe(DeviceWrapper device, String handlerMethod, Map options = null)

I tried
subscribe(testButton, testHandler)
subscribe(testButton, ,testHandler)
subscribe(testButton, "", testHandler)

None work.

Figured it out:
subscribe(testButton, null, testHandler)

The documented format is subscribe(testButton, "testHandler"). That being said, I'm not sure I've ever actually tried it...

That's what I saw also. But it throws an error.

Just pointing out a subtle difference since that wasn't a variant I saw mentioned above. :slight_smile:

In any case, that doesn't appear to be working for me either. I'm not sure why, as there appears to be hub code that should handle it. But passing null for the attribute, as you discovered, or providing an empty Map instead of null for the options (e.g., subscribe(testButton, "testHandler", [:]) — making it use a different signature) both work in my testing.