From 05fe5db030a05d9bc2877927494d8cd6b30b2bdd Mon Sep 17 00:00:00 2001 From: Paul Monigatti Date: Tue, 23 Nov 2021 21:21:14 +1300 Subject: [PATCH] Relax the icon validator to allow non-mdi icons (#2764) --- esphome/config_validation.py | 6 ++++-- tests/unit_tests/test_config_validation.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 2bb45487fa..8df74ba861 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -296,9 +296,11 @@ def icon(value): value = string_strict(value) if not value: return value - if value.startswith("mdi:"): + if re.match("^[\\w\\-]+:[\\w\\-]+$", value): return value - raise Invalid('Icons should start with prefix "mdi:"') + raise Invalid( + 'Icons must match the format "[icon pack]:[icon]", e.g. "mdi:home-assistant"' + ) def boolean(value): diff --git a/tests/unit_tests/test_config_validation.py b/tests/unit_tests/test_config_validation.py index 16cfb16e94..9e9af52d00 100644 --- a/tests/unit_tests/test_config_validation.py +++ b/tests/unit_tests/test_config_validation.py @@ -66,7 +66,7 @@ def test_string_string__invalid(value): config_validation.string_strict(value) -@given(builds(lambda v: "mdi:" + v, text())) +@given(builds(lambda v: "mdi:" + v, text(alphabet=string.ascii_letters + string.digits + "-_", min_size=1, max_size=20))) @example("") def test_icon__valid(value): actual = config_validation.icon(value) @@ -75,7 +75,7 @@ def test_icon__valid(value): def test_icon__invalid(): - with pytest.raises(Invalid, match="Icons should start with prefix"): + with pytest.raises(Invalid, match="Icons must match the format "): config_validation.icon("foo")