Add an input_datetime (#9313)

* Initial proposal for the input_datetime

* Linting

* Further linting, don't define time validation twice

* Make pylint *and* flake8 happy at the same time

* Move todos to the PR to make lint happy

* Actually validate the type of date/time

* First testing

* Linting

* Address code review issues

* Code review: Remove forgotten print()s

* Make set_datetime a coroutine

* Create contains_at_least_one_key_value CV method, use it

* Add timestamp to the attributes

* Test and fix corner case where restore data is bogus

* Add FIXME

* Fix date/time setting

* Fix Validation

* Merge date / time validation, add tests

* Simplify service data validation

* No default for initial state, allow 'unknown' as state

* cleanup

* fix schema
This commit is contained in:
Lukas Barth 2017-09-28 23:57:49 +02:00 committed by Pascal Vizeli
parent 2df433eb0a
commit 236d5f8742
4 changed files with 520 additions and 11 deletions

View file

@ -405,6 +405,31 @@ def test_time_zone():
schema('UTC')
def test_date():
"""Test date validation."""
schema = vol.Schema(cv.date)
for value in ['Not a date', '23:42', '2016-11-23T18:59:08']:
with pytest.raises(vol.Invalid):
schema(value)
schema(datetime.now().date())
schema('2016-11-23')
def test_time():
"""Test date validation."""
schema = vol.Schema(cv.time)
for value in ['Not a time', '2016-11-23', '2016-11-23T18:59:08']:
with pytest.raises(vol.Invalid):
schema(value)
schema(datetime.now().time())
schema('23:42:00')
schema('23:42')
def test_datetime():
"""Test date time validation."""
schema = vol.Schema(cv.datetime)
@ -447,6 +472,21 @@ def test_has_at_least_one_key():
schema(value)
def test_has_at_least_one_key_value():
"""Test has_at_least_one_key_value validator."""
schema = vol.Schema(cv.has_at_least_one_key_value(('drink', 'beer'),
('drink', 'soda'),
('food', 'maultaschen')))
for value in (None, [], {}, {'wine': None}, {'drink': 'water'}):
with pytest.raises(vol.MultipleInvalid):
schema(value)
for value in ({'drink': 'beer'}, {'food': 'maultaschen'},
{'drink': 'soda', 'food': 'maultaschen'}):
schema(value)
def test_enum():
"""Test enum validator."""
class TestEnum(enum.Enum):