From 625fea7ffbfbf9c95f40a8185bb1e8f7e47ac2b8 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 14 Jul 2016 09:05:35 +0200 Subject: [PATCH] Add additional example --- source/developers/server_sent_events.markdown | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/source/developers/server_sent_events.markdown b/source/developers/server_sent_events.markdown index dd88245ce9e..52dd28a42b2 100644 --- a/source/developers/server_sent_events.markdown +++ b/source/developers/server_sent_events.markdown @@ -18,7 +18,7 @@ A requirement on the client-side is existing support for the [EventSource](https There are various ways to access the stream. One is `curl`: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ +$ curl -X GET -H "x-ha-access: 12345" \ -H "Content-Type: application/json" http://localhost:8123/api/stream ``` @@ -42,7 +42,27 @@ For more comfort put the HTML snippet below in a file `sse.html` in your `www` f Visit [http://localhost:8123/local/sse.html](http://localhost:8123/local/sse.html) to see the stream of events. -### {% linkable_title Example %} +## {% linkable_title Examples %} + +### {% linkable_title Website %} The [home-assistant-sse](https://github.com/fabaff/home-assistant-sse) repository contains an more advanced example. +### {% linkable_title Python %} + +If you want test the server-sent events without creating a website then the Python module [`sseclient` ](https://pypi.python.org/pypi/sseclient/) can help. Install it first: + +```bash +$ pip3 install sseclient +``` + +The simplest script to consume the SSE looks like the following snipplet. + +```python +from sseclient import SSEClient + +messages = SSEClient('http://localhost:8123/api/stream?api_password=MYPASS') +for msg in messages: + print(msg) +``` +