diff --git a/homeassistant/components/person/__init__.py b/homeassistant/components/person/__init__.py index e6f83b80ba4..89fac761497 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -50,7 +50,8 @@ PERSON_SCHEMA = vol.Schema({ }) CONFIG_SCHEMA = vol.Schema({ - vol.Optional(DOMAIN): vol.Any(vol.All(cv.ensure_list, [PERSON_SCHEMA]), {}) + vol.Optional(DOMAIN): vol.All( + cv.ensure_list, cv.remove_falsy, [PERSON_SCHEMA]) }, extra=vol.ALLOW_EXTRA) _UNDEF = object() diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 6513f9368b0..a954d01856e 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -349,6 +349,11 @@ def positive_timedelta(value: timedelta) -> timedelta: return value +def remove_falsy(value: Sequence[T]) -> Sequence[T]: + """Remove falsy values from a list.""" + return [v for v in value if v] + + def service(value): """Validate service.""" # Services use same format as entities so we can use same helper. diff --git a/script/inspect_schemas.py b/script/inspect_schemas.py index 46d5cf92ecc..9904552c681 100755 --- a/script/inspect_schemas.py +++ b/script/inspect_schemas.py @@ -48,7 +48,7 @@ def main(): schema_type, schema = _identify_config_schema(module) - add_msg("CONFIG_SCHEMA " + schema_type, module_name + ' ' + + add_msg("CONFIG_SCHEMA " + str(schema_type), module_name + ' ' + color('cyan', str(schema)[:60])) for key in sorted(msg): diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index 4a883fbf2fd..e0bd509d330 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -1,15 +1,15 @@ """Test config validators.""" -from datetime import timedelta, datetime, date +from datetime import date, datetime, timedelta import enum import os from socket import _GLOBAL_DEFAULT_TIMEOUT from unittest.mock import Mock, patch import uuid -import homeassistant import pytest import voluptuous as vol +import homeassistant import homeassistant.helpers.config_validation as cv @@ -291,6 +291,11 @@ def test_time_period(): assert -1 * timedelta(hours=1, minutes=15) == schema('-1:15') +def test_remove_falsy(): + """Test remove falsy.""" + assert cv.remove_falsy([0, None, 1, "1", {}, [], ""]) == [1, "1"] + + def test_service(): """Test service validation.""" schema = vol.Schema(cv.service) @@ -908,7 +913,7 @@ def test_matches_regex(): schema(" nrtd ") test_str = "This is a test including uiae." - assert (schema(test_str) == test_str) + assert schema(test_str) == test_str def test_is_regex(): @@ -982,6 +987,6 @@ def test_uuid4_hex(caplog): # the 17th char should be 8-a schema('a03d31b22eee4acc7b90eec40be6ed23') - hex = uuid.uuid4().hex - assert schema(hex) == hex - assert schema(hex.upper()) == hex + _hex = uuid.uuid4().hex + assert schema(_hex) == _hex + assert schema(_hex.upper()) == _hex