Use eventloop for scheduling (#37184)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
J. Nick Koston 2020-06-29 11:39:24 -05:00 committed by GitHub
parent 0f72008090
commit 89a9634d35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 366 additions and 272 deletions

View file

@ -1,5 +1,5 @@
"""The tests for the AsusWrt sensor platform."""
from datetime import datetime, timedelta
from datetime import timedelta
from aioasuswrt.asuswrt import Device
@ -16,7 +16,6 @@ from homeassistant.components.asuswrt import (
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from homeassistant.util.dt import utcnow
from tests.async_mock import AsyncMock, patch
@ -51,7 +50,7 @@ MOCK_BYTES_TOTAL = [60000000000, 50000000000]
MOCK_CURRENT_TRANSFER_RATES = [20000000, 10000000]
async def test_sensors(hass: HomeAssistant):
async def test_sensors(hass: HomeAssistant, mock_device_tracker_conf):
"""Test creating an AsusWRT sensor."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = AsyncMock()
@ -61,23 +60,17 @@ async def test_sensors(hass: HomeAssistant):
return_value=MOCK_CURRENT_TRANSFER_RATES
)
now = datetime(2020, 1, 1, 1, tzinfo=dt_util.UTC)
with patch(("homeassistant.helpers.event.dt_util.utcnow"), return_value=now):
assert await async_setup_component(hass, DOMAIN, VALID_CONFIG_ROUTER_SSH)
await hass.async_block_till_done()
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert await async_setup_component(hass, DOMAIN, VALID_CONFIG_ROUTER_SSH)
await hass.async_block_till_done()
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert (
hass.states.get(f"{sensor.DOMAIN}.asuswrt_devices_connected").state
== "3"
)
assert (
hass.states.get(f"{sensor.DOMAIN}.asuswrt_download_speed").state
== "160.0"
)
assert hass.states.get(f"{sensor.DOMAIN}.asuswrt_download").state == "60.0"
assert (
hass.states.get(f"{sensor.DOMAIN}.asuswrt_upload_speed").state == "80.0"
)
assert hass.states.get(f"{sensor.DOMAIN}.asuswrt_upload").state == "50.0"
assert (
hass.states.get(f"{sensor.DOMAIN}.asuswrt_devices_connected").state == "3"
)
assert (
hass.states.get(f"{sensor.DOMAIN}.asuswrt_download_speed").state == "160.0"
)
assert hass.states.get(f"{sensor.DOMAIN}.asuswrt_download").state == "60.0"
assert hass.states.get(f"{sensor.DOMAIN}.asuswrt_upload_speed").state == "80.0"
assert hass.states.get(f"{sensor.DOMAIN}.asuswrt_upload").state == "50.0"