diff --git a/build_polymer b/build_polymer index 8917ff3cdad..0f303489196 100755 --- a/build_polymer +++ b/build_polymer @@ -2,5 +2,9 @@ # npm install -g bower vulcanize cd homeassistant/components/http/www_static/polymer bower install -vulcanize -o ../frontend.html --inline home-assistant-main.html -cp bower_components/platform/platform.js ../polymer_platform.js +cd .. +cp polymer/bower_components/platform/platform.js polymer_platform.js +vulcanize -o frontend.html --inline polymer/home-assistant-main.html +cd .. +echo '""" DO NOT MODIFY. Auto-generated by build_polymer script """' > frontend.py +echo 'VERSION = "'`md5 -q www_static/frontend.html`'"' >> frontend.py diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index df7f85e82c9..631c2fb269a 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -77,7 +77,8 @@ import logging import re import os import time -from http.server import BaseHTTPRequestHandler, HTTPServer +import gzip +from http.server import SimpleHTTPRequestHandler, HTTPServer from socketserver import ThreadingMixIn from urllib.parse import urlparse, parse_qs @@ -86,6 +87,8 @@ import homeassistant.remote as rem import homeassistant.util as util from homeassistant.components import (STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF) +from . import frontend + DOMAIN = "http" DEPENDENCIES = [] @@ -102,32 +105,12 @@ URL_ROOT = "/" URL_STATIC = "/static/{}" -DOMAIN_ICONS = { - "sun": "glyphicon-asterisk", - "group": "glyphicon-th-large", - "charging": "glyphicon-flash", - "light": "glyphicon-hdd", - "wemo": "glyphicon-hdd", - "device_tracker": "glyphicon-phone", - "chromecast": "glyphicon-picture", - "process": "glyphicon-barcode", - "browser": "glyphicon-globe", - "homeassistant": "glyphicon-home", - "downloader": "glyphicon-download-alt" -} - CONF_API_PASSWORD = "api_password" CONF_SERVER_HOST = "server_host" CONF_SERVER_PORT = "server_port" CONF_DEVELOPMENT = "development" -def _get_domain_icon(domain): - """ Returns HTML that shows domain icon. """ - return "".format( - DOMAIN_ICONS.get(domain, "")) - - def setup(hass, config): """ Sets up the HTTP API and debug interface. """ @@ -194,8 +177,15 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer): # pylint: disable=too-many-public-methods -class RequestHandler(BaseHTTPRequestHandler): - """ Handles incoming HTTP requests """ +class RequestHandler(SimpleHTTPRequestHandler): + """ + Handles incoming HTTP requests + + We extend from SimpleHTTPRequestHandler instead of Base so we + can use the guess content type methods. + """ + + server_version = "HomeAssistant/1.0" PATHS = [ # debug interface ('GET', URL_ROOT, '_handle_get_root'), @@ -323,6 +313,10 @@ class RequestHandler(BaseHTTPRequestHandler): else: self.send_response(HTTP_NOT_FOUND) + def do_HEAD(self): # pylint: disable=invalid-name + """ HEAD request handler. """ + self._handle_request('HEAD') + def do_GET(self): # pylint: disable=invalid-name """ GET request handler. """ self._handle_request('GET') @@ -390,7 +384,7 @@ class RequestHandler(BaseHTTPRequestHandler): if self.server.development: app_url = "polymer/home-assistant-main.html" else: - app_url = "frontend.html" + app_url = "frontend-{}.html".format(frontend.VERSION) write(("" "