Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/person/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
})

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()
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/helpers/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that need tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean unit tests or test if a dictionary?



def service(value):
"""Validate service."""
# Services use same format as entities so we can use same helper.
Expand Down
2 changes: 1 addition & 1 deletion script/inspect_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def add_msg(key, item):

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):
Expand Down
17 changes: 11 additions & 6 deletions tests/helpers/test_config_validation.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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