Load yaml using validator and include consider_home (#3743)

* Load yaml using validator, consider_home

* timedelta, track_if_away

* improve voluptuous

* Add default back

* Change time_period validation order
This commit is contained in:
Johann Kellerman 2016-10-08 03:08:33 +02:00 committed by Paulus Schoutsen
parent b09b13f552
commit fb94aaa5a1
4 changed files with 53 additions and 31 deletions

View file

@ -167,7 +167,16 @@ def time_period_str(value: str) -> timedelta:
return offset
time_period = vol.Any(time_period_str, timedelta, time_period_dict)
def time_period_seconds(value: Union[int, str]) -> timedelta:
"""Validate and transform seconds to a time offset."""
try:
return timedelta(seconds=int(value))
except (ValueError, TypeError):
raise vol.Invalid('Expected seconds, got {}'.format(value))
time_period = vol.Any(time_period_str, time_period_seconds, timedelta,
time_period_dict)
def match_all(value):