mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix flapping event template test (#42614)
This commit is contained in:
parent
a396f8f76f
commit
8eb89cdb46
@ -2123,7 +2123,10 @@ async def test_track_template_with_time_default(hass):
|
|||||||
|
|
||||||
async def test_track_template_with_time_that_leaves_scope(hass):
|
async def test_track_template_with_time_that_leaves_scope(hass):
|
||||||
"""Test tracking template with time."""
|
"""Test tracking template with time."""
|
||||||
|
now = dt_util.utcnow()
|
||||||
|
test_time = datetime(now.year + 1, 5, 24, 11, 59, 1, 500000, tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
|
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
|
||||||
hass.states.async_set("binary_sensor.washing_machine", "on")
|
hass.states.async_set("binary_sensor.washing_machine", "on")
|
||||||
specific_runs = []
|
specific_runs = []
|
||||||
template_complex = Template(
|
template_complex = Template(
|
||||||
@ -2174,15 +2177,17 @@ async def test_track_template_with_time_that_leaves_scope(hass):
|
|||||||
|
|
||||||
# Verify we do not update before the minute rolls over
|
# Verify we do not update before the minute rolls over
|
||||||
callback_count_before_time_change = len(specific_runs)
|
callback_count_before_time_change = len(specific_runs)
|
||||||
test_time = dt_util.utcnow().replace(second=1)
|
|
||||||
async_fire_time_changed(hass, test_time)
|
async_fire_time_changed(hass, test_time)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert len(specific_runs) == callback_count_before_time_change
|
||||||
|
|
||||||
async_fire_time_changed(hass, test_time + timedelta(seconds=58))
|
async_fire_time_changed(hass, test_time + timedelta(seconds=58))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(specific_runs) == callback_count_before_time_change
|
assert len(specific_runs) == callback_count_before_time_change
|
||||||
|
|
||||||
# Verify we do update on the next change of minute
|
# Verify we do update on the next change of minute
|
||||||
async_fire_time_changed(hass, test_time + timedelta(seconds=59))
|
async_fire_time_changed(hass, test_time + timedelta(seconds=59))
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(specific_runs) == callback_count_before_time_change + 1
|
assert len(specific_runs) == callback_count_before_time_change + 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user