Tweak panel parameters (#2746)

This commit is contained in:
Paulus Schoutsen 2016-08-07 21:56:17 -07:00 committed by GitHub
parent 23472cb44d
commit b9b1d95514
9 changed files with 27 additions and 26 deletions

View file

@ -20,8 +20,8 @@ _REGISTERED_COMPONENTS = set()
_LOGGER = logging.getLogger(__name__)
def register_built_in_panel(hass, component_name, title=None, icon=None,
url_name=None, config=None):
def register_built_in_panel(hass, component_name, sidebar_title=None,
sidebar_icon=None, url_path=None, config=None):
"""Register a built-in panel."""
# pylint: disable=too-many-arguments
path = 'panels/ha-panel-{}.html'.format(component_name)
@ -33,30 +33,31 @@ def register_built_in_panel(hass, component_name, title=None, icon=None,
url = None # use default url generate mechanism
register_panel(hass, component_name, os.path.join(STATIC_PATH, path),
FINGERPRINTS[path], title, icon, url_name, url, config)
FINGERPRINTS[path], sidebar_title, sidebar_icon, url_path,
url, config)
def register_panel(hass, component_name, path, md5=None, title=None, icon=None,
url_name=None, url=None, config=None):
def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
sidebar_icon=None, url_path=None, url=None, config=None):
"""Register a panel for the frontend.
component_name: name of the web component
path: path to the HTML of the web component
md5: the md5 hash of the web component (for versioning, optional)
title: title to show in the sidebar (optional)
icon: icon to show next to title in sidebar (optional)
url_name: name to use in the url (defaults to component_name)
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)
config: config to be passed into the web component
Warning: this API will probably change. Use at own risk.
"""
# pylint: disable=too-many-arguments
if url_name is None:
url_name = component_name
if url_path is None:
url_path = component_name
if url_name in PANELS:
_LOGGER.warning('Overwriting component %s', url_name)
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)
@ -67,14 +68,14 @@ def register_panel(hass, component_name, path, md5=None, title=None, icon=None,
md5 = hashlib.md5(fil.read().encode('utf-8')).hexdigest()
data = {
'url_name': url_name,
'url_path': url_path,
'component_name': component_name,
}
if title:
data['title'] = title
if icon:
data['icon'] = icon
if sidebar_title:
data['title'] = sidebar_title
if sidebar_icon:
data['icon'] = sidebar_icon
if config is not None:
data['config'] = config
@ -90,7 +91,7 @@ def register_panel(hass, component_name, path, md5=None, title=None, icon=None,
fprinted_url = URL_PANEL_COMPONENT_FP.format(component_name, md5)
data['url'] = fprinted_url
PANELS[url_name] = data
PANELS[url_path] = data
def setup(hass, config):

View file

@ -2,7 +2,7 @@
FINGERPRINTS = {
"core.js": "fb9a1af0cf7d39f3041d3fa67e16e81c",
"frontend.html": "fb24d923539bd6cf82a96b0a93b33aec",
"frontend.html": "cfebe592f524eff270282929d5f5fa0c",
"mdi.html": "f6c6cc64c2ec38a80e91f801b41119b3",
"panels/ha-panel-dev-event.html": "8f63a091246408228beebf276440c06e",
"panels/ha-panel-dev-info.html": "34e2df1af32e60fffcafe7e008a92169",

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit a343d3d098e78976fc66f8ed66ce0ae5d7bc3861
Subproject commit 3512e5aa25c0d48328a384865bd47514072a6c7e

File diff suppressed because one or more lines are too long

View file

@ -23,9 +23,9 @@ CONFIG_SCHEMA = vol.Schema({
def setup(hass, config):
"""Setup iframe frontend panels."""
for url_name, info in config[DOMAIN].items():
for url_path, info in config[DOMAIN].items():
register_built_in_panel(
hass, 'iframe', info.get(CONF_TITLE), info.get(CONF_ICON),
url_name, {'url': info[CONF_URL]})
url_path, {'url': info[CONF_URL]})
return True

View file

@ -63,7 +63,7 @@ class TestPanelIframe(unittest.TestCase):
'icon': 'mdi:network-wireless',
'title': 'Router',
'url': '/frontend/panels/iframe-md5md5.html',
'url_name': 'router'
'url_path': 'router'
}
assert frontend.PANELS['weather'] == {
@ -72,5 +72,5 @@ class TestPanelIframe(unittest.TestCase):
'icon': 'mdi:weather',
'title': 'Weather',
'url': '/frontend/panels/iframe-md5md5.html',
'url_name': 'weather',
'url_path': 'weather',
}