Streaming API will keep session alive

This commit is contained in:
Paulus Schoutsen 2015-11-28 22:14:40 -08:00
parent e67732b4f8
commit 733de6b357
2 changed files with 28 additions and 18 deletions

View file

@ -106,6 +106,7 @@ def _handle_get_api_stream(handler, path_match, data):
wfile = handler.wfile
write_lock = threading.Lock()
block = threading.Event()
session_id = None
restrict = data.get('restrict')
if restrict:
@ -119,6 +120,7 @@ def _handle_get_api_stream(handler, path_match, data):
try:
wfile.write(msg.encode("UTF-8"))
wfile.flush()
handler.server.sessions.extend_validation(session_id)
except IOError:
block.set()
@ -138,6 +140,7 @@ def _handle_get_api_stream(handler, path_match, data):
handler.send_response(HTTP_OK)
handler.send_header('Content-type', 'text/event-stream')
session_id = handler.set_session_cookie_header()
handler.end_headers()
hass.bus.listen(MATCH_ALL, forward_events)