Skip to content

Commit

Permalink
Consolidate frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Oct 21, 2017
1 parent 2ab14bb commit bd171c1
Show file tree
Hide file tree
Showing 148 changed files with 50 additions and 4,983 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,3 +1,3 @@
[submodule "homeassistant/components/frontend/www_static/home-assistant-polymer"]
path = homeassistant/components/frontend/www_static/home-assistant-polymer
path = homeassistant/components/frontend/home-assistant-polymer
url = https://github.com/home-assistant/home-assistant-polymer.git
3 changes: 2 additions & 1 deletion MANIFEST.in
@@ -1,5 +1,6 @@
include README.rst
include LICENSE.md
graft homeassistant
prune homeassistant/components/frontend/www_static/home-assistant-polymer
prune homeassistant/components/frontend/home-assistant-polymer
graft homeassistant/components/frontend/home-assistant-polymer/final
recursive-exclude * *.py[co]
78 changes: 35 additions & 43 deletions homeassistant/components/frontend/__init__.py
Expand Up @@ -13,7 +13,6 @@
from homeassistant.const import CONF_NAME, EVENT_THEMES_UPDATED
from homeassistant.core import callback
from homeassistant.loader import bind_hass
from homeassistant.components import api
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.auth import is_trusted_ip
from homeassistant.components.http.const import KEY_DEVELOPMENT
Expand All @@ -25,7 +24,9 @@
URL_PANEL_COMPONENT = '/frontend/panels/{}.html'
URL_PANEL_COMPONENT_FP = '/frontend/panels/{}-{}.html'

STATIC_PATH = os.path.join(os.path.dirname(__file__), 'www_static/')
POLYMER_PATH = os.path.join(os.path.dirname(__file__),
'home-assistant-polymer/')
FINAL_PATH = os.path.join(POLYMER_PATH, 'final')

ATTR_THEMES = 'themes'
ATTR_EXTRA_HTML_URL = 'extra_html_url'
Expand Down Expand Up @@ -87,18 +88,24 @@ def register_built_in_panel(hass, component_name, sidebar_title=None,
nondev_path = 'panels/ha-panel-{}.html'.format(component_name)

if hass.http.development:
url = ('/static/home-assistant-polymer/panels/'
url = ('/home-assistant-polymer/panels/'
'{0}/ha-panel-{0}.html'.format(component_name))
path = os.path.join(
STATIC_PATH, 'home-assistant-polymer/panels/',
'{0}/ha-panel-{0}.html'.format(component_name))
POLYMER_PATH,
'panels/{0}/ha-panel-{0}.html'.format(component_name))
fingerprint = None
else:
url = None # use default url generate mechanism
path = os.path.join(STATIC_PATH, nondev_path)
path = os.path.join(FINAL_PATH, nondev_path)
fingerprint = FINGERPRINTS.get(nondev_path)

# Fingerprint doesn't exist when adding new built-in panel
register_panel(hass, component_name, path,
FINGERPRINTS.get(nondev_path, 'dev'), sidebar_title,
if nondev_path not in FINGERPRINTS:
_LOGGER.warning('Unable to find fingerprint for %s.', nondev_path)
fingerprint = _fingerprint(path)

url = '/static/panels/ha-panel-{}-{}.html'.format(
component_name, fingerprint)

register_panel(hass, component_name, path, fingerprint, sidebar_title,
sidebar_icon, url_path, url, config)


Expand All @@ -110,7 +117,7 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
component_name: name of the web component
path: path to the HTML of the web component
(required unless url is provided)
md5: the md5 hash of the web component (for versioning, optional)
md5: the md5 hash of the web component (for versioning in url, optional)
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)
Expand All @@ -134,8 +141,7 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None,
return

if md5 is None:
with open(path) as fil:
md5 = hashlib.md5(fil.read().encode('utf-8')).hexdigest()
md5 = _fingerprint(path)

data = {
'url_path': url_path,
Expand Down Expand Up @@ -190,19 +196,19 @@ def add_manifest_json_key(key, val):

def setup(hass, config):
"""Set up the serving of the frontend."""
hass.http.register_view(BootstrapView)
hass.http.register_view(ManifestJSONView)

if hass.http.development:
sw_path = "home-assistant-polymer/build/service_worker.js"
sw_path = os.path.join(POLYMER_PATH, "build/service_worker.js")
else:
sw_path = "service_worker.js"
sw_path = os.path.join(FINAL_PATH, "service_worker.js")

hass.http.register_static_path("/service_worker.js",
os.path.join(STATIC_PATH, sw_path), False)
hass.http.register_static_path("/service_worker.js", sw_path, False)
hass.http.register_static_path("/robots.txt",
os.path.join(STATIC_PATH, "robots.txt"))
hass.http.register_static_path("/static", STATIC_PATH)
os.path.join(FINAL_PATH, "robots.txt"))
hass.http.register_static_path("/static", FINAL_PATH)
if hass.http.development:
hass.http.register_static_path("/home-assistant-polymer", POLYMER_PATH)

local = hass.config.path('www')
if os.path.isdir(local):
Expand Down Expand Up @@ -294,26 +300,6 @@ def reload_themes(_):
descriptions[SERVICE_RELOAD_THEMES])


class BootstrapView(HomeAssistantView):
"""View to bootstrap frontend with all needed data."""

url = '/api/bootstrap'
name = 'api:bootstrap'

@callback
def get(self, request):
"""Return all data needed to bootstrap Home Assistant."""
hass = request.app['hass']

return self.json({
'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],
})


class IndexView(HomeAssistantView):
"""Serve the frontend."""

Expand All @@ -339,10 +325,10 @@ def get(self, request, extra=None):
hass = request.app['hass']

if request.app[KEY_DEVELOPMENT]:
core_url = '/static/home-assistant-polymer/build/core.js'
core_url = '/home-assistant-polymer/build/core.js'
compatibility_url = \
'/static/home-assistant-polymer/build/compatibility.js'
ui_url = '/static/home-assistant-polymer/src/home-assistant.html'
'/home-assistant-polymer/build/compatibility.js'
ui_url = '/home-assistant-polymer/src/home-assistant.html'
else:
core_url = '/static/core-{}.js'.format(
FINGERPRINTS['core.js'])
Expand Down Expand Up @@ -418,3 +404,9 @@ def get(self, request):
'themes': hass.data[DATA_THEMES],
'default_theme': hass.data[DATA_DEFAULT_THEME],
})


def _fingerprint(path):
"""Fingerprint a file."""
with open(path) as fil:
return hashlib.md5(fil.read().encode('utf-8')).hexdigest()
1 change: 1 addition & 0 deletions homeassistant/components/frontend/home-assistant-polymer
Submodule home-assistant-polymer added at 81ca0b
10 changes: 5 additions & 5 deletions homeassistant/components/frontend/version.py
Expand Up @@ -3,22 +3,22 @@
FINGERPRINTS = {
"compatibility.js": "1686167ff210e001f063f5c606b2e74b",
"core.js": "2a7d01e45187c7d4635da05065b5e54e",
"frontend.html": "2de1bde3b4a6c6c47dd95504fc098906",
"frontend.html": "ee71dcb43046ca2423e8bddc58c7bb4c",
"mdi.html": "2e848b4da029bf73d426d5ba058a088d",
"micromarkdown-js.html": "93b5ec4016f0bba585521cf4d18dec1a",
"panels/ha-panel-config.html": "52e2e1d477bfd6dc3708d65b8337f0af",
"panels/ha-panel-config.html": "16c63f34358c45e5a62b7b5510a03ce0",
"panels/ha-panel-dev-event.html": "d409e7ab537d9fe629126d122345279c",
"panels/ha-panel-dev-info.html": "b0e55eb657fd75f21aba2426ac0cedc0",
"panels/ha-panel-dev-info.html": "45a7d59eccc68fffdece16feaaccc0fb",
"panels/ha-panel-dev-mqtt.html": "94b222b013a98583842de3e72d5888c6",
"panels/ha-panel-dev-service.html": "422b2c181ee0713fa31d45a64e605baf",
"panels/ha-panel-dev-state.html": "7948d3dba058f31517d880df8ed0e857",
"panels/ha-panel-dev-template.html": "928e7b81b9c113b70edc9f4a1d051827",
"panels/ha-panel-dev-template.html": "dc4b19f63a2053197d71a9fb736313f2",
"panels/ha-panel-hassio.html": "b46e7619f3c355f872d5370741d89f6a",
"panels/ha-panel-history.html": "fe2daac10a14f51fa3eb7d23978df1f7",
"panels/ha-panel-iframe.html": "56930204d6e067a3d600cf030f4b34c8",
"panels/ha-panel-kiosk.html": "b40aa5cb52dd7675bea744afcf9eebf8",
"panels/ha-panel-logbook.html": "771afdcf48dc7e308b0282417d2e02d8",
"panels/ha-panel-mailbox.html": "a8cca44ca36553e91565e3c894ea6323",
"panels/ha-panel-map.html": "565db019147162080c21af962afc097f",
"panels/ha-panel-map.html": "e7c3bc6068e0285c2767ba494471cc06",
"panels/ha-panel-shopping-list.html": "d8cfd0ecdb3aa6214c0f6908c34c7141"
}

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion homeassistant/components/frontend/www_static/core.js

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

0 comments on commit bd171c1

Please sign in to comment.