Skip to content

Commit

Permalink
Various fixes. Fix #9. Fix #10. Fix #11. Fix #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed May 1, 2020
1 parent 8e448f5 commit 0b6afed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
44 changes: 27 additions & 17 deletions custom_components/favicon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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);
</script>
""")

Expand Down
6 changes: 3 additions & 3 deletions custom_components/favicon/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 0b6afed

Please sign in to comment.