`.subscribe_states` implemented?
zmrow opened this issue · 1 comments
Hi there! Thanks for the hard work on this library! I was familiarizing myself with this and the reference python implementation here.
I'm very new to protobuf and how everything works, but it seems like the python implementation of subscribe_states
takes a callback function which would be called when states of the entities change. It appears esphome.rs
's AuthenticatedDevice
implements the method, but it doesn't take a callback function as an argument.
Is this just a choice of the library? Or is it unimplemented? Just trying to understand. :)
Hi @zmrow, nice to see some interest in this library!
Right now this is a very minimal MVP - the library supports reading states and not much else. I did however use the full protobuf specification for the protocol (and as such already included in api.rs), so it should be fairly trivial to add support for other messages. (Another thing to add would be the recently added encryption support in the protocol).
The subscribe_states
call right now only sends the message to the device indicating that you want to receive state updates. Right now the library simply ignores any such update messages it receives (it actually only attempts to receive and interpret messages at all when you ask it to - e.g. list_devices will send a request to list devices, then wait for responses, and will discard any messages other than answers to the 'list devices' command).
To make subscribe_states work there should probably be some central loop that listens and dispatches messages from the devices to the correct 'listener'. In this scenario list_devices
would be an async function and I guess subscribe_states
could be an async iterator that you can await
for new state updates.
Feel free to send a PR, I don't really have time to work on this over the next few weeks!