hass-core/homeassistant/components/panel_iframe.py
Rene Nulsch cad0bde95b Panel_Iframe - Allow relative urls in config (#11832)
* Panel_Iframe - Allow relative urls in config

* change regex to check for starting forward slash only

* Change error message and const name
2018-01-26 22:31:40 -08:00

44 lines
1.2 KiB
Python

"""
Register an iFrame front end panel.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/panel_iframe/
"""
import asyncio
import voluptuous as vol
from homeassistant.const import (CONF_ICON, CONF_URL)
import homeassistant.helpers.config_validation as cv
DEPENDENCIES = ['frontend']
DOMAIN = 'panel_iframe'
CONF_TITLE = 'title'
CONF_RELATIVE_URL_ERROR_MSG = "Invalid relative URL. Absolute path required."
CONF_RELATIVE_URL_REGEX = r'\A/'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
cv.slug: {
vol.Optional(CONF_TITLE): cv.string,
vol.Optional(CONF_ICON): cv.icon,
vol.Required(CONF_URL): vol.Any(
vol.Match(
CONF_RELATIVE_URL_REGEX,
msg=CONF_RELATIVE_URL_ERROR_MSG),
cv.url),
}})}, extra=vol.ALLOW_EXTRA)
@asyncio.coroutine
def setup(hass, config):
"""Set up the iFrame frontend panels."""
for url_path, info in config[DOMAIN].items():
yield from hass.components.frontend.async_register_built_in_panel(
'iframe', info.get(CONF_TITLE), info.get(CONF_ICON),
url_path, {'url': info[CONF_URL]})
return True