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 = {
|
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user