Don't add a url to built-in panels (#14456)
* Don't add a url to built-in panels * Add url_path back * Lint * Frontend bump to 20180515.0 * Fix tests
This commit is contained in:
parent
2e7b5dcd19
commit
df69680d24
5 changed files with 31 additions and 53 deletions
|
@ -25,7 +25,7 @@ from homeassistant.core import callback
|
|||
from homeassistant.helpers.translation import async_get_translations
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
REQUIREMENTS = ['home-assistant-frontend==20180510.1']
|
||||
REQUIREMENTS = ['home-assistant-frontend==20180515.0']
|
||||
|
||||
DOMAIN = 'frontend'
|
||||
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log']
|
||||
|
@ -147,21 +147,6 @@ class AbstractPanel:
|
|||
'get', '/{}/{{extra:.+}}'.format(self.frontend_url_path),
|
||||
index_view.get)
|
||||
|
||||
def to_response(self, hass, request):
|
||||
"""Panel as dictionary."""
|
||||
result = {
|
||||
'component_name': self.component_name,
|
||||
'icon': self.sidebar_icon,
|
||||
'title': self.sidebar_title,
|
||||
'url_path': self.frontend_url_path,
|
||||
'config': self.config,
|
||||
}
|
||||
if _is_latest(hass.data[DATA_JS_VERSION], request):
|
||||
result['url'] = self.webcomponent_url_latest
|
||||
else:
|
||||
result['url'] = self.webcomponent_url_es5
|
||||
return result
|
||||
|
||||
|
||||
class BuiltInPanel(AbstractPanel):
|
||||
"""Panel that is part of hass_frontend."""
|
||||
|
@ -175,30 +160,15 @@ class BuiltInPanel(AbstractPanel):
|
|||
self.frontend_url_path = frontend_url_path or component_name
|
||||
self.config = config
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_finalize(self, hass, frontend_repository_path):
|
||||
"""Finalize this panel for usage.
|
||||
|
||||
If frontend_repository_path is set, will be prepended to path of
|
||||
built-in components.
|
||||
"""
|
||||
if frontend_repository_path is None:
|
||||
import hass_frontend
|
||||
import hass_frontend_es5
|
||||
|
||||
self.webcomponent_url_latest = \
|
||||
'/frontend_latest/panels/ha-panel-{}-{}.html'.format(
|
||||
self.component_name,
|
||||
hass_frontend.FINGERPRINTS[self.component_name])
|
||||
self.webcomponent_url_es5 = \
|
||||
'/frontend_es5/panels/ha-panel-{}-{}.html'.format(
|
||||
self.component_name,
|
||||
hass_frontend_es5.FINGERPRINTS[self.component_name])
|
||||
else:
|
||||
# Dev mode
|
||||
self.webcomponent_url_es5 = self.webcomponent_url_latest = \
|
||||
'/home-assistant-polymer/panels/{}/ha-panel-{}.html'.format(
|
||||
self.component_name, self.component_name)
|
||||
def to_response(self, hass, request):
|
||||
"""Panel as dictionary."""
|
||||
return {
|
||||
'component_name': self.component_name,
|
||||
'icon': self.sidebar_icon,
|
||||
'title': self.sidebar_title,
|
||||
'config': self.config,
|
||||
'url_path': self.frontend_url_path,
|
||||
}
|
||||
|
||||
|
||||
class ExternalPanel(AbstractPanel):
|
||||
|
@ -244,6 +214,21 @@ class ExternalPanel(AbstractPanel):
|
|||
frontend_repository_path is None)
|
||||
self.REGISTERED_COMPONENTS.add(self.component_name)
|
||||
|
||||
def to_response(self, hass, request):
|
||||
"""Panel as dictionary."""
|
||||
result = {
|
||||
'component_name': self.component_name,
|
||||
'icon': self.sidebar_icon,
|
||||
'title': self.sidebar_title,
|
||||
'url_path': self.frontend_url_path,
|
||||
'config': self.config,
|
||||
}
|
||||
if _is_latest(hass.data[DATA_JS_VERSION], request):
|
||||
result['url'] = self.webcomponent_url_latest
|
||||
else:
|
||||
result['url'] = self.webcomponent_url_es5
|
||||
return result
|
||||
|
||||
|
||||
@bind_hass
|
||||
@asyncio.coroutine
|
||||
|
@ -365,10 +350,10 @@ def async_setup(hass, config):
|
|||
index_view = IndexView(repo_path, js_version, client)
|
||||
hass.http.register_view(index_view)
|
||||
|
||||
@asyncio.coroutine
|
||||
def finalize_panel(panel):
|
||||
async def finalize_panel(panel):
|
||||
"""Finalize setup of a panel."""
|
||||
yield from panel.async_finalize(hass, repo_path)
|
||||
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([
|
||||
|
|
|
@ -386,7 +386,7 @@ hipnotify==1.0.8
|
|||
holidays==0.9.5
|
||||
|
||||
# homeassistant.components.frontend
|
||||
home-assistant-frontend==20180510.1
|
||||
home-assistant-frontend==20180515.0
|
||||
|
||||
# homeassistant.components.homekit_controller
|
||||
# homekit==0.6
|
||||
|
|
|
@ -81,7 +81,7 @@ hbmqtt==0.9.2
|
|||
holidays==0.9.5
|
||||
|
||||
# homeassistant.components.frontend
|
||||
home-assistant-frontend==20180510.1
|
||||
home-assistant-frontend==20180515.0
|
||||
|
||||
# homeassistant.components.influxdb
|
||||
# homeassistant.components.sensor.influxdb
|
||||
|
|
|
@ -57,7 +57,7 @@ def test_frontend_and_static(mock_http_client):
|
|||
|
||||
# Test we can retrieve frontend.js
|
||||
frontendjs = re.search(
|
||||
r'(?P<app>\/frontend_es5\/frontend-[A-Za-z0-9]{32}.html)', text)
|
||||
r'(?P<app>\/frontend_es5\/app-[A-Za-z0-9]{32}.js)', text)
|
||||
|
||||
assert frontendjs is not None
|
||||
resp = yield from mock_http_client.get(frontendjs.groups(0)[0])
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""The tests for the panel_iframe component."""
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import setup
|
||||
from homeassistant.components import frontend
|
||||
|
@ -33,8 +32,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||
'panel_iframe': conf
|
||||
})
|
||||
|
||||
@patch.dict('hass_frontend_es5.FINGERPRINTS',
|
||||
{'iframe': 'md5md5'})
|
||||
def test_correct_config(self):
|
||||
"""Test correct config."""
|
||||
assert setup.setup_component(
|
||||
|
@ -70,7 +67,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||
'config': {'url': 'http://192.168.1.1'},
|
||||
'icon': 'mdi:network-wireless',
|
||||
'title': 'Router',
|
||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
||||
'url_path': 'router'
|
||||
}
|
||||
|
||||
|
@ -79,7 +75,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||
'config': {'url': 'https://www.wunderground.com/us/ca/san-diego'},
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'Weather',
|
||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
||||
'url_path': 'weather',
|
||||
}
|
||||
|
||||
|
@ -88,7 +83,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||
'config': {'url': '/api'},
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'Api',
|
||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
||||
'url_path': 'api',
|
||||
}
|
||||
|
||||
|
@ -97,6 +91,5 @@ class TestPanelIframe(unittest.TestCase):
|
|||
'config': {'url': 'ftp://some/ftp'},
|
||||
'icon': 'mdi:weather',
|
||||
'title': 'FTP',
|
||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
||||
'url_path': 'ftp',
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue