Skip to content

Commit

Permalink
Bump to Iconify JSON datestamp 2024-11-22.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Beeching authored and James Beeching committed Nov 22, 2024
1 parent 1296eb0 commit 3582395
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1 align="center">Material Symbols for Home Assistant</h1>
</div>

**Material Symbols for Home Assistant** is a collection of 13,616 Google Material Symbols for use within Home Assistant. It uses the icon-set produced and maintained by [iconify](https://github.com/iconify/icon-sets).
**Material Symbols for Home Assistant** is a collection of 13,693 Google Material Symbols for use within Home Assistant. It uses the icon-set produced and maintained by [iconify](https://github.com/iconify/icon-sets).

There is a [Icon Finder Tool](https://beecho01.github.io/material-symbols-iconfinder/) to help you select the correct icon. Simply type in what you're looking for, click the icon of choice, and the icon entry for home assistant will be copied to your clipboard (e.g., `m3o:light`). The copied text can be pasted for use in your YAML configuration or into you UI frontend interface.

Expand All @@ -17,7 +17,7 @@ There is a [Icon Finder Tool](https://beecho01.github.io/material-symbols-iconfi
> ### Breaking Changes
> - **Repository Structure**: The repository and installation have transitioned from a "Lovelace" repository (v1.X.X) to an "Integration" repository (202X.X.X+). Users should reinstall from the new integration repository to avoid compatibility issues.
> - **Icon Prefix Migration**: The icon prefix has transitioned from m3s, which previously contained all icon styles, to individual prefixes based on style. Each style now has its unique prefix (e.g., m3o for outlined, m3r for rounded). Refer to the documentation for the complete list of prefixes.
> - **Reduction in Available Icons**: The number of available icons has been reduced from ~18,600 to 13,616.
> - **Reduction in Available Icons**: The number of available icons has been reduced from ~18,600 to 13,693.
---

Expand Down
57 changes: 42 additions & 15 deletions custom_components/material_symbols/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
import logging
import json
from os import path, walk
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.components.frontend import add_extra_js_url
from homeassistant.components.http import StaticPathConfig
from homeassistant.components.http.view import HomeAssistantView

LOGGER = logging.getLogger(__name__)

NAME = "Material Symbols"
DOMAIN = "material_symbols"
VERSION = "2024.11.17"
VERSION = "2024.11.22-b1"

DATA_EXTRA_MODULE_URL = "frontend_extra_module_url"
LOADER_URL = f"/{DOMAIN}/material_symbols.js"
LOADER_PATH = f"custom_components/{DOMAIN}/material_symbols.js"
ICONS_URL = f"/{DOMAIN}"
LOADER_URL = f"/{DOMAIN}/material_symbols.js"
ICONS_PATH = f"custom_components/{DOMAIN}/data"
LOADER_PATH = f"custom_components/{DOMAIN}/material_symbols.js"

class ListingView(HomeAssistantView):

requires_auth = False

def __init__(self, url, iconset_path, hass, iconset_prefix):
self.url = url
self.name = f"api:{DOMAIN}:icons:{iconset_prefix}"
self.iconset_path = iconset_path
self.hass = hass

async def get(self, request):
icons_list = await self.hass.async_add_executor_job(
self.get_icons_list, self.iconset_path
)
return self.json(icons_list)

def get_icons_list(self, iconset_path):
icons = []
for dirpath, dirnames, filenames in walk(iconset_path):
relative_dir = path.relpath(dirpath, iconset_path)
for fn in filenames:
if fn.endswith(".svg"):
icon_name = path.join(relative_dir, fn[:-4]).replace(path.sep, '/')
icons.append({"name": icon_name})
return icons

async def async_setup(hass: HomeAssistant, config):
# Register the JS loader file
await hass.http.async_register_static_paths(
[StaticPathConfig(LOADER_URL, hass.config.path(LOADER_PATH), True)]
)
add_extra_js_url(hass, LOADER_URL)

# Define icon set folders and register their static paths
iconset_prefixes = ["m3o", "m3of", "m3r", "m3rf", "m3s", "m3sf"]
for iconset_prefix in iconset_prefixes:
icons_url = f"{ICONS_URL}/{iconset_prefix}"
icons_path = hass.config.path(f"{ICONS_PATH}/{iconset_prefix}")
icons_list_url = f"{icons_url}/icons.json"

await hass.http.async_register_static_paths(
[
StaticPathConfig(
f"{ICONS_URL}/{iconset_prefix}",
hass.config.path(f"{ICONS_PATH}/{iconset_prefix}"),
True,
)
]
[StaticPathConfig(icons_url, icons_path, True)]
)
hass.http.register_view(
ListingView(icons_list_url, icons_path, hass, iconset_prefix)
)

return True

async def async_setup_entry(hass, entry):
Expand All @@ -51,5 +78,5 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry,
title="Material Symbols"
)
LOGGER.info("Migrating Material Symbols config entry.")
LOGGER.info("Migrated Material Symbols config entry to version 2.")
return True
2 changes: 1 addition & 1 deletion custom_components/material_symbols/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from homeassistant import config_entries

_LOGGER = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)

DOMAIN = "material_symbols"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/material_symbols/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/beecho01/material-symbols/issues",
"requirements": [],
"version": "2024.11.17"
"version": "2024.11.22-b1"
}
4 changes: 2 additions & 2 deletions custom_components/material_symbols/material_symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@
});

console.info(
"%c MATERIAL SYMBOLS %c %c 2024.11.17 ",
"%c MATERIAL SYMBOLS %c %c 2024.11.22-b1 ",
'@import url("https://fonts.googleapis.com/css2?family=Roboto");background-color:#1FBEF2;color:#FFFFFF;padding:3px 43px 2px 8px;border-radius:999vh;border:5px solid #1FBEF2;font-family:"Roboto", sans-serif;margin-top:18px',
'@import url("https://fonts.googleapis.com/css2?family=Roboto");background-color:#FFFFFF;color:#1FBEF2;padding:3px 8px 2px 0;border-radius:999vh 0 0 999vh;border:0;font-family:"Roboto", sans-serif;margin-left:-94px',
'@import url("https://fonts.googleapis.com/css2?family=Roboto");background-color:#FFFFFF;color:#1FBEF2;padding:3px 9px 2px 0;border-radius:0 999vh 999vh 0;border:0;font-family:"Roboto", sans-serif;margin-left:-1px;margin-bottom:18px'
);
})();
})();

0 comments on commit 3582395

Please sign in to comment.