From 5322789c1448ba042d07bfa08cabaa8f0fc175c2 Mon Sep 17 00:00:00 2001 From: Tom Duijf Date: Thu, 8 Oct 2015 14:10:33 +0000 Subject: [PATCH] Ability to store icons/pictures in config_dir/www for e.g. device_tracker pictures --- homeassistant/components/frontend/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 419e48d55b5..b327e510cd8 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -11,6 +11,7 @@ import logging from . import version import homeassistant.util as util from homeassistant.const import URL_ROOT, HTTP_OK +from homeassistant.config import get_default_config_dir DOMAIN = 'frontend' DEPENDENCIES = ['api'] @@ -19,7 +20,6 @@ INDEX_PATH = os.path.join(os.path.dirname(__file__), 'index.html.template') _LOGGER = logging.getLogger(__name__) - FRONTEND_URLS = [ URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState', '/devEvent'] @@ -44,6 +44,9 @@ def setup(hass, config): hass.http.register_path( 'HEAD', re.compile(r'/static/(?P[a-zA-Z\._\-0-9/]+)'), _handle_get_static, False) + hass.http.register_path( + 'GET', re.compile(r'/local/(?P[a-zA-Z\._\-0-9/]+)'), + _handle_get_local, False) return True @@ -84,3 +87,16 @@ def _handle_get_static(handler, path_match, data): path = os.path.join(os.path.dirname(__file__), 'www_static', req_file) handler.write_file(path) + + +def _handle_get_local(handler, path_match, data): + """ + Returns a static file from the hass.config.path/www for the frontend. + """ + req_file = util.sanitize_path(path_match.group('file')) + + path = os.path.join(get_default_config_dir(), 'www', req_file) + if not os.path.isfile(path): + return False + + handler.write_file(path)