Star working on a config panel
This commit is contained in:
158
custom_components/browser_mod/browser_mod_panel.js
Normal file
158
custom_components/browser_mod/browser_mod_panel.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
||||
DOMAIN = "browser_mod"
|
||||
|
||||
FRONTEND_SCRIPT_URL = "/browser_mod.js"
|
||||
SETTINGS_PANEL_URL = "/browser_mod_panel.js"
|
||||
|
||||
DATA_EXTRA_MODULE_URL = "frontend_extra_module_url"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "browser_mod",
|
||||
"name": "Browser mod",
|
||||
"documentation": "https://github.com/thomasloven/hass-browser_mod/blob/master/README.md",
|
||||
"dependencies": ["websocket_api", "http", "frontend"],
|
||||
"dependencies": ["panel_custom", "websocket_api", "http", "frontend"],
|
||||
"codeowners": [],
|
||||
"requirements": [],
|
||||
"version": "1.5.3",
|
||||
|
||||
@@ -1,37 +1,29 @@
|
||||
from aiohttp import web
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
|
||||
from .const import FRONTEND_SCRIPT_URL, DATA_EXTRA_MODULE_URL
|
||||
from .const import FRONTEND_SCRIPT_URL, DATA_EXTRA_MODULE_URL, SETTINGS_PANEL_URL
|
||||
|
||||
|
||||
def setup_view(hass):
|
||||
url_set = hass.data[DATA_EXTRA_MODULE_URL]
|
||||
url_set.add(FRONTEND_SCRIPT_URL)
|
||||
|
||||
hass.http.register_view(ModView(hass, FRONTEND_SCRIPT_URL))
|
||||
hass.components.frontend.async_register_built_in_panel(
|
||||
component_name="custom",
|
||||
sidebar_title="Browser Mod",
|
||||
sidebar_icon="mdi:server",
|
||||
frontend_url_path="browser-mod",
|
||||
require_admin=True,
|
||||
config={
|
||||
"_panel_custom": {
|
||||
"name": "browser-mod-panel",
|
||||
"js_url": SETTINGS_PANEL_URL,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class ModView(HomeAssistantView):
|
||||
|
||||
name = "browser_mod_script"
|
||||
requires_auth = False
|
||||
|
||||
def __init__(self, hass, url):
|
||||
self.url = url
|
||||
self.config_dir = hass.config.path()
|
||||
|
||||
async def get(self, request):
|
||||
path = "{}/custom_components/browser_mod/browser_mod.js".format(self.config_dir)
|
||||
|
||||
filecontent = ""
|
||||
|
||||
try:
|
||||
with open(path, mode="r", encoding="utf-8", errors="ignore") as localfile:
|
||||
filecontent = localfile.read()
|
||||
localfile.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return web.Response(
|
||||
body=filecontent, content_type="text/javascript", charset="utf-8"
|
||||
)
|
||||
hass.http.register_static_path(
|
||||
FRONTEND_SCRIPT_URL,
|
||||
hass.config.path("custom_components/browser_mod/browser_mod.js"),
|
||||
)
|
||||
hass.http.register_static_path(
|
||||
SETTINGS_PANEL_URL,
|
||||
hass.config.path("custom_components/browser_mod/browser_mod_panel.js"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user