def get_template(self, latest): """Get template.""" if self.repo_path is not None: root = self.repo_path elif latest: import hass_frontend root = hass_frontend.where() else: import hass_frontend_es5 root = hass_frontend_es5.where() tpl = self._template_cache.get(root) if tpl is None: with open(os.path.join(root, 'index.html')) as file: tpl = jinja2.Template(file.read()) # Cache template if not running from repository if self.repo_path is None: self._template_cache[root] = tpl return tpl
def async_setup(hass, config): """Set up the serving of the frontend.""" hass.http.register_view(ManifestJSONView) conf = config.get(DOMAIN, {}) repo_path = conf.get(CONF_FRONTEND_REPO) is_dev = repo_path is not None hass.data[DATA_JS_VERSION] = js_version = conf.get(CONF_JS_VERSION) if is_dev: hass.http.register_static_path("/home-assistant-polymer", repo_path, False) hass.http.register_static_path( "/static/translations", os.path.join(repo_path, "build-translations"), False) sw_path_es5 = os.path.join(repo_path, "build-es5/service_worker.js") sw_path_latest = os.path.join(repo_path, "build/service_worker.js") static_path = os.path.join(repo_path, 'hass_frontend') frontend_es5_path = os.path.join(repo_path, 'build-es5') frontend_latest_path = os.path.join(repo_path, 'build') else: import hass_frontend import hass_frontend_es5 sw_path_es5 = os.path.join(hass_frontend_es5.where(), "service_worker.js") sw_path_latest = os.path.join(hass_frontend.where(), "service_worker.js") # /static points to dir with files that are JS-type agnostic. # ES5 files are served from /frontend_es5. # ES6 files are served from /frontend_latest. static_path = hass_frontend.where() frontend_es5_path = hass_frontend_es5.where() frontend_latest_path = static_path hass.http.register_static_path("/service_worker_es5.js", sw_path_es5, False) hass.http.register_static_path("/service_worker.js", sw_path_latest, False) hass.http.register_static_path("/robots.txt", os.path.join(static_path, "robots.txt"), not is_dev) hass.http.register_static_path("/static", static_path, not is_dev) hass.http.register_static_path("/frontend_latest", frontend_latest_path, not is_dev) hass.http.register_static_path("/frontend_es5", frontend_es5_path, not is_dev) local = hass.config.path('www') if os.path.isdir(local): hass.http.register_static_path("/local", local, not is_dev) index_view = IndexView(repo_path, js_version) hass.http.register_view(index_view) @asyncio.coroutine def finalize_panel(panel): """Finalize setup of a panel.""" yield from panel.async_finalize(hass, repo_path) panel.async_register_index_routes(hass.http.app.router, index_view) yield from asyncio.wait([ async_register_built_in_panel(hass, panel) for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template', 'dev-mqtt', 'kiosk') ], loop=hass.loop) hass.data[DATA_FINALIZE_PANEL] = finalize_panel # Finalize registration of panels that registered before frontend was setup # This includes the built-in panels from line above. yield from asyncio.wait( [finalize_panel(panel) for panel in hass.data[DATA_PANELS].values()], loop=hass.loop) if DATA_EXTRA_HTML_URL not in hass.data: hass.data[DATA_EXTRA_HTML_URL] = set() if DATA_EXTRA_HTML_URL_ES5 not in hass.data: hass.data[DATA_EXTRA_HTML_URL_ES5] = set() for url in conf.get(CONF_EXTRA_HTML_URL, []): add_extra_html_url(hass, url, False) for url in conf.get(CONF_EXTRA_HTML_URL_ES5, []): add_extra_html_url(hass, url, True) yield from async_setup_themes(hass, conf.get(CONF_THEMES)) return True
async def async_setup(hass, config): """Set up the serving of the frontend.""" hass.components.websocket_api.async_register_command( WS_TYPE_GET_PANELS, websocket_get_panels, SCHEMA_GET_PANELS) hass.components.websocket_api.async_register_command( WS_TYPE_GET_THEMES, websocket_get_themes, SCHEMA_GET_THEMES) hass.components.websocket_api.async_register_command( WS_TYPE_GET_TRANSLATIONS, websocket_get_translations, SCHEMA_GET_TRANSLATIONS) hass.http.register_view(ManifestJSONView) conf = config.get(DOMAIN, {}) repo_path = conf.get(CONF_FRONTEND_REPO) is_dev = repo_path is not None hass.data[DATA_JS_VERSION] = js_version = conf.get(CONF_JS_VERSION) if is_dev: hass_frontend_path = os.path.join(repo_path, 'hass_frontend') hass_frontend_es5_path = os.path.join(repo_path, 'hass_frontend_es5') else: import hass_frontend import hass_frontend_es5 hass_frontend_path = hass_frontend.where() hass_frontend_es5_path = hass_frontend_es5.where() hass.http.register_static_path( "/service_worker_es5.js", os.path.join(hass_frontend_es5_path, "service_worker.js"), False) hass.http.register_static_path( "/service_worker.js", os.path.join(hass_frontend_path, "service_worker.js"), False) hass.http.register_static_path( "/robots.txt", os.path.join(hass_frontend_path, "robots.txt"), False) hass.http.register_static_path("/static", hass_frontend_path, not is_dev) hass.http.register_static_path("/frontend_latest", hass_frontend_path, not is_dev) hass.http.register_static_path("/frontend_es5", hass_frontend_es5_path, not is_dev) local = hass.config.path('www') if os.path.isdir(local): hass.http.register_static_path("/local", local, not is_dev) index_view = IndexView(repo_path, js_version, hass.auth.active) hass.http.register_view(index_view) hass.http.register_view(AuthorizeView(repo_path, js_version)) @callback def async_finalize_panel(panel): """Finalize setup of a panel.""" panel.async_register_index_routes(hass.http.app.router, index_view) await asyncio.wait([ async_register_built_in_panel(hass, panel) for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template', 'dev-mqtt', 'kiosk', 'lovelace', 'profile') ], loop=hass.loop) hass.data[DATA_FINALIZE_PANEL] = async_finalize_panel # Finalize registration of panels that registered before frontend was setup # This includes the built-in panels from line above. for panel in hass.data[DATA_PANELS].values(): async_finalize_panel(panel) if DATA_EXTRA_HTML_URL not in hass.data: hass.data[DATA_EXTRA_HTML_URL] = set() if DATA_EXTRA_HTML_URL_ES5 not in hass.data: hass.data[DATA_EXTRA_HTML_URL_ES5] = set() for url in conf.get(CONF_EXTRA_HTML_URL, []): add_extra_html_url(hass, url, False) for url in conf.get(CONF_EXTRA_HTML_URL_ES5, []): add_extra_html_url(hass, url, True) _async_setup_themes(hass, conf.get(CONF_THEMES)) return True
def async_setup(hass, config): """Set up the serving of the frontend.""" if list(hass.auth.async_auth_providers): client = yield from hass.auth.async_create_client( 'Home Assistant Frontend', redirect_uris=['/'], no_secret=True, ) else: client = None hass.components.websocket_api.async_register_command( WS_TYPE_GET_PANELS, websocket_handle_get_panels, SCHEMA_GET_PANELS) hass.http.register_view(ManifestJSONView) conf = config.get(DOMAIN, {}) repo_path = conf.get(CONF_FRONTEND_REPO) is_dev = repo_path is not None hass.data[DATA_JS_VERSION] = js_version = conf.get(CONF_JS_VERSION) if is_dev: hass_frontend_path = os.path.join(repo_path, 'hass_frontend') hass_frontend_es5_path = os.path.join(repo_path, 'hass_frontend_es5') else: import hass_frontend import hass_frontend_es5 hass_frontend_path = hass_frontend.where() hass_frontend_es5_path = hass_frontend_es5.where() hass.http.register_static_path( "/service_worker_es5.js", os.path.join(hass_frontend_es5_path, "service_worker.js"), False) hass.http.register_static_path( "/service_worker.js", os.path.join(hass_frontend_path, "service_worker.js"), False) hass.http.register_static_path( "/robots.txt", os.path.join(hass_frontend_path, "robots.txt"), False) hass.http.register_static_path("/static", hass_frontend_path, not is_dev) hass.http.register_static_path("/frontend_latest", hass_frontend_path, not is_dev) hass.http.register_static_path("/frontend_es5", hass_frontend_es5_path, not is_dev) local = hass.config.path('www') if os.path.isdir(local): hass.http.register_static_path("/local", local, not is_dev) index_view = IndexView(repo_path, js_version, client) hass.http.register_view(index_view) async def finalize_panel(panel): """Finalize setup of a panel.""" if hasattr(panel, 'async_finalize'): await panel.async_finalize(hass, repo_path) panel.async_register_index_routes(hass.http.app.router, index_view) yield from asyncio.wait([ async_register_built_in_panel(hass, panel) for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template', 'dev-mqtt', 'kiosk') ], loop=hass.loop) hass.data[DATA_FINALIZE_PANEL] = finalize_panel # Finalize registration of panels that registered before frontend was setup # This includes the built-in panels from line above. yield from asyncio.wait( [finalize_panel(panel) for panel in hass.data[DATA_PANELS].values()], loop=hass.loop) if DATA_EXTRA_HTML_URL not in hass.data: hass.data[DATA_EXTRA_HTML_URL] = set() if DATA_EXTRA_HTML_URL_ES5 not in hass.data: hass.data[DATA_EXTRA_HTML_URL_ES5] = set() for url in conf.get(CONF_EXTRA_HTML_URL, []): add_extra_html_url(hass, url, False) for url in conf.get(CONF_EXTRA_HTML_URL_ES5, []): add_extra_html_url(hass, url, True) async_setup_themes(hass, conf.get(CONF_THEMES)) hass.http.register_view(TranslationsView) return True
def async_setup(hass, config): """Set up the serving of the frontend.""" hass.http.register_view(ManifestJSONView) conf = config.get(DOMAIN, {}) repo_path = conf.get(CONF_FRONTEND_REPO) is_dev = repo_path is not None hass.data[DATA_JS_VERSION] = js_version = conf.get(CONF_JS_VERSION) if is_dev: for subpath in ["src", "build-translations", "build-temp", "build", "hass_frontend", "bower_components", "panels", "hassio"]: hass.http.register_static_path( "/home-assistant-polymer/{}".format(subpath), os.path.join(repo_path, subpath), False) hass.http.register_static_path( "/static/translations", os.path.join(repo_path, "build-translations/output"), False) sw_path_es5 = os.path.join(repo_path, "build-es5/service_worker.js") sw_path_latest = os.path.join(repo_path, "build/service_worker.js") static_path = os.path.join(repo_path, 'hass_frontend') frontend_es5_path = os.path.join(repo_path, 'build-es5') frontend_latest_path = os.path.join(repo_path, 'build') else: import hass_frontend import hass_frontend_es5 sw_path_es5 = os.path.join(hass_frontend_es5.where(), "service_worker.js") sw_path_latest = os.path.join(hass_frontend.where(), "service_worker.js") # /static points to dir with files that are JS-type agnostic. # ES5 files are served from /frontend_es5. # ES6 files are served from /frontend_latest. static_path = hass_frontend.where() frontend_es5_path = hass_frontend_es5.where() frontend_latest_path = static_path hass.http.register_static_path( "/service_worker_es5.js", sw_path_es5, False) hass.http.register_static_path( "/service_worker.js", sw_path_latest, False) hass.http.register_static_path( "/robots.txt", os.path.join(static_path, "robots.txt"), not is_dev) hass.http.register_static_path("/static", static_path, not is_dev) hass.http.register_static_path( "/frontend_latest", frontend_latest_path, not is_dev) hass.http.register_static_path( "/frontend_es5", frontend_es5_path, not is_dev) local = hass.config.path('www') if os.path.isdir(local): hass.http.register_static_path("/local", local, not is_dev) index_view = IndexView(repo_path, js_version) hass.http.register_view(index_view) @asyncio.coroutine def finalize_panel(panel): """Finalize setup of a panel.""" yield from panel.async_finalize(hass, repo_path) panel.async_register_index_routes(hass.http.app.router, index_view) yield from asyncio.wait([ async_register_built_in_panel(hass, panel) for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template', 'dev-mqtt', 'kiosk')], loop=hass.loop) hass.data[DATA_FINALIZE_PANEL] = finalize_panel # Finalize registration of panels that registered before frontend was setup # This includes the built-in panels from line above. yield from asyncio.wait( [finalize_panel(panel) for panel in hass.data[DATA_PANELS].values()], loop=hass.loop) if DATA_EXTRA_HTML_URL not in hass.data: hass.data[DATA_EXTRA_HTML_URL] = set() if DATA_EXTRA_HTML_URL_ES5 not in hass.data: hass.data[DATA_EXTRA_HTML_URL_ES5] = set() for url in conf.get(CONF_EXTRA_HTML_URL, []): add_extra_html_url(hass, url, False) for url in conf.get(CONF_EXTRA_HTML_URL_ES5, []): add_extra_html_url(hass, url, True) async_setup_themes(hass, conf.get(CONF_THEMES)) return True
async def async_setup(hass, config): """Set up the serving of the frontend.""" await async_setup_frontend_storage(hass) hass.components.websocket_api.async_register_command( WS_TYPE_GET_PANELS, websocket_get_panels, SCHEMA_GET_PANELS) hass.components.websocket_api.async_register_command( WS_TYPE_GET_THEMES, websocket_get_themes, SCHEMA_GET_THEMES) hass.components.websocket_api.async_register_command( WS_TYPE_GET_TRANSLATIONS, websocket_get_translations, SCHEMA_GET_TRANSLATIONS) hass.http.register_view(ManifestJSONView) conf = config.get(DOMAIN, {}) repo_path = conf.get(CONF_FRONTEND_REPO) is_dev = repo_path is not None hass.data[DATA_JS_VERSION] = js_version = conf.get(CONF_JS_VERSION) if is_dev: hass_frontend_path = os.path.join(repo_path, 'hass_frontend') hass_frontend_es5_path = os.path.join(repo_path, 'hass_frontend_es5') else: import hass_frontend import hass_frontend_es5 hass_frontend_path = hass_frontend.where() hass_frontend_es5_path = hass_frontend_es5.where() hass.http.register_static_path( "/service_worker_es5.js", os.path.join(hass_frontend_es5_path, "service_worker.js"), False) hass.http.register_static_path( "/service_worker.js", os.path.join(hass_frontend_path, "service_worker.js"), False) hass.http.register_static_path( "/robots.txt", os.path.join(hass_frontend_path, "robots.txt"), False) hass.http.register_static_path("/static", hass_frontend_path, not is_dev) hass.http.register_static_path( "/frontend_latest", hass_frontend_path, not is_dev) hass.http.register_static_path( "/frontend_es5", hass_frontend_es5_path, not is_dev) local = hass.config.path('www') if os.path.isdir(local): hass.http.register_static_path("/local", local, not is_dev) index_view = IndexView(repo_path, js_version) hass.http.register_view(index_view) hass.http.register_view(AuthorizeView(repo_path, js_version)) @callback def async_finalize_panel(panel): """Finalize setup of a panel.""" panel.async_register_index_routes(hass.http.app.router, index_view) await asyncio.wait( [async_register_built_in_panel(hass, panel) for panel in ( 'dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template', 'dev-mqtt', 'kiosk', 'states', 'profile')], loop=hass.loop) hass.data[DATA_FINALIZE_PANEL] = async_finalize_panel # Finalize registration of panels that registered before frontend was setup # This includes the built-in panels from line above. for panel in hass.data[DATA_PANELS].values(): async_finalize_panel(panel) if DATA_EXTRA_HTML_URL not in hass.data: hass.data[DATA_EXTRA_HTML_URL] = set() if DATA_EXTRA_HTML_URL_ES5 not in hass.data: hass.data[DATA_EXTRA_HTML_URL_ES5] = set() for url in conf.get(CONF_EXTRA_HTML_URL, []): add_extra_html_url(hass, url, False) for url in conf.get(CONF_EXTRA_HTML_URL_ES5, []): add_extra_html_url(hass, url, True) _async_setup_themes(hass, conf.get(CONF_THEMES)) return True
def async_setup(hass, config): """Set up the serving of the frontend.""" if list(hass.auth.async_auth_providers): client = yield from hass.auth.async_create_client( 'Home Assistant Frontend', redirect_uris=['/'], no_secret=True, ) else: client = None hass.components.websocket_api.async_register_command( WS_TYPE_GET_PANELS, websocket_handle_get_panels, SCHEMA_GET_PANELS) hass.http.register_view(ManifestJSONView) conf = config.get(DOMAIN, {}) repo_path = conf.get(CONF_FRONTEND_REPO) is_dev = repo_path is not None hass.data[DATA_JS_VERSION] = js_version = conf.get(CONF_JS_VERSION) if is_dev: hass_frontend_path = os.path.join(repo_path, 'hass_frontend') hass_frontend_es5_path = os.path.join(repo_path, 'hass_frontend_es5') else: import hass_frontend import hass_frontend_es5 hass_frontend_path = hass_frontend.where() hass_frontend_es5_path = hass_frontend_es5.where() hass.http.register_static_path( "/service_worker_es5.js", os.path.join(hass_frontend_es5_path, "service_worker.js"), False) hass.http.register_static_path( "/service_worker.js", os.path.join(hass_frontend_path, "service_worker.js"), False) hass.http.register_static_path( "/robots.txt", os.path.join(hass_frontend_path, "robots.txt"), False) hass.http.register_static_path("/static", hass_frontend_path, not is_dev) hass.http.register_static_path( "/frontend_latest", hass_frontend_path, not is_dev) hass.http.register_static_path( "/frontend_es5", hass_frontend_es5_path, not is_dev) local = hass.config.path('www') if os.path.isdir(local): hass.http.register_static_path("/local", local, not is_dev) index_view = IndexView(repo_path, js_version, client) hass.http.register_view(index_view) async def finalize_panel(panel): """Finalize setup of a panel.""" if hasattr(panel, 'async_finalize'): await panel.async_finalize(hass, repo_path) panel.async_register_index_routes(hass.http.app.router, index_view) yield from asyncio.wait([ async_register_built_in_panel(hass, panel) for panel in ('dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template', 'dev-mqtt', 'kiosk')], loop=hass.loop) hass.data[DATA_FINALIZE_PANEL] = finalize_panel # Finalize registration of panels that registered before frontend was setup # This includes the built-in panels from line above. yield from asyncio.wait( [finalize_panel(panel) for panel in hass.data[DATA_PANELS].values()], loop=hass.loop) if DATA_EXTRA_HTML_URL not in hass.data: hass.data[DATA_EXTRA_HTML_URL] = set() if DATA_EXTRA_HTML_URL_ES5 not in hass.data: hass.data[DATA_EXTRA_HTML_URL_ES5] = set() for url in conf.get(CONF_EXTRA_HTML_URL, []): add_extra_html_url(hass, url, False) for url in conf.get(CONF_EXTRA_HTML_URL_ES5, []): add_extra_html_url(hass, url, True) async_setup_themes(hass, conf.get(CONF_THEMES)) hass.http.register_view(TranslationsView) return True