Simplify loading of icons (#110687)

This commit is contained in:
J. Nick Koston 2024-02-16 09:51:14 -06:00 committed by GitHub
parent a0ead2b861
commit 53062a81cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -104,10 +104,7 @@ class _IconsCache:
async def _async_load(self, components: set[str]) -> None: async def _async_load(self, components: set[str]) -> None:
"""Populate the cache for a given set of components.""" """Populate the cache for a given set of components."""
_LOGGER.debug( _LOGGER.debug("Cache miss for: %s", components)
"Cache miss for: %s",
", ".join(components),
)
integrations: dict[str, Integration] = {} integrations: dict[str, Integration] = {}
domains = {loaded.rpartition(".")[-1] for loaded in components} domains = {loaded.rpartition(".")[-1] for loaded in components}
@ -129,16 +126,15 @@ class _IconsCache:
icons: dict[str, dict[str, Any]], icons: dict[str, dict[str, Any]],
) -> None: ) -> None:
"""Extract resources into the cache.""" """Extract resources into the cache."""
resource: dict[str, Any] | str
categories: set[str] = set() categories: set[str] = set()
for resource in icons.values(): for resource in icons.values():
categories.update(resource) categories.update(resource)
for category in categories: for category in categories:
new_resources = build_resources(icons, components, category) self._cache.setdefault(category, {}).update(
for component, resource in new_resources.items(): build_resources(icons, components, category)
category_cache: dict[str, Any] = self._cache.setdefault(category, {}) )
category_cache[component] = resource
async def async_get_icons( async def async_get_icons(