diff --git a/.gitignore b/.gitignore index af2fb1769b1..ec8fbb301ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ config/* !config/home-assistant.conf.default homeassistant/components/http/www_static/polymer/bower_components/* -homeassistant/components/http/www_static/polymer/build.htm # There is not a better solution afaik.. !config/custom_components diff --git a/README.md b/README.md index f97bbd462fd..b0fc49566e5 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The system is built modular so support for other devices or actions can be imple ## Installation instructions / Quick-start guide -Running Home Assistant requires that node.js and python3 are installed. (Node.js is required for installing dependencies and concatenating the frontend) +Running Home Assistant requires that python3 is installed. Run the following code to get up and running with the minimum setup: @@ -36,8 +36,6 @@ Run the following code to get up and running with the minimum setup: git clone --recursive https://github.com/balloob/home-assistant.git cd home-assistant pip3 install -r requirements.txt -npm install bower vulcanize -./build_polymer python3 start.py ``` diff --git a/build_polymer b/build_polymer index 42eeae21143..3c865987c6a 100755 --- a/build_polymer +++ b/build_polymer @@ -1,3 +1,5 @@ +# To build the frontend, you need node, bower and vulcanize +# npm install -g bower vulcanize cd homeassistant/components/http/www_static/polymer bower install -vulcanize -o build.htm home-assistant-main.html +vulcanize -o ../frontend.html home-assistant-main.html diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 50741e7f3b6..7c951be0229 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -119,6 +119,7 @@ DOMAIN_ICONS = { CONF_API_PASSWORD = "api_password" CONF_SERVER_HOST = "server_host" CONF_SERVER_PORT = "server_port" +CONF_DEVELOPMENT = "development" def _get_domain_icon(domain): @@ -141,8 +142,11 @@ def setup(hass, config): server_port = config[DOMAIN].get(CONF_SERVER_PORT, rem.SERVER_PORT) + development = config[DOMAIN].get(CONF_DEVELOPMENT, "") == "1" + server = HomeAssistantHTTPServer((server_host, server_port), - RequestHandler, hass, api_password) + RequestHandler, hass, api_password, + development) hass.listen_once_event( ha.EVENT_HOMEASSISTANT_START, @@ -161,12 +165,13 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer): """ Handle HTTP requests in a threaded fashion. """ def __init__(self, server_address, RequestHandlerClass, - hass, api_password): + hass, api_password, development=False): super().__init__(server_address, RequestHandlerClass) + self.server_address = server_address self.hass = hass self.api_password = api_password - self.server_address = server_address + self.development = development self.logger = logging.getLogger(__name__) # To store flash messages between sessions @@ -175,6 +180,10 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer): # We will lazy init this one if needed self.event_forwarder = None + if development: + self.logger.info("running frontend in development mode") + + def start(self): """ Starts the server. """ self.logger.info( @@ -378,8 +387,10 @@ class RequestHandler(BaseHTTPRequestHandler): self.send_header('Content-type', 'text/html; charset=utf-8') self.end_headers() - # TODO let's be able to switch this based on env - app_url = "build.htm" if False else "home-assistant-main.html" + if self.server.development: + app_url = "polymer/home-assistant-main.html" + else: + app_url = "frontend.html" write(("" "Home Assistant" @@ -390,7 +401,7 @@ class RequestHandler(BaseHTTPRequestHandler): "" - "" + "" "" diff --git a/homeassistant/components/http/www_static/frontend.html b/homeassistant/components/http/www_static/frontend.html new file mode 100644 index 00000000000..271466d3823 --- /dev/null +++ b/homeassistant/components/http/www_static/frontend.html @@ -0,0 +1,9976 @@ + + + + + + + + + + + + + diff --git a/homeassistant/components/http/www_static/polymer/home-assistant-api.html b/homeassistant/components/http/www_static/polymer/home-assistant-api.html index 8bad3463f9e..6f9f51d538c 100644 --- a/homeassistant/components/http/www_static/polymer/home-assistant-api.html +++ b/homeassistant/components/http/www_static/polymer/home-assistant-api.html @@ -23,7 +23,7 @@ auto method="GET" url="/api/states" - headers='{"HA-access": "{{auth}}"}' + headers="{{ha_headers}}" on-core-response="{{statesLoaded}}" handleAs="json"> @@ -32,7 +32,7 @@ auto method="GET" url="/api/events" - headers='{"HA-access": "{{auth}}"}' + headers="{{ha_headers}}" on-core-response="{{eventsLoaded}}" handleAs="json"> @@ -41,7 +41,7 @@ auto method="GET" url="/api/services" - headers='{"HA-access": "{{auth}}"}' + headers="{{ha_headers}}" on-core-response="{{servicesLoaded}}" handleAs="json"> @@ -49,12 +49,16 @@