2019-08-18 20:39:28 +02:00

54 lines
1.6 KiB
Python

import logging
import homeassistant.components.frontend
from homeassistant.components.frontend import _frontend_root
_LOGGER = logging.getLogger(__name__)
DOMAIN = "favicon"
async def async_setup(hass, config):
favicon = config[DOMAIN].get('favicon')
apple = config[DOMAIN].get('apple')
title = config[DOMAIN].get('title')
if favicon or apple or title:
get_template = homeassistant.components.frontend.IndexView.get_template
def new_get_template(self):
tpl = get_template(self)
render = tpl.render
def new_render(*args, **kwargs):
text = render(*args, **kwargs)
if favicon:
text = text.replace("/static/icons/favicon.ico", favicon)
if apple:
text = text.replace("/static/icons/favicon-apple-180x180.png", apple)
if title:
text = text.replace("<title>Home Assistant</title>", f"<title>{title}</title>")
return text
tpl.render = new_render
return tpl
homeassistant.components.frontend.IndexView.get_template = new_get_template
icons = []
for size in config[DOMAIN]:
if not isinstance(size, int):
continue
i = config[DOMAIN].get(size)
if i:
icons.append({
"src": i,
"sizes": f"{size}x{size}",
"type": "image/png",
})
if icons:
homeassistant.components.frontend.MANIFEST_JSON["icons"] = icons
return True