diff --git a/custom_components/fontawesome/__init__.py b/custom_components/fontawesome/__init__.py index 7534066..0eb7576 100644 --- a/custom_components/fontawesome/__init__.py +++ b/custom_components/fontawesome/__init__.py @@ -1,35 +1,39 @@ -import homeassistant.components.frontend -from homeassistant.components.frontend import _frontend_root - -from .custom_component_server import setup_view - DOMAIN = "fontawesome" DATA_EXTRA_MODULE_URL = 'frontend_extra_module_url' -ICONS_URL = '/'+DOMAIN+'/data/' +ICONS_URL = f'/{DOMAIN}/' ICON_FILES = { 'regular': 'far.js', 'solid': 'fas.js', 'brands': 'fab.js', } + async def async_setup(hass, config): - setup_view(hass, DOMAIN) + for f in ICON_FILES.values(): + hass.http.register_static_path( + f"/{DOMAIN}/{f}", + hass.config.path(f"custom_components/{DOMAIN}/data/{f}"), + True + ) conf = config.get(DOMAIN) if not conf: return True register_modules(hass, conf) return True + async def async_setup_entry(hass, config_entry): config_entry.add_update_listener(_update_listener) register_modules(hass, config_entry.options) return True + async def async_remove_entry(hass, config_entry): register_modules(hass, []) return True + async def _update_listener(hass, config_entry): register_modules(hass, config_entry.options) return True @@ -40,7 +44,7 @@ def register_modules(hass, modules): hass.data[DATA_EXTRA_MODULE_URL] = set() url_set = hass.data[DATA_EXTRA_MODULE_URL] - for k,v in ICON_FILES.items(): + for k, v in ICON_FILES.items(): url_set.discard(ICONS_URL+v) - if k in modules and modules[k] != False: - url_set.add(ICONS_URL+v) \ No newline at end of file + if k in modules and modules[k] is not False: + url_set.add(ICONS_URL+v) diff --git a/custom_components/fontawesome/config_flow.py b/custom_components/fontawesome/config_flow.py index e2bf5ac..0e5380b 100644 --- a/custom_components/fontawesome/config_flow.py +++ b/custom_components/fontawesome/config_flow.py @@ -6,6 +6,7 @@ _LOGGER = logging.getLogger(__name__) + @config_entries.HANDLERS.register("fontawesome") class FontawesomeConfigFlow(config_entries.ConfigFlow): async def async_step_user(self, user_input=None): @@ -18,6 +19,7 @@ async def async_step_user(self, user_input=None): def async_get_options_flow(config_entry): return FontawesomeEditFlow(config_entry) + class FontawesomeEditFlow(config_entries.OptionsFlow): def __init__(self, config_entry): self.config_entry = config_entry @@ -44,4 +46,4 @@ async def async_step_init(self, user_input=None): ): bool, } ) - ) \ No newline at end of file + ) diff --git a/custom_components/fontawesome/custom_component_server.py b/custom_components/fontawesome/custom_component_server.py deleted file mode 100644 index ed7f84e..0000000 --- a/custom_components/fontawesome/custom_component_server.py +++ /dev/null @@ -1,34 +0,0 @@ -from aiohttp import web -from homeassistant.components.http import HomeAssistantView -import os.path -from homeassistant.util import sanitize_path - - -def setup_view(hass, name): - hass.http.register_view(CustomComponentServer(hass, name)) - - -class CustomComponentServer(HomeAssistantView): - - requires_auth = False - - def __init__(self, hass, domain): - self.name = domain+"_server" - self.url = '/'+domain+'/{filename:.*}' - self.config_dir = hass.config.path() - self.domain = domain - - async def get(self, request, filename): - - filename = sanitize_path(filename) - path = os.path.join(self.config_dir, 'custom_components', self.domain, filename) - filecontent = "" - - try: - with open(path, mode="r", encoding="utf-8", errors="ignore") as localfile: - filecontent = localfile.read() - localfile.close() - except Exception: - return web.Response(status=404) - - return web.Response(body=filecontent, content_type="text/javascript", charset="utf-8") diff --git a/package.json b/package.json index 379e1b1..cdee6e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fontawesome", "private": true, - "version": "1.3.0", + "version": "1.3.1", "description": "", "scripts": { "build": "webpack",