From d7aec798887d53e4172c16df7ed18a43b22483ae Mon Sep 17 00:00:00 2001 From: clydebarrow <2366188+clydebarrow@users.noreply.github.com> Date: Sun, 23 Feb 2025 18:20:54 +1100 Subject: [PATCH] Fix path in error message --- esphome/components/font/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/esphome/components/font/__init__.py b/esphome/components/font/__init__.py index 9405bdbd65..de0d41fdb5 100644 --- a/esphome/components/font/__init__.py +++ b/esphome/components/font/__init__.py @@ -52,6 +52,16 @@ CONF_IGNORE_MISSING_GLYPHS = "ignore_missing_glyphs" # Cache loaded freetype fonts class FontCache(MutableMapping): + @staticmethod + def get_name(value): + if CONF_FAMILY in value: + return ( + f"{value[CONF_FAMILY]}:{int(value[CONF_ITALIC])}:{value[CONF_WEIGHT]}" + ) + if CONF_URL in value: + return value[CONF_URL] + return value[CONF_PATH] + @staticmethod def _keytransform(value): if CONF_FAMILY in value: @@ -131,7 +141,7 @@ def check_missing_glyphs(file, codepoints, warning: bool = False): ) if count > 10: missing_str += f"\n and {count - 10} more." - message = f"Font {Path(file).name} is missing {count} glyph{'s' if count != 1 else ''}:\n {missing_str}" + message = f"Font {FontCache.get_name(file)} is missing {count} glyph{'s' if count != 1 else ''}:\n {missing_str}" if warning: _LOGGER.warning(message) else: