Site updated at 2016-10-17 19:36:44 UTC
This commit is contained in:
parent
6bb71e64c4
commit
baa5bef666
25 changed files with 52 additions and 52 deletions
|
@ -138,7 +138,7 @@ You can append <code class="highlighter-rouge">?api_password=YOUR_PASSWORD</code
|
|||
<p>The API supports the following actions:</p>
|
||||
|
||||
<h4><a class="title-link" name="get-api" href="#get-api"></a> GET /api/</h4>
|
||||
<p>Returns message if API is up and running.</p>
|
||||
<p>Returns a message if the API is up and running.</p>
|
||||
|
||||
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="w">
|
||||
</span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"API running."</span><span class="w">
|
||||
|
@ -226,7 +226,7 @@ You can append <code class="highlighter-rouge">?api_password=YOUR_PASSWORD</code
|
|||
</div>
|
||||
|
||||
<h4><a class="title-link" name="get-apievents" href="#get-apievents"></a> GET /api/events</h4>
|
||||
<p>Returns an array of event objects. Each event object contain event name and listener count.</p>
|
||||
<p>Returns an array of event objects. Each event object contains event name and listener count.</p>
|
||||
|
||||
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">[</span><span class="w">
|
||||
</span><span class="p">{</span><span class="w">
|
||||
|
@ -277,7 +277,7 @@ You can append <code class="highlighter-rouge">?api_password=YOUR_PASSWORD</code
|
|||
</div>
|
||||
|
||||
<h4><a class="title-link" name="get-apihistory" href="#get-apihistory"></a> GET /api/history</h4>
|
||||
<p>Returns an array of state changes in the past. Each object contains further detail for the entities.</p>
|
||||
<p>Returns an array of state changes in the past. Each object contains further details for the entities.</p>
|
||||
|
||||
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">[</span><span class="w">
|
||||
</span><span class="p">[</span><span class="w">
|
||||
|
@ -461,7 +461,7 @@ You can append <code class="highlighter-rouge">?api_password=YOUR_PASSWORD</code
|
|||
</div>
|
||||
|
||||
<h4><a class="title-link" name="post-apiservicesltdomainltservice" href="#post-apiservicesltdomainltservice"></a> POST /api/services/<domain>/<service></h4>
|
||||
<p>Calls a service within a specific domain. Will return when the service has been executed or 10 seconds has past, whichever comes first.</p>
|
||||
<p>Calls a service within a specific domain. Will return when the service has been executed or after 10 seconds, whichever comes first.</p>
|
||||
|
||||
<p>You can pass an optional JSON object to be used as <code class="highlighter-rouge">service_data</code>.</p>
|
||||
|
||||
|
@ -500,7 +500,7 @@ You can append <code class="highlighter-rouge">?api_password=YOUR_PASSWORD</code
|
|||
</div>
|
||||
|
||||
<p class="note">
|
||||
The result will include any changed states that changed while the service was being executed, even if their change was the result of something else happening in the system.
|
||||
The result will include any states that changed while the service was being executed, even if their change was the result of something else happening in the system.
|
||||
</p>
|
||||
|
||||
<h4><a class="title-link" name="post-apitemplate" href="#post-apitemplate"></a> POST /api/template</h4>
|
||||
|
@ -527,7 +527,7 @@ The result will include any changed states that changed while the service was be
|
|||
</div>
|
||||
|
||||
<h4><a class="title-link" name="post-apievent_forwarding" href="#post-apievent_forwarding"></a> POST /api/event_forwarding</h4>
|
||||
<p>Setup event forwarding to another Home Assistant instance.</p>
|
||||
<p>Set up event forwarding to another Home Assistant instance.</p>
|
||||
|
||||
<p>Requires a JSON object that represents the API to forward to.</p>
|
||||
|
||||
|
@ -539,7 +539,7 @@ The result will include any changed states that changed while the service was be
|
|||
</span></code></pre>
|
||||
</div>
|
||||
|
||||
<p>It will return a message if event forwarding was setup successful.</p>
|
||||
<p>It will return a message if event forwarding was set up successfully.</p>
|
||||
|
||||
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="w">
|
||||
</span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Event forwarding setup."</span><span class="w">
|
||||
|
@ -560,7 +560,7 @@ The result will include any changed states that changed while the service was be
|
|||
</span></code></pre>
|
||||
</div>
|
||||
|
||||
<p>It will return a message if event forwarding was cancelled successful.</p>
|
||||
<p>It will return a message if event forwarding was cancelled successfully.</p>
|
||||
|
||||
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="w">
|
||||
</span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Event forwarding cancelled."</span><span class="w">
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>For more comfort put the HTML snippet below in a file <code class="highlighter-rouge">sse.html</code> in your <code class="highlighter-rouge">www</code> folder of your Home Assistant configuration directory (<code class="highlighter-rouge">.homeassistant</code>)</p>
|
||||
<p>You can create a convenient view for this by creating an HTML file (<code class="highlighter-rouge">sse.html</code>) in the <code class="highlighter-rouge">www</code> folder of your Home Assistant configuration directory (<code class="highlighter-rouge">.homeassistant</code>). Paste this snippet into the file:</p>
|
||||
|
||||
<div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="cp"><!DOCTYPE html></span>
|
||||
<span class="nt"><html></span>
|
||||
|
@ -124,7 +124,7 @@
|
|||
|
||||
<h2><a class="title-link" name="examples" href="#examples"></a> Examples</h2>
|
||||
|
||||
<p>A simplest way to consume server-sent events is <code class="highlighter-rouge">httpie</code>.</p>
|
||||
<p>A simple way to consume server-sent events is to use a command-line http client like [httpie][https://httpie.org/]. Installation info is on the site (if you use Homebrew, it’s <code class="highlighter-rouge">brew install httpie</code>). Once installed, run this snippet from your terminal:</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>http --stream http://localhost:8123/api/stream x-ha-access:YOUR_PASSWORD content-type:application/json
|
||||
</code></pre>
|
||||
|
@ -132,17 +132,17 @@
|
|||
|
||||
<h3><a class="title-link" name="website" href="#website"></a> Website</h3>
|
||||
|
||||
<p>The <a href="https://github.com/fabaff/home-assistant-sse">home-assistant-sse</a> repository contains an more advanced example.</p>
|
||||
<p>The <a href="https://github.com/fabaff/home-assistant-sse">home-assistant-sse</a> repository contains a more advanced example.</p>
|
||||
|
||||
<h3><a class="title-link" name="python" href="#python"></a> Python</h3>
|
||||
|
||||
<p>If you want test the server-sent events without creating a website then the Python module <a href="https://pypi.python.org/pypi/sseclient/"><code class="highlighter-rouge">sseclient</code> </a> can help. Install it first:</p>
|
||||
<p>If you want to test the server-sent events without creating a website, the Python module <a href="https://pypi.python.org/pypi/sseclient/"><code class="highlighter-rouge">sseclient</code> </a> can help. To install (assuming Python and pip3 are already installed):</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>pip3 install sseclient
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The simplest script to consume the SSE looks like the following snipplet.</p>
|
||||
<p>The simplest script to consume the SSE in Python looks like this:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">sseclient</span> <span class="kn">import</span> <span class="n">SSEClient</span>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue