Fix time config validation

This commit is contained in:
Otto Winter 2018-05-06 17:40:37 +02:00
parent a88aad2179
commit e65a4d50e5
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E

View File

@ -237,21 +237,26 @@ def time_period_str_unit(value):
unit_to_kwarg = { unit_to_kwarg = {
'ms': 'milliseconds', 'ms': 'milliseconds',
'milliseconds': 'milliseconds',
's': 'seconds', 's': 'seconds',
'sec': 'seconds', 'sec': 'seconds',
'seconds': 'seconds',
'min': 'minutes', 'min': 'minutes',
'minutes': 'minutes',
'h': 'hours', 'h': 'hours',
'hours': 'hours',
'd': 'days', '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: if match is None or match.group(2) not in unit_to_kwarg:
raise vol.Invalid(u"Expected time period with unit, " raise vol.Invalid(u"Expected time period with unit, "
u"got {}".format(value)) u"got {}".format(value))
kwarg = unit_to_kwarg[match.group(2)] 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): def time_period_to_milliseconds(value):