2016-03-09 10:15:04 +00:00
|
|
|
"""Handle the frontend for Home Assistant."""
|
2016-10-24 06:48:01 +00:00
|
|
|
import asyncio
|
2016-07-29 07:49:58 +00:00
|
|
|
import hashlib
|
2016-10-24 06:48:01 +00:00
|
|
|
import json
|
2016-07-17 05:32:25 +00:00
|
|
|
import logging
|
2015-01-30 07:56:04 +00:00
|
|
|
import os
|
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
from aiohttp import web
|
2017-07-13 01:08:13 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
2016-10-24 06:48:01 +00:00
|
|
|
|
2017-07-13 01:08:13 +00:00
|
|
|
from homeassistant.config import find_config_file, load_yaml_config_file
|
|
|
|
from homeassistant.const import CONF_NAME, EVENT_THEMES_UPDATED
|
2016-10-24 06:48:01 +00:00
|
|
|
from homeassistant.core import callback
|
2017-07-07 03:58:21 +00:00
|
|
|
from homeassistant.components import api
|
2016-05-14 07:58:36 +00:00
|
|
|
from homeassistant.components.http import HomeAssistantView
|
2016-11-25 21:04:06 +00:00
|
|
|
from homeassistant.components.http.auth import is_trusted_ip
|
|
|
|
from homeassistant.components.http.const import KEY_DEVELOPMENT
|
2016-07-17 05:32:25 +00:00
|
|
|
from .version import FINGERPRINTS
|
2015-01-30 07:56:04 +00:00
|
|
|
|
|
|
|
DOMAIN = 'frontend'
|
2016-11-27 20:13:01 +00:00
|
|
|
DEPENDENCIES = ['api', 'websocket_api']
|
2017-04-30 05:04:49 +00:00
|
|
|
|
2016-07-17 05:32:25 +00:00
|
|
|
URL_PANEL_COMPONENT = '/frontend/panels/{}.html'
|
|
|
|
URL_PANEL_COMPONENT_FP = '/frontend/panels/{}-{}.html'
|
2017-04-30 05:04:49 +00:00
|
|
|
|
2017-02-12 01:29:05 +00:00
|
|
|
STATIC_PATH = os.path.join(os.path.dirname(__file__), 'www_static/')
|
2017-04-30 05:04:49 +00:00
|
|
|
|
2017-07-13 01:08:13 +00:00
|
|
|
ATTR_THEMES = 'themes'
|
|
|
|
DEFAULT_THEME_COLOR = '#03A9F4'
|
2016-08-14 08:10:07 +00:00
|
|
|
MANIFEST_JSON = {
|
2017-04-30 05:04:49 +00:00
|
|
|
'background_color': '#FFFFFF',
|
|
|
|
'description': 'Open-source home automation platform running on Python 3.',
|
|
|
|
'dir': 'ltr',
|
|
|
|
'display': 'standalone',
|
|
|
|
'icons': [],
|
|
|
|
'lang': 'en-US',
|
|
|
|
'name': 'Home Assistant',
|
2017-07-01 04:57:38 +00:00
|
|
|
'short_name': 'Assistant',
|
2017-04-30 05:04:49 +00:00
|
|
|
'start_url': '/',
|
2017-07-13 01:08:13 +00:00
|
|
|
'theme_color': DEFAULT_THEME_COLOR
|
2016-08-14 08:10:07 +00:00
|
|
|
}
|
2016-07-20 06:36:46 +00:00
|
|
|
|
2016-11-25 05:37:56 +00:00
|
|
|
for size in (192, 384, 512, 1024):
|
|
|
|
MANIFEST_JSON['icons'].append({
|
2017-04-30 05:04:49 +00:00
|
|
|
'src': '/static/icons/favicon-{}x{}.png'.format(size, size),
|
|
|
|
'sizes': '{}x{}'.format(size, size),
|
|
|
|
'type': 'image/png'
|
2016-11-25 05:37:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
DATA_PANELS = 'frontend_panels'
|
|
|
|
DATA_INDEX_VIEW = 'frontend_index_view'
|
2017-07-13 01:08:13 +00:00
|
|
|
DATA_THEMES = 'frontend_themes'
|
|
|
|
DATA_DEFAULT_THEME = 'frontend_default_theme'
|
|
|
|
DEFAULT_THEME = 'default'
|
|
|
|
|
|
|
|
PRIMARY_COLOR = 'primary-color'
|
2016-11-25 05:37:56 +00:00
|
|
|
|
2016-07-20 06:36:46 +00:00
|
|
|
# To keep track we don't register a component twice (gives a warning)
|
|
|
|
_REGISTERED_COMPONENTS = set()
|
2016-07-17 05:32:25 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2017-07-13 01:08:13 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
|
|
DOMAIN: vol.Schema({
|
|
|
|
vol.Optional(ATTR_THEMES): vol.Schema({
|
|
|
|
cv.string: {cv.string: cv.string}
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
|
|
|
SERVICE_SET_THEME = 'set_theme'
|
|
|
|
SERVICE_RELOAD_THEMES = 'reload_themes'
|
|
|
|
SERVICE_SET_THEME_SCHEMA = vol.Schema({
|
|
|
|
vol.Required(CONF_NAME): cv.string,
|
|
|
|
})
|
|
|
|
|
2016-07-17 05:32:25 +00:00
|
|
|
|
2016-08-08 04:56:17 +00:00
|
|
|
def register_built_in_panel(hass, component_name, sidebar_title=None,
|
|
|
|
sidebar_icon=None, url_path=None, config=None):
|
2016-07-17 05:32:25 +00:00
|
|
|
"""Register a built-in panel."""
|
2017-02-12 01:29:05 +00:00
|
|
|
nondev_path = 'panels/ha-panel-{}.html'.format(component_name)
|
2016-07-17 05:32:25 +00:00
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
if hass.http.development:
|
2016-07-29 07:49:58 +00:00
|
|
|
url = ('/static/home-assistant-polymer/panels/'
|
|
|
|
'{0}/ha-panel-{0}.html'.format(component_name))
|
2017-02-12 01:29:05 +00:00
|
|
|
path = os.path.join(
|
|
|
|
STATIC_PATH, 'home-assistant-polymer/panels/',
|
|
|
|
'{0}/ha-panel-{0}.html'.format(component_name))
|
2016-07-29 07:49:58 +00:00
|
|
|
else:
|
|
|
|
url = None # use default url generate mechanism
|
2017-02-12 01:29:05 +00:00
|
|
|
path = os.path.join(STATIC_PATH, nondev_path)
|
2016-07-29 07:49:58 +00:00
|
|
|
|
2017-02-12 01:29:05 +00:00
|
|
|
# Fingerprint doesn't exist when adding new built-in panel
|
|
|
|
register_panel(hass, component_name, path,
|
|
|
|
FINGERPRINTS.get(nondev_path, 'dev'), sidebar_title,
|
|
|
|
sidebar_icon, url_path, url, config)
|
2016-07-17 05:32:25 +00:00
|
|
|
|
|
|
|
|
2016-08-08 04:56:17 +00:00
|
|
|
def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
|
|
|
|
sidebar_icon=None, url_path=None, url=None, config=None):
|
2016-07-17 05:32:25 +00:00
|
|
|
"""Register a panel for the frontend.
|
|
|
|
|
|
|
|
component_name: name of the web component
|
|
|
|
path: path to the HTML of the web component
|
2016-07-29 07:49:58 +00:00
|
|
|
md5: the md5 hash of the web component (for versioning, optional)
|
2016-08-08 04:56:17 +00:00
|
|
|
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)
|
2016-07-29 07:49:58 +00:00
|
|
|
url: for the web component (for dev environment, optional)
|
2016-07-17 05:32:25 +00:00
|
|
|
config: config to be passed into the web component
|
|
|
|
|
|
|
|
Warning: this API will probably change. Use at own risk.
|
|
|
|
"""
|
2016-11-25 05:37:56 +00:00
|
|
|
panels = hass.data.get(DATA_PANELS)
|
|
|
|
if panels is None:
|
|
|
|
panels = hass.data[DATA_PANELS] = {}
|
|
|
|
|
2016-08-08 04:56:17 +00:00
|
|
|
if url_path is None:
|
|
|
|
url_path = component_name
|
2016-07-17 05:32:25 +00:00
|
|
|
|
2016-11-25 05:37:56 +00:00
|
|
|
if url_path in panels:
|
2017-04-30 05:04:49 +00:00
|
|
|
_LOGGER.warning("Overwriting component %s", url_path)
|
2016-07-17 05:32:25 +00:00
|
|
|
if not os.path.isfile(path):
|
2017-04-30 05:04:49 +00:00
|
|
|
_LOGGER.error(
|
|
|
|
"Panel %s component does not exist: %s", component_name, path)
|
2016-07-29 07:49:58 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if md5 is None:
|
|
|
|
with open(path) as fil:
|
|
|
|
md5 = hashlib.md5(fil.read().encode('utf-8')).hexdigest()
|
2016-07-17 05:32:25 +00:00
|
|
|
|
|
|
|
data = {
|
2016-08-08 04:56:17 +00:00
|
|
|
'url_path': url_path,
|
2016-07-17 05:32:25 +00:00
|
|
|
'component_name': component_name,
|
|
|
|
}
|
|
|
|
|
2016-08-08 04:56:17 +00:00
|
|
|
if sidebar_title:
|
|
|
|
data['title'] = sidebar_title
|
|
|
|
if sidebar_icon:
|
|
|
|
data['icon'] = sidebar_icon
|
2016-07-17 05:32:25 +00:00
|
|
|
if config is not None:
|
|
|
|
data['config'] = config
|
|
|
|
|
2016-07-29 07:49:58 +00:00
|
|
|
if url is not None:
|
|
|
|
data['url'] = url
|
2016-07-17 05:32:25 +00:00
|
|
|
else:
|
|
|
|
url = URL_PANEL_COMPONENT.format(component_name)
|
2016-07-20 06:36:46 +00:00
|
|
|
|
|
|
|
if url not in _REGISTERED_COMPONENTS:
|
2016-10-24 06:48:01 +00:00
|
|
|
hass.http.register_static_path(url, path)
|
2016-07-20 06:36:46 +00:00
|
|
|
_REGISTERED_COMPONENTS.add(url)
|
|
|
|
|
2016-07-17 05:32:25 +00:00
|
|
|
fprinted_url = URL_PANEL_COMPONENT_FP.format(component_name, md5)
|
|
|
|
data['url'] = fprinted_url
|
|
|
|
|
2016-11-25 05:37:56 +00:00
|
|
|
panels[url_path] = data
|
|
|
|
|
|
|
|
# Register index view for this route if IndexView already loaded
|
|
|
|
# Otherwise it will be done during setup.
|
|
|
|
index_view = hass.data.get(DATA_INDEX_VIEW)
|
|
|
|
|
|
|
|
if index_view:
|
2017-04-30 05:04:49 +00:00
|
|
|
hass.http.app.router.add_route(
|
|
|
|
'get', '/{}'.format(url_path), index_view.get)
|
2017-07-07 03:58:21 +00:00
|
|
|
hass.http.app.router.add_route(
|
|
|
|
'get', '/{}/{{extra:.+}}'.format(url_path), index_view.get)
|
2016-07-17 05:32:25 +00:00
|
|
|
|
2015-06-24 06:22:32 +00:00
|
|
|
|
2016-08-14 08:10:07 +00:00
|
|
|
def add_manifest_json_key(key, val):
|
|
|
|
"""Add a keyval to the manifest.json."""
|
|
|
|
MANIFEST_JSON[key] = val
|
|
|
|
|
|
|
|
|
2015-01-30 07:56:04 +00:00
|
|
|
def setup(hass, config):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the serving of the frontend."""
|
2016-10-24 06:48:01 +00:00
|
|
|
hass.http.register_view(BootstrapView)
|
|
|
|
hass.http.register_view(ManifestJSONView)
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
if hass.http.development:
|
2016-05-10 01:09:38 +00:00
|
|
|
sw_path = "home-assistant-polymer/build/service_worker.js"
|
|
|
|
else:
|
|
|
|
sw_path = "service_worker.js"
|
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
hass.http.register_static_path("/service_worker.js",
|
2017-03-30 07:50:53 +00:00
|
|
|
os.path.join(STATIC_PATH, sw_path), False)
|
2016-10-24 06:48:01 +00:00
|
|
|
hass.http.register_static_path("/robots.txt",
|
2016-07-17 05:32:25 +00:00
|
|
|
os.path.join(STATIC_PATH, "robots.txt"))
|
2016-10-24 06:48:01 +00:00
|
|
|
hass.http.register_static_path("/static", STATIC_PATH)
|
|
|
|
|
|
|
|
local = hass.config.path('www')
|
|
|
|
if os.path.isdir(local):
|
|
|
|
hass.http.register_static_path("/local", local)
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-11-25 21:04:06 +00:00
|
|
|
index_view = hass.data[DATA_INDEX_VIEW] = IndexView()
|
2016-11-25 05:37:56 +00:00
|
|
|
hass.http.register_view(index_view)
|
|
|
|
|
|
|
|
# Components have registered panels before frontend got setup.
|
|
|
|
# Now register their urls.
|
|
|
|
if DATA_PANELS in hass.data:
|
|
|
|
for url_path in hass.data[DATA_PANELS]:
|
2017-07-07 03:58:21 +00:00
|
|
|
hass.http.app.router.add_route(
|
|
|
|
'get', '/{}'.format(url_path), index_view.get)
|
|
|
|
hass.http.app.router.add_route(
|
|
|
|
'get', '/{}/{{extra:.+}}'.format(url_path), index_view.get)
|
2016-11-25 05:37:56 +00:00
|
|
|
else:
|
|
|
|
hass.data[DATA_PANELS] = {}
|
|
|
|
|
2016-07-17 05:32:25 +00:00
|
|
|
register_built_in_panel(hass, 'map', 'Map', 'mdi:account-location')
|
|
|
|
|
|
|
|
for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state',
|
2017-07-13 16:11:49 +00:00
|
|
|
'dev-template', 'kiosk'):
|
2016-07-17 05:32:25 +00:00
|
|
|
register_built_in_panel(hass, panel)
|
|
|
|
|
2017-07-13 01:08:13 +00:00
|
|
|
themes = config.get(DOMAIN, {}).get(ATTR_THEMES)
|
|
|
|
if themes:
|
|
|
|
setup_themes(hass, themes)
|
|
|
|
|
2015-01-30 07:56:04 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2017-07-13 01:08:13 +00:00
|
|
|
def setup_themes(hass, themes):
|
|
|
|
"""Set up themes data and services."""
|
|
|
|
hass.data[DATA_THEMES] = themes
|
|
|
|
hass.data[DATA_DEFAULT_THEME] = DEFAULT_THEME
|
|
|
|
hass.http.register_view(ThemesView)
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def update_theme_and_fire_event():
|
|
|
|
"""Update theme_color in manifest."""
|
|
|
|
name = hass.data[DATA_DEFAULT_THEME]
|
|
|
|
themes = hass.data[DATA_THEMES]
|
|
|
|
if name != DEFAULT_THEME and PRIMARY_COLOR in themes[name]:
|
|
|
|
MANIFEST_JSON['theme_color'] = themes[name][PRIMARY_COLOR]
|
|
|
|
else:
|
|
|
|
MANIFEST_JSON['theme_color'] = DEFAULT_THEME_COLOR
|
|
|
|
hass.bus.async_fire(EVENT_THEMES_UPDATED, {
|
|
|
|
'themes': themes,
|
|
|
|
'default_theme': name,
|
|
|
|
})
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def set_theme(call):
|
|
|
|
"""Set backend-prefered theme."""
|
|
|
|
data = call.data
|
|
|
|
name = data[CONF_NAME]
|
|
|
|
if name == DEFAULT_THEME or name in hass.data[DATA_THEMES]:
|
|
|
|
_LOGGER.info("Theme %s set as default", name)
|
|
|
|
hass.data[DATA_DEFAULT_THEME] = name
|
|
|
|
update_theme_and_fire_event()
|
|
|
|
else:
|
|
|
|
_LOGGER.warning("Theme %s is not defined.", name)
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def reload_themes(_):
|
|
|
|
"""Reload themes."""
|
|
|
|
path = find_config_file(hass.config.config_dir)
|
|
|
|
new_themes = load_yaml_config_file(path)[DOMAIN].get(ATTR_THEMES, {})
|
|
|
|
hass.data[DATA_THEMES] = new_themes
|
|
|
|
if hass.data[DATA_DEFAULT_THEME] not in new_themes:
|
|
|
|
hass.data[DATA_DEFAULT_THEME] = DEFAULT_THEME
|
|
|
|
update_theme_and_fire_event()
|
|
|
|
|
|
|
|
descriptions = load_yaml_config_file(
|
|
|
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
|
|
|
hass.services.register(DOMAIN, SERVICE_SET_THEME,
|
|
|
|
set_theme,
|
|
|
|
descriptions[SERVICE_SET_THEME],
|
|
|
|
SERVICE_SET_THEME_SCHEMA)
|
|
|
|
hass.services.register(DOMAIN, SERVICE_RELOAD_THEMES, reload_themes,
|
|
|
|
descriptions[SERVICE_RELOAD_THEMES])
|
|
|
|
|
|
|
|
|
2016-05-10 01:09:38 +00:00
|
|
|
class BootstrapView(HomeAssistantView):
|
2016-05-14 07:58:36 +00:00
|
|
|
"""View to bootstrap frontend with all needed data."""
|
|
|
|
|
2017-04-30 05:04:49 +00:00
|
|
|
url = '/api/bootstrap'
|
|
|
|
name = 'api:bootstrap'
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
@callback
|
2016-05-10 01:09:38 +00:00
|
|
|
def get(self, request):
|
|
|
|
"""Return all data needed to bootstrap Home Assistant."""
|
2016-11-25 21:04:06 +00:00
|
|
|
hass = request.app['hass']
|
|
|
|
|
2016-05-14 07:58:36 +00:00
|
|
|
return self.json({
|
2016-11-25 21:04:06 +00:00
|
|
|
'config': hass.config.as_dict(),
|
|
|
|
'states': hass.states.async_all(),
|
|
|
|
'events': api.async_events_json(hass),
|
|
|
|
'services': api.async_services_json(hass),
|
|
|
|
'panels': hass.data[DATA_PANELS],
|
2016-05-14 07:58:36 +00:00
|
|
|
})
|
2016-05-10 01:09:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class IndexView(HomeAssistantView):
|
2016-05-14 07:58:36 +00:00
|
|
|
"""Serve the frontend."""
|
|
|
|
|
2016-05-28 04:45:38 +00:00
|
|
|
url = '/'
|
2017-04-30 05:04:49 +00:00
|
|
|
name = 'frontend:index'
|
2016-05-14 07:58:36 +00:00
|
|
|
requires_auth = False
|
2017-07-07 03:58:21 +00:00
|
|
|
extra_urls = ['/states', '/states/{extra}']
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-11-25 21:04:06 +00:00
|
|
|
def __init__(self):
|
2016-05-14 07:58:36 +00:00
|
|
|
"""Initialize the frontend view."""
|
2016-05-12 05:55:24 +00:00
|
|
|
from jinja2 import FileSystemLoader, Environment
|
|
|
|
|
2016-05-14 07:58:36 +00:00
|
|
|
self.templates = Environment(
|
2016-05-12 05:55:24 +00:00
|
|
|
loader=FileSystemLoader(
|
|
|
|
os.path.join(os.path.dirname(__file__), 'templates/')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
@asyncio.coroutine
|
2017-07-07 03:58:21 +00:00
|
|
|
def get(self, request, extra=None):
|
2016-05-12 05:55:24 +00:00
|
|
|
"""Serve the index view."""
|
2016-11-25 21:04:06 +00:00
|
|
|
hass = request.app['hass']
|
|
|
|
|
|
|
|
if request.app[KEY_DEVELOPMENT]:
|
2016-07-17 05:32:25 +00:00
|
|
|
core_url = '/static/home-assistant-polymer/build/core.js'
|
2017-02-14 20:00:45 +00:00
|
|
|
compatibility_url = \
|
|
|
|
'/static/home-assistant-polymer/build/compatibility.js'
|
2016-07-12 07:10:05 +00:00
|
|
|
ui_url = '/static/home-assistant-polymer/src/home-assistant.html'
|
2016-05-14 22:07:20 +00:00
|
|
|
else:
|
2016-07-17 05:32:25 +00:00
|
|
|
core_url = '/static/core-{}.js'.format(
|
|
|
|
FINGERPRINTS['core.js'])
|
2017-02-14 20:00:45 +00:00
|
|
|
compatibility_url = '/static/compatibility-{}.js'.format(
|
|
|
|
FINGERPRINTS['compatibility.js'])
|
2016-07-17 05:32:25 +00:00
|
|
|
ui_url = '/static/frontend-{}.html'.format(
|
|
|
|
FINGERPRINTS['frontend.html'])
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-07-20 06:36:46 +00:00
|
|
|
if request.path == '/':
|
|
|
|
panel = 'states'
|
|
|
|
else:
|
|
|
|
panel = request.path.split('/')[1]
|
|
|
|
|
2016-11-25 05:37:56 +00:00
|
|
|
if panel == 'states':
|
|
|
|
panel_url = ''
|
|
|
|
else:
|
2016-11-25 21:04:06 +00:00
|
|
|
panel_url = hass.data[DATA_PANELS][panel]['url']
|
2016-07-20 06:36:46 +00:00
|
|
|
|
2016-10-09 15:13:30 +00:00
|
|
|
no_auth = 'true'
|
2016-11-25 21:04:06 +00:00
|
|
|
if hass.config.api.api_password:
|
2016-10-09 15:13:30 +00:00
|
|
|
# require password if set
|
|
|
|
no_auth = 'false'
|
2016-11-25 21:04:06 +00:00
|
|
|
if is_trusted_ip(request):
|
2016-10-09 15:13:30 +00:00
|
|
|
# bypass for trusted networks
|
|
|
|
no_auth = 'true'
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-07-17 05:32:25 +00:00
|
|
|
icons_url = '/static/mdi-{}.html'.format(FINGERPRINTS['mdi.html'])
|
2017-05-26 15:28:07 +00:00
|
|
|
template = yield from hass.async_add_job(
|
|
|
|
self.templates.get_template, 'index.html')
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-05-16 07:25:47 +00:00
|
|
|
# pylint is wrong
|
|
|
|
# pylint: disable=no-member
|
2016-10-24 06:48:01 +00:00
|
|
|
# This is a jinja2 template, not a HA template so we call 'render'.
|
2016-05-29 01:38:46 +00:00
|
|
|
resp = template.render(
|
2017-02-14 20:00:45 +00:00
|
|
|
core_url=core_url, ui_url=ui_url,
|
|
|
|
compatibility_url=compatibility_url, no_auth=no_auth,
|
2016-07-20 06:36:46 +00:00
|
|
|
icons_url=icons_url, icons=FINGERPRINTS['mdi.html'],
|
2016-11-25 21:04:06 +00:00
|
|
|
panel_url=panel_url, panels=hass.data[DATA_PANELS])
|
2016-05-10 01:09:38 +00:00
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
return web.Response(text=resp, content_type='text/html')
|
2016-08-14 08:10:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ManifestJSONView(HomeAssistantView):
|
|
|
|
"""View to return a manifest.json."""
|
|
|
|
|
|
|
|
requires_auth = False
|
2017-04-30 05:04:49 +00:00
|
|
|
url = '/manifest.json'
|
|
|
|
name = 'manifestjson'
|
2016-08-14 08:10:07 +00:00
|
|
|
|
2016-10-24 06:48:01 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def get(self, request): # pylint: disable=no-self-use
|
2016-08-14 08:10:07 +00:00
|
|
|
"""Return the manifest.json."""
|
|
|
|
msg = json.dumps(MANIFEST_JSON, sort_keys=True).encode('UTF-8')
|
2016-10-24 06:48:01 +00:00
|
|
|
return web.Response(body=msg, content_type="application/manifest+json")
|
2017-07-13 01:08:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ThemesView(HomeAssistantView):
|
|
|
|
"""View to return defined themes."""
|
|
|
|
|
|
|
|
requires_auth = False
|
|
|
|
url = '/api/themes'
|
|
|
|
name = 'api:themes'
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def get(self, request):
|
|
|
|
"""Return themes."""
|
|
|
|
hass = request.app['hass']
|
|
|
|
|
|
|
|
return self.json({
|
|
|
|
'themes': hass.data[DATA_THEMES],
|
|
|
|
'default_theme': hass.data[DATA_DEFAULT_THEME],
|
|
|
|
})
|