Closed robertklep closed 1 year ago
Why would you need the state of a stateless button?
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.
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.
Undocumented?
Undocumented?
Yes it's not something we really want to advertise to be used.
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?
I'll see if I can make it work with this 👍🏻 FWIW, is this a regular
EventEmitter
-type setup, where I can other methods likeremoveListener
etc?
Yes or device.off('capability', mylistener)
.
Listeners are also removed if the device is destroyed(deleted).
I can't get the capability
event to be sent at all, do I have to enable something for it to be emitted?
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();
.
I got it working, but it looks like the capability
event also isn't emitted for button
capabilities 😟
I got it working, but it looks like the
capability
event also isn't emitted forbutton
capabilities worried
:facepalm: it only happens for getable === true capabilities.
I got it working, but it looks like the
capability
event also isn't emitted forbutton
capabilities worried
This is decided in the firmware btw.
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.
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.
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!
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.