Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

button capability not triggering listener for device.makeCapabilityInstance()? #19

Closed
robertklep opened this issue Nov 28, 2022 · 15 comments

Comments

@robertklep
Copy link

robertklep commented Nov 28, 2022

The HomeKitty app relies on device.makeCapabilityInstance() to watch for capability changes.

This works fine for the most part, but it looks like changes to button capabilities don't trigger a call to the listener.

I initially tested this with virtual devices (both from the Virtual Devices and the Device Capabilities apps), but to rule out an issue with those apps I wrote a test app, and the issue also occurs with that.

The registered capability listener for button in the device driver gets triggered as expected, so the capability itself is "wired in" correctly AFAICS.

It's also not limited to HomeKitty: the current version of HomeyKit, which uses a completely different codebase, also doesn't receive any change "events" for that capability.

@jeroenwienk
Copy link

Why would you need the state of a stateless button?

@robertklep
Copy link
Author

I don't need the state, but I would like to be able to catch button presses (for instance, a doorbell button being pressed) and pass them to HomeKit. AFAIK using a capability instance listener is the only (programmatic) way of doing that.

@jeroenwienk
Copy link

You could listen to device.on('capability', ({ capabilityId, transactionId, transactionTime, value }) => {}) this is the same event the capability instance listens to.

This would of course require that you check if it is an actual button capability.

@robertklep
Copy link
Author

Undocumented?

image

@jeroenwienk
Copy link

Undocumented?

image

Yes it's not something we really want to advertise to be used.

@robertklep
Copy link
Author

I'll see if I can make it work with this 👍🏻 FWIW, is this a regular EventEmitter-type setup, where I can other methods like removeListener etc?

@jeroenwienk
Copy link

I'll see if I can make it work with this 👍🏻 FWIW, is this a regular EventEmitter-type setup, where I can other methods like removeListener etc?

Yes or device.off('capability', mylistener).

Listeners are also removed if the device is destroyed(deleted).

@robertklep
Copy link
Author

I can't get the capability event to be sent at all, do I have to enable something for it to be emitted?

@jeroenwienk
Copy link

I can't get the capability event to be sent at all, do I have to enable something for it to be emitted?

Ah yes it seems makeCapabilityInstance calls device.connect();.

@robertklep
Copy link
Author

I got it working, but it looks like the capability event also isn't emitted for button capabilities 😟

@jeroenwienk
Copy link

I got it working, but it looks like the capability event also isn't emitted for button capabilities worried

🤦 it only happens for getable === true capabilities.

@jeroenwienk
Copy link

I got it working, but it looks like the capability event also isn't emitted for button capabilities worried

This is decided in the firmware btw.

@robertklep
Copy link
Author

Any idea if this a (relatively) recent change? HomeyKit has had a button listener implemented for ages so I assume that at some point it worked.

@jeroenwienk
Copy link

Any idea if this a (relatively) recent change? HomeyKit has had a button listener implemented for ages so I assume that at some point it worked.

It's been like this for at least 4 years. But there are button capabilities that are stateful. I think you can override it with capabilityOptions aswell and then it would emit the 'capability' event.

@robertklep
Copy link
Author

It looks like the relevant HomeyKit code is even older than that, so I guess it was never noticed (or complained about). I'll close this issue since I cannot control the capabilities of devices of other apps and it's not a big deal anyway 😊 Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants