Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vigonotion committed Apr 22, 2020
0 parents commit f62e87e
Show file tree
Hide file tree
Showing 16 changed files with 4,335 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom_components/**/*.js binary
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
**/__pycache__
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Tom Schneider

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# hass-simpleicons

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)

Use free icons from the [simpleicons](https://simpleicons.com) set in Home Assistant.

## Installation instructions

- Install using [HACS](https://hacs.xyz) (Or copy the contents of `custom_components/simpleicons/` to `<your config dir>/custom_components/simpleicons/`.)

- Restart Home Assistant

- Go to your integrations configuration and add simpleicons

## Usage

Find the icon you want in the [gallery](http://simpleicons.org/). Click on an icon. This will download the icon. You don't need that file, just it's filename.

The icon set is prefixed by: `si:`. Then comes the filename.

So,

- to get a facebook logo, use `si:facebook`
- to get a zigbee logo, use `si:zigbee`
- and so on

The icons are useable anywhere in Home Assistant - not only in lovelace.

## FAQ

### Can I set this up in configure.yaml instead?

Yes.

```yaml
simpleicons:
```
## Special thanks
This work is heavily based on [hass-fontawesome](https://github.com/thomasloven/hass-fontawesome) by Thomas Loven. Thank you!
8 changes: 8 additions & 0 deletions custom_components/simpleicons/.translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"config": {
"title": "Simple Icons",
"abort": {
"single_instance_allowed": "Es ist nur eine Instanz von Simple Icons erlaubt."
}
}
}
8 changes: 8 additions & 0 deletions custom_components/simpleicons/.translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"config": {
"title": "Simple Icons",
"abort": {
"single_instance_allowed": "Only a single configuration of simpleicons is allowed."
}
}
}
44 changes: 44 additions & 0 deletions custom_components/simpleicons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import homeassistant.components.frontend
from homeassistant.components.frontend import _frontend_root

from .custom_component_server import setup_view

DOMAIN = "simpleicons"

DATA_EXTRA_MODULE_URL = 'frontend_extra_module_url'
ICONS_URL = '/'+DOMAIN+'/data/'
ICON_FILES = {
'simpleicons': 'si.js'
}

async def async_setup(hass, config):
setup_view(hass, DOMAIN)
conf = config.get(DOMAIN)
if not conf:
return True
register_modules(hass)
return True

async def async_setup_entry(hass, config_entry):
config_entry.add_update_listener(_update_listener)
register_modules(hass)
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)
return True


def register_modules(hass):
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)
14 changes: 14 additions & 0 deletions custom_components/simpleicons/config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.core import callback

_LOGGER = logging.getLogger(__name__)

@config_entries.HANDLERS.register("simpleicons")
class simpleiconsConfigFlow(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={})
29 changes: 29 additions & 0 deletions custom_components/simpleicons/custom_component_server.py
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions custom_components/simpleicons/data/si.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions custom_components/simpleicons/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"domain": "simpleicons",
"name": "Simple Icons",
"documentation": "",
"dependencies": ["frontend"],
"codeowners": [],
"requirements": [],
"config_flow": true
}
4 changes: 4 additions & 0 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "simpleicons",
"render_readme": true
}
22 changes: 22 additions & 0 deletions js/si.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const simpleIcons = require('simple-icons');


var x = 2

var svg = "<svg><defs>";

for(var icon of Object.entries(simpleIcons)) {
var path = icon[1].path;
var slug = icon[1].slug;

var g = "<g id=\"" + slug + "\" viewBox=\"-1 -1 26 26\"><path d=\"" + path + "\"/></g>";
svg += g;
}

svg += "</defs></svg>"

const iconset = document.createElement("ha-iconset-svg");
iconset.name="si";
iconset.size=1024;
iconset.innerHTML = svg;
document.body.appendChild(iconset);
Loading

0 comments on commit f62e87e

Please sign in to comment.