Skip to content

Commit

Permalink
Use what home assistant provides instead of reinventing wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Jan 23, 2021
1 parent 6b3e6da commit 5b3ea45
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 46 deletions.
24 changes: 14 additions & 10 deletions custom_components/fontawesome/__init__.py
Original file line number Diff line number Diff line change
@@ -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():

This comment has been minimized.

Copy link
@bramkragten

bramkragten Jan 23, 2021

No need to do this for every file, just once for the folder.

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
Expand All @@ -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)
if k in modules and modules[k] is not False:
url_set.add(ICONS_URL+v)
4 changes: 3 additions & 1 deletion custom_components/fontawesome/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -44,4 +46,4 @@ async def async_step_init(self, user_input=None):
): bool,
}
)
)
)
34 changes: 0 additions & 34 deletions custom_components/fontawesome/custom_component_server.py

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fontawesome",
"private": true,
"version": "1.3.0",
"version": "1.3.1",
"description": "",
"scripts": {
"build": "webpack",
Expand Down

0 comments on commit 5b3ea45

Please sign in to comment.