mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 12:06:26 +01:00
Fix time config validation
This commit is contained in:
parent
a88aad2179
commit
e65a4d50e5
@ -237,21 +237,26 @@ def time_period_str_unit(value):
|
||||
|
||||
unit_to_kwarg = {
|
||||
'ms': 'milliseconds',
|
||||
'milliseconds': 'milliseconds',
|
||||
's': 'seconds',
|
||||
'sec': 'seconds',
|
||||
'seconds': 'seconds',
|
||||
'min': 'minutes',
|
||||
'minutes': 'minutes',
|
||||
'h': 'hours',
|
||||
'hours': 'hours',
|
||||
'd': 'days',
|
||||
'days': 'days',
|
||||
}
|
||||
|
||||
match = re.match(r"^([-+]?\d+)\s*(\w*)$", value)
|
||||
match = re.match(r"^([-+]?[0-9]*\.?[0-9]*)\s*(\w*)$", value)
|
||||
|
||||
if match is None or match.group(2) not in unit_to_kwarg:
|
||||
raise vol.Invalid(u"Expected time period with unit, "
|
||||
u"got {}".format(value))
|
||||
|
||||
kwarg = unit_to_kwarg[match.group(2)]
|
||||
return timedelta(**{kwarg: int(match.group(1))})
|
||||
return timedelta(**{kwarg: float(match.group(1))})
|
||||
|
||||
|
||||
def time_period_to_milliseconds(value):
|
||||
|
Loading…
Reference in New Issue
Block a user