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

Read /api/stream to receive server events #7

Open
fabiolima1 opened this issue Apr 14, 2020 · 3 comments
Open

Read /api/stream to receive server events #7

fabiolima1 opened this issue Apr 14, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@fabiolima1
Copy link

New Feature Description

It would be great to be able to receive server sent events form the endpoint /api/stream and call a callback function when a event is received.

Code Example

var ServerEventClient = ClientFactory.GetClient<ServerEventClient>();
ServerEventClient.Listen(ServerEventCallback());

HA API Docs or Sample

https://developers.home-assistant.io/docs/external_api_server_sent_events

@fabiolima1 fabiolima1 added the enhancement New feature or request label Apr 14, 2020
@fabiolima1 fabiolima1 changed the title Read /api/stream to Read /api/stream to receive server events Apr 14, 2020
@Devqon
Copy link

Devqon commented Feb 2, 2021

This would be really cool, but my understanding is that this can only be implemented through websockets, not through the RestSharp client

@qJake
Copy link
Owner

qJake commented Feb 2, 2021

Sort of, @Devqon... my understanding is that Home Assistant also supports Server-sent Events (SSE), and so we would need to either build out a custom HTTP client implementation that could listen for SSEs, or find a C# library specifically designed for them.

One example: https://makolyte.com/event-driven-dotnet-how-to-consume-an-sse-endpoint-with-httpclient/

Great care must be taken for this implementation, because you are effectively opening a connection and then keeping it open, which means handling opens/closes/reconnects as well as some possible threading issues. Definitely not a trivial task.

@RafaelEstevamReis
Copy link

Can this be worked around if implemented as a Asp component?
This is not what was asked, but some event is better than no event 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants