Complete overhaul

This commit is contained in:
2019-11-15 00:07:04 +01:00
parent de4bbf9700
commit 201a1466de
23 changed files with 4394 additions and 1563 deletions

View File

@@ -0,0 +1,21 @@
{
"config": {
"title": "FontAwesome",
"abort": {
"single_instance_allowed": "Only a single configuration of FontAwesome is allowed."
}
},
"options": {
"step": {
"init": {
"title": "Icon sets",
"description": "Which icon sets to include",
"data": {
"regular": "Include Regular icons (far:)",
"solid": "Include Solid icons (fas:)",
"brands": "Include Brand icons (fab:)"
}
}
}
}
}

View File

@@ -0,0 +1,46 @@
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/'
ICON_FILES = {
'regular': 'far.js',
'solid': 'fas.js',
'brands': 'fab.js',
}
async def async_setup(hass, config):
setup_view(hass, DOMAIN)
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
def register_modules(hass, modules):
if DATA_EXTRA_MODULE_URL not in hass.data:
hass.data[DATA_EXTRA_MODULE_URL] = set()
url_set = hass.data[DATA_EXTRA_MODULE_URL]
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)

View File

@@ -0,0 +1,47 @@
import logging
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import callback
_LOGGER = logging.getLogger(__name__)
@config_entries.HANDLERS.register("fontawesome")
class FontawesomeConfigFlow(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")
return self.async_create_entry(title="", data={})
@staticmethod
@callback
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
async def async_step_init(self, user_input=None):
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Optional(
"regular",
default=self.config_entry.options.get("regular", False),
): bool,
vol.Optional(
"solid",
default=self.config_entry.options.get("solid", False),
): bool,
vol.Optional(
"brands",
default=self.config_entry.options.get("brands", False),
): bool,
}
)
)

View File

@@ -0,0 +1,29 @@
from aiohttp import web
from homeassistant.components.http import HomeAssistantView
import os.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):
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 as exception:
return web.Response(status=404)
return web.Response(body=filecontent, content_type="text/javascript", charset="utf-8")

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
{
"domain": "fontawesome",
"name": "Fontawesome icons",
"documentation": "",
"dependencies": ["frontend"],
"codeowners": [],
"requirements": [],
"config_flow": true
}