Allow panels with external URL (#9214)
* Allow panels with external URL * Update comment
This commit is contained in:
parent
de4a4fe71a
commit
bb37294047
2 changed files with 29 additions and 11 deletions
|
@ -109,14 +109,13 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
|
|||
|
||||
component_name: name of the web component
|
||||
path: path to the HTML of the web component
|
||||
(required unless url is provided)
|
||||
md5: the md5 hash of the web component (for versioning, optional)
|
||||
sidebar_title: title to show in the sidebar (optional)
|
||||
sidebar_icon: icon to show next to title in sidebar (optional)
|
||||
url_path: name to use in the url (defaults to component_name)
|
||||
url: for the web component (for dev environment, optional)
|
||||
url: for the web component (optional)
|
||||
config: config to be passed into the web component
|
||||
|
||||
Warning: this API will probably change. Use at own risk.
|
||||
"""
|
||||
panels = hass.data.get(DATA_PANELS)
|
||||
if panels is None:
|
||||
|
@ -127,14 +126,16 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
|
|||
|
||||
if url_path in panels:
|
||||
_LOGGER.warning("Overwriting component %s", url_path)
|
||||
if not os.path.isfile(path):
|
||||
_LOGGER.error(
|
||||
"Panel %s component does not exist: %s", component_name, path)
|
||||
return
|
||||
|
||||
if md5 is None:
|
||||
with open(path) as fil:
|
||||
md5 = hashlib.md5(fil.read().encode('utf-8')).hexdigest()
|
||||
if url is None:
|
||||
if not os.path.isfile(path):
|
||||
_LOGGER.error(
|
||||
"Panel %s component does not exist: %s", component_name, path)
|
||||
return
|
||||
|
||||
if md5 is None:
|
||||
with open(path) as fil:
|
||||
md5 = hashlib.md5(fil.read().encode('utf-8')).hexdigest()
|
||||
|
||||
data = {
|
||||
'url_path': url_path,
|
||||
|
|
|
@ -7,7 +7,7 @@ import pytest
|
|||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.frontend import (
|
||||
DOMAIN, ATTR_THEMES, ATTR_EXTRA_HTML_URL)
|
||||
DOMAIN, ATTR_THEMES, ATTR_EXTRA_HTML_URL, DATA_PANELS, register_panel)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -163,3 +163,20 @@ def test_extra_urls(mock_http_client_with_urls):
|
|||
assert resp.status == 200
|
||||
text = yield from resp.text()
|
||||
assert text.find('href=\'https://domain.com/my_extra_url.html\'') >= 0
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_panel_without_path(hass):
|
||||
"""Test panel registration without file path."""
|
||||
register_panel(hass, 'test_component', 'nonexistant_file')
|
||||
assert hass.data[DATA_PANELS] == {}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_panel_with_url(hass):
|
||||
"""Test panel registration without file path."""
|
||||
register_panel(hass, 'test_component', None, url='some_url')
|
||||
assert hass.data[DATA_PANELS] == {
|
||||
'test_component': {'component_name': 'test_component',
|
||||
'url': 'some_url',
|
||||
'url_path': 'test_component'}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue