Initial service worker support

This commit is contained in:
Paulus Schoutsen committed 2015-12-07 23:43:28 -08:00
1 parent e1990e07c7
commit fe485cc27d
6 files changed
+30 -14

No files matched your search

+13 -3
View File
@@ -22,8 +22,7 @@ _LOGGER = logging.getLogger(__name__)
FRONTEND_URLS = [
URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState',
'/devEvent', '/devInfo']
STATES_URL = re.compile(r'/states(/([a-zA-Z\._\-0-9/]+)|)')
'/devEvent', '/devInfo', '/states']
_FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
@@ -37,7 +36,8 @@ def setup(hass, config):
for url in FRONTEND_URLS:
hass.http.register_path('GET', url, _handle_get_root, False)
hass.http.register_path('GET', STATES_URL, _handle_get_root, False)
hass.http.register_path('GET', '/service_worker.js',
_handle_get_service_worker, False)
# Static files
hass.http.register_path(
@@ -78,6 +78,16 @@ def _handle_get_root(handler, path_match, data):
handler.wfile.write(template_html.encode("UTF-8"))
def _handle_get_service_worker(handler, path_match, data):
if handler.server.development:
sw_path = "home-assistant-polymer/build/service_worker.js"
else:
sw_path = "service_worker.js"
handler.write_file(os.path.join(os.path.dirname(__file__), 'www_static',
sw_path))
def _handle_get_static(handler, path_match, data):
""" Returns a static file for the frontend. """
req_file = util.sanitize_path(path_match.group('file'))