Refactoring and cleanup

This commit is contained in:
2022-07-25 22:03:54 +00:00
parent ae916a3900
commit 947735292a
16 changed files with 132 additions and 144 deletions

View File

@@ -9,12 +9,18 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_view(hass):
# Serve the Browser Mod controller and add it as extra_module_url
hass.http.register_static_path(
FRONTEND_SCRIPT_URL,
hass.config.path("custom_components/browser_mod/browser_mod.js"),
)
add_extra_js_url(hass, FRONTEND_SCRIPT_URL)
# Serve the Browser Mod Settings panel and register it as a panel
hass.http.register_static_path(
SETTINGS_PANEL_URL,
hass.config.path("custom_components/browser_mod/browser_mod_panel.js"),
)
hass.components.frontend.async_register_built_in_panel(
component_name="custom",
sidebar_title="Browser Mod",
@@ -28,10 +34,6 @@ async def async_setup_view(hass):
}
},
)
hass.http.register_static_path(
SETTINGS_PANEL_URL,
hass.config.path("custom_components/browser_mod/browser_mod_panel.js"),
)
# Also load Browser Mod as a lovelace resource so it's accessible to Cast
resources = hass.data["lovelace"]["resources"]
@@ -39,14 +41,17 @@ async def async_setup_view(hass):
if not resources.loaded:
await resources.async_load()
resources.loaded = True
frontend_added = False
for r in resources.async_items():
if r["url"].startswith(FRONTEND_SCRIPT_URL):
frontend_added = True
continue
# While going through the resources, also preload card-mod if it is found
if "card-mod.js" in r["url"]:
add_extra_js_url(hass, r["url"])
if not frontend_added:
await resources.async_create_item(
{