mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
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
@ -25,7 +25,7 @@ from homeassistant.core import callback
|
|||||||
from homeassistant.helpers.translation import async_get_translations
|
from homeassistant.helpers.translation import async_get_translations
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
|
|
||||||
REQUIREMENTS = ['home-assistant-frontend==20180510.1']
|
REQUIREMENTS = ['home-assistant-frontend==20180515.0']
|
||||||
|
|
||||||
DOMAIN = 'frontend'
|
DOMAIN = 'frontend'
|
||||||
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log']
|
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log']
|
||||||
@ -147,21 +147,6 @@ class AbstractPanel:
|
|||||||
'get', '/{}/{{extra:.+}}'.format(self.frontend_url_path),
|
'get', '/{}/{{extra:.+}}'.format(self.frontend_url_path),
|
||||||
index_view.get)
|
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):
|
class BuiltInPanel(AbstractPanel):
|
||||||
"""Panel that is part of hass_frontend."""
|
"""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.frontend_url_path = frontend_url_path or component_name
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
@asyncio.coroutine
|
def to_response(self, hass, request):
|
||||||
def async_finalize(self, hass, frontend_repository_path):
|
"""Panel as dictionary."""
|
||||||
"""Finalize this panel for usage.
|
return {
|
||||||
|
'component_name': self.component_name,
|
||||||
If frontend_repository_path is set, will be prepended to path of
|
'icon': self.sidebar_icon,
|
||||||
built-in components.
|
'title': self.sidebar_title,
|
||||||
"""
|
'config': self.config,
|
||||||
if frontend_repository_path is None:
|
'url_path': self.frontend_url_path,
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class ExternalPanel(AbstractPanel):
|
class ExternalPanel(AbstractPanel):
|
||||||
@ -244,6 +214,21 @@ class ExternalPanel(AbstractPanel):
|
|||||||
frontend_repository_path is None)
|
frontend_repository_path is None)
|
||||||
self.REGISTERED_COMPONENTS.add(self.component_name)
|
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
|
@bind_hass
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -365,10 +350,10 @@ def async_setup(hass, config):
|
|||||||
index_view = IndexView(repo_path, js_version, client)
|
index_view = IndexView(repo_path, js_version, client)
|
||||||
hass.http.register_view(index_view)
|
hass.http.register_view(index_view)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def finalize_panel(panel):
|
||||||
def finalize_panel(panel):
|
|
||||||
"""Finalize setup of a 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)
|
panel.async_register_index_routes(hass.http.app.router, index_view)
|
||||||
|
|
||||||
yield from asyncio.wait([
|
yield from asyncio.wait([
|
||||||
|
@ -386,7 +386,7 @@ hipnotify==1.0.8
|
|||||||
holidays==0.9.5
|
holidays==0.9.5
|
||||||
|
|
||||||
# homeassistant.components.frontend
|
# homeassistant.components.frontend
|
||||||
home-assistant-frontend==20180510.1
|
home-assistant-frontend==20180515.0
|
||||||
|
|
||||||
# homeassistant.components.homekit_controller
|
# homeassistant.components.homekit_controller
|
||||||
# homekit==0.6
|
# homekit==0.6
|
||||||
|
@ -81,7 +81,7 @@ hbmqtt==0.9.2
|
|||||||
holidays==0.9.5
|
holidays==0.9.5
|
||||||
|
|
||||||
# homeassistant.components.frontend
|
# homeassistant.components.frontend
|
||||||
home-assistant-frontend==20180510.1
|
home-assistant-frontend==20180515.0
|
||||||
|
|
||||||
# homeassistant.components.influxdb
|
# homeassistant.components.influxdb
|
||||||
# homeassistant.components.sensor.influxdb
|
# homeassistant.components.sensor.influxdb
|
||||||
|
@ -57,7 +57,7 @@ def test_frontend_and_static(mock_http_client):
|
|||||||
|
|
||||||
# Test we can retrieve frontend.js
|
# Test we can retrieve frontend.js
|
||||||
frontendjs = re.search(
|
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
|
assert frontendjs is not None
|
||||||
resp = yield from mock_http_client.get(frontendjs.groups(0)[0])
|
resp = yield from mock_http_client.get(frontendjs.groups(0)[0])
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""The tests for the panel_iframe component."""
|
"""The tests for the panel_iframe component."""
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from homeassistant import setup
|
from homeassistant import setup
|
||||||
from homeassistant.components import frontend
|
from homeassistant.components import frontend
|
||||||
@ -33,8 +32,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||||||
'panel_iframe': conf
|
'panel_iframe': conf
|
||||||
})
|
})
|
||||||
|
|
||||||
@patch.dict('hass_frontend_es5.FINGERPRINTS',
|
|
||||||
{'iframe': 'md5md5'})
|
|
||||||
def test_correct_config(self):
|
def test_correct_config(self):
|
||||||
"""Test correct config."""
|
"""Test correct config."""
|
||||||
assert setup.setup_component(
|
assert setup.setup_component(
|
||||||
@ -70,7 +67,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||||||
'config': {'url': 'http://192.168.1.1'},
|
'config': {'url': 'http://192.168.1.1'},
|
||||||
'icon': 'mdi:network-wireless',
|
'icon': 'mdi:network-wireless',
|
||||||
'title': 'Router',
|
'title': 'Router',
|
||||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
|
||||||
'url_path': 'router'
|
'url_path': 'router'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +75,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||||||
'config': {'url': 'https://www.wunderground.com/us/ca/san-diego'},
|
'config': {'url': 'https://www.wunderground.com/us/ca/san-diego'},
|
||||||
'icon': 'mdi:weather',
|
'icon': 'mdi:weather',
|
||||||
'title': 'Weather',
|
'title': 'Weather',
|
||||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
|
||||||
'url_path': 'weather',
|
'url_path': 'weather',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +83,6 @@ class TestPanelIframe(unittest.TestCase):
|
|||||||
'config': {'url': '/api'},
|
'config': {'url': '/api'},
|
||||||
'icon': 'mdi:weather',
|
'icon': 'mdi:weather',
|
||||||
'title': 'Api',
|
'title': 'Api',
|
||||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
|
||||||
'url_path': 'api',
|
'url_path': 'api',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +91,5 @@ class TestPanelIframe(unittest.TestCase):
|
|||||||
'config': {'url': 'ftp://some/ftp'},
|
'config': {'url': 'ftp://some/ftp'},
|
||||||
'icon': 'mdi:weather',
|
'icon': 'mdi:weather',
|
||||||
'title': 'FTP',
|
'title': 'FTP',
|
||||||
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
|
|
||||||
'url_path': 'ftp',
|
'url_path': 'ftp',
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user