Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
STATIC_PATH = os.path.join(os.path.dirname(__file__), 'www_static/')

ATTR_THEMES = 'themes'
ATTR_EXTRA_HTML_URL = 'extra_html_url'
DEFAULT_THEME_COLOR = '#03A9F4'
MANIFEST_JSON = {
'background_color': '#FFFFFF',
Expand All @@ -50,6 +51,7 @@
})

DATA_PANELS = 'frontend_panels'
DATA_EXTRA_HTML_URL = 'frontend_extra_html_url'
DATA_INDEX_VIEW = 'frontend_index_view'
DATA_THEMES = 'frontend_themes'
DATA_DEFAULT_THEME = 'frontend_default_theme'
Expand All @@ -66,6 +68,8 @@
vol.Optional(ATTR_THEMES): vol.Schema({
cv.string: {cv.string: cv.string}
}),
vol.Optional(ATTR_EXTRA_HTML_URL):
vol.All(cv.ensure_list, [cv.string]),
}),
}, extra=vol.ALLOW_EXTRA)

Expand Down Expand Up @@ -169,6 +173,15 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
'get', '/{}/{{extra:.+}}'.format(url_path), index_view.get)


@bind_hass
def add_extra_html_url(hass, url):
"""Register extra html url to load."""
url_set = hass.data.get(DATA_EXTRA_HTML_URL)
if url_set is None:
url_set = hass.data[DATA_EXTRA_HTML_URL] = set()
url_set.add(url)


def add_manifest_json_key(key, val):
"""Add a keyval to the manifest.json."""
MANIFEST_JSON[key] = val
Expand Down Expand Up @@ -208,6 +221,9 @@ def setup(hass, config):
else:
hass.data[DATA_PANELS] = {}

if DATA_EXTRA_HTML_URL not in hass.data:
hass.data[DATA_EXTRA_HTML_URL] = set()

register_built_in_panel(hass, 'map', 'Map', 'mdi:account-location')

for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state',
Expand All @@ -217,6 +233,9 @@ def setup(hass, config):
themes = config.get(DOMAIN, {}).get(ATTR_THEMES)
setup_themes(hass, themes)

for url in config.get(DOMAIN, {}).get(ATTR_EXTRA_HTML_URL, []):
add_extra_html_url(hass, url)

return True


Expand Down Expand Up @@ -362,7 +381,9 @@ def get(self, request, extra=None):
compatibility_url=compatibility_url, no_auth=no_auth,
icons_url=icons_url, icons=FINGERPRINTS['mdi.html'],
panel_url=panel_url, panels=hass.data[DATA_PANELS],
dev_mode=request.app[KEY_DEVELOPMENT])
dev_mode=request.app[KEY_DEVELOPMENT],
theme_color=MANIFEST_JSON['theme_color'],
extra_urls=hass.data[DATA_EXTRA_HTML_URL])

return web.Response(text=resp, content_type='text/html')

Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/frontend/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<meta name="msapplication-TileColor" content="#3fbbf4ff"/>
<meta name='mobile-web-app-capable' content='yes'>
<meta name='viewport' content='width=device-width, user-scalable=no'>
<meta name='theme-color' content='#03a9f4'>
<meta name='theme-color' content='{{ theme_color }}'>
<style>
body {
font-family: 'Roboto', 'Noto', sans-serif;
Expand Down Expand Up @@ -97,6 +97,10 @@
<link rel='import' href='{{ panel_url }}' onerror='initError()' async>
{% endif -%}
<link rel='import' href='{{ icons_url }}' async>
{% for extra_url in extra_urls -%}
<link rel='import' href='{{ extra_url }}' async>
{% endfor -%}

<script>
var webComponentsSupported = (
'registerElement' in document &&
Expand Down
22 changes: 21 additions & 1 deletion tests/components/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import pytest

from homeassistant.setup import async_setup_component
from homeassistant.components.frontend import DOMAIN, ATTR_THEMES
from homeassistant.components.frontend import (
DOMAIN, ATTR_THEMES, ATTR_EXTRA_HTML_URL)


@pytest.fixture
Expand All @@ -30,6 +31,16 @@ def mock_http_client_with_themes(hass, test_client):
return hass.loop.run_until_complete(test_client(hass.http.app))


@pytest.fixture
def mock_http_client_with_urls(hass, test_client):
"""Start the Hass HTTP component."""
hass.loop.run_until_complete(async_setup_component(hass, 'frontend', {
DOMAIN: {
ATTR_EXTRA_HTML_URL: ["https://domain.com/my_extra_url.html"]
}}))
return hass.loop.run_until_complete(test_client(hass.http.app))


@asyncio.coroutine
def test_frontend_and_static(mock_http_client):
"""Test if we can get the frontend."""
Expand Down Expand Up @@ -143,3 +154,12 @@ def test_missing_themes(mock_http_client):
json = yield from resp.json()
assert json['default_theme'] == 'default'
assert json['themes'] == {}


@asyncio.coroutine
def test_extra_urls(mock_http_client_with_urls):
"""Test that extra urls are loaded."""
resp = yield from mock_http_client_with_urls.get('/states')
assert resp.status == 200
text = yield from resp.text()
assert text.find('href=\'https://domain.com/my_extra_url.html\'') >= 0