Fix handling of quoted time_pattern values (#40470)

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Anders Melchiorsen 2020-09-23 09:21:57 +02:00 committed by GitHub
parent df9634a41f
commit 7876cdb37a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View file

@ -36,7 +36,7 @@ class TimePattern:
if isinstance(value, str) and value.startswith("/"):
number = int(value[1:])
else:
number = int(value)
value = number = int(value)
if not (0 <= number <= self.maximum):
raise vol.Invalid(f"must be a value between 0 and {self.maximum}")

View file

@ -1,4 +1,6 @@
"""The tests for the time_pattern automation."""
from datetime import timedelta
import pytest
import voluptuous as vol
@ -123,6 +125,39 @@ async def test_if_fires_when_second_matches(hass, calls):
assert len(calls) == 1
async def test_if_fires_when_second_as_string_matches(hass, calls):
"""Test for firing if seconds are matching."""
now = dt_util.utcnow()
time_that_will_not_match_right_away = dt_util.utcnow().replace(
year=now.year + 1, second=15
)
with patch(
"homeassistant.util.dt.utcnow", return_value=time_that_will_not_match_right_away
):
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": "*",
"minutes": "*",
"seconds": "30",
},
"action": {"service": "test.automation"},
}
},
)
async_fire_time_changed(
hass, time_that_will_not_match_right_away + timedelta(seconds=15)
)
await hass.async_block_till_done()
assert len(calls) == 1
async def test_if_fires_when_all_matches(hass, calls):
"""Test for firing if everything matches."""
now = dt_util.utcnow()