Fix event test (#42078)
This commit is contained in:
parent
16c402f583
commit
8d4675713a
2 changed files with 47 additions and 6 deletions
|
@ -1,9 +1,20 @@
|
||||||
"""The tests for time_date sensor platform."""
|
"""The tests for time_date sensor platform."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
import homeassistant.components.time_date.sensor as time_date
|
import homeassistant.components.time_date.sensor as time_date
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.async_mock import patch
|
from tests.async_mock import patch
|
||||||
|
|
||||||
|
ORIG_TZ = dt_util.DEFAULT_TIME_ZONE
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def restore_ts():
|
||||||
|
"""Restore default TZ."""
|
||||||
|
yield
|
||||||
|
dt_util.DEFAULT_TIME_ZONE = ORIG_TZ
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
async def test_intervals(hass):
|
async def test_intervals(hass):
|
||||||
|
|
|
@ -1545,7 +1545,12 @@ async def test_track_template_rate_limit_suppress_listener(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
info.async_refresh()
|
info.async_refresh()
|
||||||
|
|
||||||
assert info.listeners == {"all": True, "domains": set(), "entities": set()}
|
assert info.listeners == {
|
||||||
|
"all": True,
|
||||||
|
"domains": set(),
|
||||||
|
"entities": set(),
|
||||||
|
"time": False,
|
||||||
|
}
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert refresh_runs == [0]
|
assert refresh_runs == [0]
|
||||||
|
@ -1557,7 +1562,12 @@ async def test_track_template_rate_limit_suppress_listener(hass):
|
||||||
hass.states.async_set("sensor.two", "any")
|
hass.states.async_set("sensor.two", "any")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# Should be suppressed during the rate limit
|
# Should be suppressed during the rate limit
|
||||||
assert info.listeners == {"all": False, "domains": set(), "entities": set()}
|
assert info.listeners == {
|
||||||
|
"all": False,
|
||||||
|
"domains": set(),
|
||||||
|
"entities": set(),
|
||||||
|
"time": False,
|
||||||
|
}
|
||||||
assert refresh_runs == [0, 1]
|
assert refresh_runs == [0, 1]
|
||||||
next_time = dt_util.utcnow() + timedelta(seconds=0.125)
|
next_time = dt_util.utcnow() + timedelta(seconds=0.125)
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -1566,7 +1576,12 @@ async def test_track_template_rate_limit_suppress_listener(hass):
|
||||||
async_fire_time_changed(hass, next_time)
|
async_fire_time_changed(hass, next_time)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# Rate limit released and the all listener returns
|
# Rate limit released and the all listener returns
|
||||||
assert info.listeners == {"all": True, "domains": set(), "entities": set()}
|
assert info.listeners == {
|
||||||
|
"all": True,
|
||||||
|
"domains": set(),
|
||||||
|
"entities": set(),
|
||||||
|
"time": False,
|
||||||
|
}
|
||||||
assert refresh_runs == [0, 1, 2]
|
assert refresh_runs == [0, 1, 2]
|
||||||
hass.states.async_set("sensor.three", "any")
|
hass.states.async_set("sensor.three", "any")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1575,7 +1590,12 @@ async def test_track_template_rate_limit_suppress_listener(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert refresh_runs == [0, 1, 2]
|
assert refresh_runs == [0, 1, 2]
|
||||||
# Rate limit hit and the all listener is shut off
|
# Rate limit hit and the all listener is shut off
|
||||||
assert info.listeners == {"all": False, "domains": set(), "entities": set()}
|
assert info.listeners == {
|
||||||
|
"all": False,
|
||||||
|
"domains": set(),
|
||||||
|
"entities": set(),
|
||||||
|
"time": False,
|
||||||
|
}
|
||||||
next_time = dt_util.utcnow() + timedelta(seconds=0.125 * 2)
|
next_time = dt_util.utcnow() + timedelta(seconds=0.125 * 2)
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.ratelimit.dt_util.utcnow", return_value=next_time
|
"homeassistant.helpers.ratelimit.dt_util.utcnow", return_value=next_time
|
||||||
|
@ -1583,12 +1603,22 @@ async def test_track_template_rate_limit_suppress_listener(hass):
|
||||||
async_fire_time_changed(hass, next_time)
|
async_fire_time_changed(hass, next_time)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# Rate limit released and the all listener returns
|
# Rate limit released and the all listener returns
|
||||||
assert info.listeners == {"all": True, "domains": set(), "entities": set()}
|
assert info.listeners == {
|
||||||
|
"all": True,
|
||||||
|
"domains": set(),
|
||||||
|
"entities": set(),
|
||||||
|
"time": False,
|
||||||
|
}
|
||||||
assert refresh_runs == [0, 1, 2, 4]
|
assert refresh_runs == [0, 1, 2, 4]
|
||||||
hass.states.async_set("sensor.five", "any")
|
hass.states.async_set("sensor.five", "any")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# Rate limit hit and the all listener is shut off
|
# Rate limit hit and the all listener is shut off
|
||||||
assert info.listeners == {"all": False, "domains": set(), "entities": set()}
|
assert info.listeners == {
|
||||||
|
"all": False,
|
||||||
|
"domains": set(),
|
||||||
|
"entities": set(),
|
||||||
|
"time": False,
|
||||||
|
}
|
||||||
assert refresh_runs == [0, 1, 2, 4]
|
assert refresh_runs == [0, 1, 2, 4]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue