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:
parent
df9634a41f
commit
7876cdb37a
2 changed files with 36 additions and 1 deletions
|
@ -36,7 +36,7 @@ class TimePattern:
|
||||||
if isinstance(value, str) and value.startswith("/"):
|
if isinstance(value, str) and value.startswith("/"):
|
||||||
number = int(value[1:])
|
number = int(value[1:])
|
||||||
else:
|
else:
|
||||||
number = int(value)
|
value = number = int(value)
|
||||||
|
|
||||||
if not (0 <= number <= self.maximum):
|
if not (0 <= number <= self.maximum):
|
||||||
raise vol.Invalid(f"must be a value between 0 and {self.maximum}")
|
raise vol.Invalid(f"must be a value between 0 and {self.maximum}")
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""The tests for the time_pattern automation."""
|
"""The tests for the time_pattern automation."""
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -123,6 +125,39 @@ async def test_if_fires_when_second_matches(hass, calls):
|
||||||
assert len(calls) == 1
|
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):
|
async def test_if_fires_when_all_matches(hass, calls):
|
||||||
"""Test for firing if everything matches."""
|
"""Test for firing if everything matches."""
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue