Use eventloop for scheduling (#37184)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
0f72008090
commit
89a9634d35
42 changed files with 366 additions and 272 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
This includes tests for all mock object types.
|
||||
"""
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -37,9 +37,7 @@ from homeassistant.const import (
|
|||
ATTR_BATTERY_CHARGING,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_NOW,
|
||||
ATTR_SERVICE,
|
||||
EVENT_TIME_CHANGED,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
|
@ -49,7 +47,7 @@ from homeassistant.helpers.event import TRACK_STATE_CHANGE_CALLBACKS
|
|||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import async_mock_service
|
||||
from tests.common import async_fire_time_changed, async_mock_service
|
||||
|
||||
|
||||
async def test_debounce(hass):
|
||||
|
@ -66,11 +64,11 @@ async def test_debounce(hass):
|
|||
|
||||
debounce_demo = debounce(demo_func)
|
||||
assert debounce_demo.__name__ == "demo_func"
|
||||
now = datetime(2018, 1, 1, 20, 0, 0, tzinfo=dt_util.UTC)
|
||||
now = dt_util.utcnow()
|
||||
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
await hass.async_add_executor_job(debounce_demo, mock, "value")
|
||||
hass.bus.async_fire(EVENT_TIME_CHANGED, {ATTR_NOW: now + timedelta(seconds=3)})
|
||||
async_fire_time_changed(hass, now + timedelta(seconds=3))
|
||||
await hass.async_block_till_done()
|
||||
assert counter == 1
|
||||
assert len(arguments) == 2
|
||||
|
@ -79,7 +77,7 @@ async def test_debounce(hass):
|
|||
await hass.async_add_executor_job(debounce_demo, mock, "value")
|
||||
await hass.async_add_executor_job(debounce_demo, mock, "value")
|
||||
|
||||
hass.bus.async_fire(EVENT_TIME_CHANGED, {ATTR_NOW: now + timedelta(seconds=3)})
|
||||
async_fire_time_changed(hass, now + timedelta(seconds=3))
|
||||
await hass.async_block_till_done()
|
||||
assert counter == 2
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue