core/homeassistant/components/panel_iframe.py

46 lines
1.3 KiB
Python
Raw Normal View History

"""
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
2016-07-17 05:32:36 +00:00
import voluptuous as vol
from homeassistant.const import (CONF_ICON, CONF_URL)
2016-07-17 05:32:36 +00:00
import homeassistant.helpers.config_validation as cv
DEPENDENCIES = ['frontend']
DOMAIN = 'panel_iframe'
2016-07-17 05:32:36 +00:00
CONF_TITLE = 'title'
CONF_RELATIVE_URL_ERROR_MSG = "Invalid relative URL. Absolute path required."
CONF_RELATIVE_URL_REGEX = r'\A/'
2016-07-17 05:32:36 +00:00
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
cv.slug: {
# pylint: disable=no-value-for-parameter
2016-07-17 05:32:36 +00:00
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),
vol.Url()),
2016-07-17 05:32:36 +00:00
}})}, extra=vol.ALLOW_EXTRA)
@asyncio.coroutine
2016-07-17 05:32:36 +00:00
def setup(hass, config):
"""Set up the iFrame frontend panels."""
2016-08-08 04:56:17 +00:00
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),
2016-08-08 04:56:17 +00:00
url_path, {'url': info[CONF_URL]})
2016-07-17 05:32:36 +00:00
return True