diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py
index 8f1ba162b46..5b4c948db41 100644
--- a/homeassistant/components/api.py
+++ b/homeassistant/components/api.py
@@ -6,6 +6,8 @@ Provides a Rest API for Home Assistant.
"""
import re
import logging
+import threading
+import json
import homeassistant as ha
from homeassistant.helpers import TrackStates
@@ -34,6 +36,9 @@ def setup(hass, config):
# /api - for validation purposes
hass.http.register_path('GET', URL_API, _handle_get_api)
+ # /api/stream
+ hass.http.register_path('GET', URL_API_STREAM, _handle_get_api_stream)
+
# /states
hass.http.register_path('GET', URL_API_STATES, _handle_get_api_states)
hass.http.register_path(
@@ -79,6 +84,40 @@ def _handle_get_api(handler, path_match, data):
handler.write_json_message("API running.")
+def _handle_get_api_stream(handler, path_match, data):
+ """ Provide a streaming interface for the event bus. """
+ hass = handler.server.hass
+ wfile = handler.wfile
+ block = threading.Event()
+
+ def event_sourcer(event):
+ """ Forwards events to the open request. """
+ if block.is_set() or event.event_type == EVENT_TIME_CHANGED:
+ return
+ elif event.event_type == EVENT_HOMEASSISTANT_STOP:
+ block.set()
+ return
+
+ msg = "data: {}\n\n".format(
+ json.dumps(event.as_dict(), cls=rem.JSONEncoder))
+
+ try:
+ wfile.write(msg.encode("UTF-8"))
+ wfile.flush()
+ except IOError:
+ block.set()
+
+ handler.send_response(HTTP_OK)
+ handler.send_header('Content-type', 'text/event-stream')
+ handler.end_headers()
+
+ hass.bus.listen(MATCH_ALL, event_sourcer)
+
+ block.wait()
+
+ hass.bus.remove_listener(MATCH_ALL, event_sourcer)
+
+
def _handle_get_api_states(handler, path_match, data):
""" Returns a dict containing all entity ids and their state. """
handler.write_json(handler.server.hass.states.all())
diff --git a/homeassistant/components/frontend/version.py b/homeassistant/components/frontend/version.py
index 451e72cc781..abb9ff32536 100644
--- a/homeassistant/components/frontend/version.py
+++ b/homeassistant/components/frontend/version.py
@@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
-VERSION = "873a4efef163787ea768e761f47354a2"
+VERSION = "3c4dc2ed787b1b4c50b17f4b2bedf0c4"
diff --git a/homeassistant/components/frontend/www_static/frontend.html b/homeassistant/components/frontend/www_static/frontend.html
index f0eb6978883..68c0ee6c6ca 100644
--- a/homeassistant/components/frontend/www_static/frontend.html
+++ b/homeassistant/components/frontend/www_static/frontend.html
@@ -109,13 +109,25 @@ b.events&&Object.keys(a).length>0&&console.log("[%s] addHostListeners:",this.loc
text-align: right;
word-break: break-all;
}
+
+
It looks like we have nothing to show you right now. It could be that we have not yet discovered all your devices but it is more likely that you have not configured Home Assistant yet.
Please see the Getting Started section on how to setup your devices. -
Fire an event on the event bus. @@ -195,7 +208,7 @@ return pickBy("isBefore",args)};moment.max=function(){var args=[].slice.call(arg