Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 28 additions & 43 deletions homeassistant/components/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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']
Expand Down Expand Up @@ -147,21 +147,6 @@ def async_register_index_routes(self, router, index_view):
'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."""
Expand All @@ -175,30 +160,15 @@ def __init__(self, component_name, sidebar_title, sidebar_icon,
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):
Expand Down Expand Up @@ -244,6 +214,21 @@ def async_finalize(self, hass, frontend_repository_path):
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
Expand Down Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 0 additions & 7 deletions tests/components/test_panel_iframe.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,8 +32,6 @@ def test_wrong_config(self):
'panel_iframe': conf
})

@patch.dict('hass_frontend_es5.FINGERPRINTS',
{'iframe': 'md5md5'})
def test_correct_config(self):
"""Test correct config."""
assert setup.setup_component(
Expand Down Expand Up @@ -70,7 +67,6 @@ def test_correct_config(self):
'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'
}

Expand All @@ -79,7 +75,6 @@ def test_correct_config(self):
'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',
}

Expand All @@ -88,7 +83,6 @@ def test_correct_config(self):
'config': {'url': '/api'},
'icon': 'mdi:weather',
'title': 'Api',
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
'url_path': 'api',
}

Expand All @@ -97,6 +91,5 @@ def test_correct_config(self):
'config': {'url': 'ftp://some/ftp'},
'icon': 'mdi:weather',
'title': 'FTP',
'url': '/frontend_es5/panels/ha-panel-iframe-md5md5.html',
'url_path': 'ftp',
}