From 0b6afed654d2390b491afc3da0c8a3fd36fb8a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Fri, 1 May 2020 20:32:30 +0200 Subject: [PATCH] Various fixes. Fix #9. Fix #10. Fix #11. Fix #12. --- custom_components/favicon/__init__.py | 44 ++++++++++++------- custom_components/favicon/config_flow.py | 6 +-- .../{.translations => translations}/en.json | 0 3 files changed, 30 insertions(+), 20 deletions(-) rename custom_components/favicon/{.translations => translations}/en.json (100%) diff --git a/custom_components/favicon/__init__.py b/custom_components/favicon/__init__.py index 49b0101..f849877 100644 --- a/custom_components/favicon/__init__.py +++ b/custom_components/favicon/__init__.py @@ -37,7 +37,8 @@ async def async_setup(hass, config): async def async_setup_entry(hass, config_entry): config_entry.add_update_listener(_update_listener) - config_entry.options = config_entry.data + if not config_entry.options: + config_entry.options = config_entry.data return await _update_listener(hass, config_entry) async def async_remove_entry(hass, config_entry): @@ -63,22 +64,25 @@ def find_icons(hass, path): localpath = "www" + path[len("/local"):] localpath = hass.config.path(localpath) _LOGGER.info("Looking for icons in: %s", localpath) - for fn in os.listdir(localpath): - if fn == "favicon.ico": - icons["favicon"] = os.path.join(path, fn) - _LOGGER.info("Found favicon: %s", os.path.join(path, fn)) - apple = re.search(RE_APPLE, fn) - if apple: - icons["apple"] = os.path.join(path, fn) - _LOGGER.info("Found apple icon: %s", os.path.join(path, fn)) - icon = re.search(RE_ICON, fn) - if icon: - manifest.append({ - "src": os.path.join(path, fn), - "sizes": icon.group(1), - "type": "image/png", - }) - _LOGGER.info("Found icon: %s", os.path.join(path, fn)) + try: + for fn in os.listdir(localpath): + if fn == "favicon.ico": + icons["favicon"] = os.path.join(path, fn) + _LOGGER.info("Found favicon: %s", os.path.join(path, fn)) + apple = re.search(RE_APPLE, fn) + if apple: + icons["apple"] = os.path.join(path, fn) + _LOGGER.info("Found apple icon: %s", os.path.join(path, fn)) + icon = re.search(RE_ICON, fn) + if icon: + manifest.append({ + "src": os.path.join(path, fn), + "sizes": icon.group(1), + "type": "image/png", + }) + _LOGGER.info("Found icon: %s", os.path.join(path, fn)) + except: + pass if manifest: icons["manifest"] = manifest @@ -111,6 +115,12 @@ def new_render(*args, **kwargs): this.shadowRoot.querySelector(".menu .title").innerHTML = "{title}"; }} }}); + + window.setInterval(() => {{ + if(!document.title.endsWith("- {title}") && document.title !== "{title}") {{ + document.title = document.title.replace(/Home Assistant/, "{title}"); + }} + }}, 1000); """) diff --git a/custom_components/favicon/config_flow.py b/custom_components/favicon/config_flow.py index c863d37..20d448b 100644 --- a/custom_components/favicon/config_flow.py +++ b/custom_components/favicon/config_flow.py @@ -7,7 +7,7 @@ _LOGGER = logging.getLogger(__name__) @config_entries.HANDLERS.register("favicon") -class ExampleConfigFlow(config_entries.ConfigFlow): +class ConfigFlow(config_entries.ConfigFlow): async def async_step_user(self, user_input=None): if self._async_current_entries(): return self.async_abort(reason="single_instance_allowed") @@ -31,9 +31,9 @@ async def async_step_config(self, user_input=None): @staticmethod @callback def async_get_options_flow(config_entry): - return ExampleEditFlow(config_entry) + return EditFlow(config_entry) -class ExampleEditFlow(config_entries.OptionsFlow): +class EditFlow(config_entries.OptionsFlow): def __init__(self, config_entry): self.config_entry = config_entry diff --git a/custom_components/favicon/.translations/en.json b/custom_components/favicon/translations/en.json similarity index 100% rename from custom_components/favicon/.translations/en.json rename to custom_components/favicon/translations/en.json