mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Disallow list/dict for string configuration (#17202)
This commit is contained in:
parent
c8266c6692
commit
6e81ae096e
@ -335,9 +335,12 @@ def slugify(value):
|
|||||||
|
|
||||||
def string(value: Any) -> str:
|
def string(value: Any) -> str:
|
||||||
"""Coerce value to string, except for None."""
|
"""Coerce value to string, except for None."""
|
||||||
if value is not None:
|
if value is None:
|
||||||
return str(value)
|
raise vol.Invalid('string value is None')
|
||||||
raise vol.Invalid('string value is None')
|
if isinstance(value, (list, dict)):
|
||||||
|
raise vol.Invalid('value should be a string')
|
||||||
|
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
def temperature_unit(value) -> str:
|
def temperature_unit(value) -> str:
|
||||||
|
@ -356,9 +356,15 @@ def test_string():
|
|||||||
"""Test string validation."""
|
"""Test string validation."""
|
||||||
schema = vol.Schema(cv.string)
|
schema = vol.Schema(cv.string)
|
||||||
|
|
||||||
with pytest.raises(vol.MultipleInvalid):
|
with pytest.raises(vol.Invalid):
|
||||||
schema(None)
|
schema(None)
|
||||||
|
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
schema([])
|
||||||
|
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
schema({})
|
||||||
|
|
||||||
for value in (True, 1, 'hello'):
|
for value in (True, 1, 'hello'):
|
||||||
schema(value)
|
schema(value)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user