mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Relax the icon validator to allow non-mdi icons (#2764)
This commit is contained in:
parent
710096b1c6
commit
05fe5db030
2 changed files with 6 additions and 4 deletions
|
@ -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):
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue