Do async_setup_platform in background (#36244)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Paulus Schoutsen 2020-05-31 22:18:30 -07:00 committed by GitHub
parent d488c779fc
commit 276f3afb00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
161 changed files with 1184 additions and 305 deletions

View File

@ -34,6 +34,7 @@ from homeassistant.components.stream.const import (
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_FILENAME,
EVENT_HOMEASSISTANT_START,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
@ -48,7 +49,6 @@ from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.network import get_url
from homeassistant.loader import bind_hass
from homeassistant.setup import async_when_setup
from .const import DATA_CAMERA_PREFS, DOMAIN
from .prefs import CameraPreferences
@ -259,7 +259,7 @@ async def async_setup(hass, config):
await component.async_setup(config)
async def preload_stream(hass, _):
async def preload_stream(_):
for camera in component.entities:
camera_prefs = prefs.get(camera.entity_id)
if not camera_prefs.preload_stream:
@ -273,7 +273,7 @@ async def async_setup(hass, config):
request_stream(hass, source, keepalive=True, options=camera.stream_options)
async_when_setup(hass, DOMAIN_STREAM, preload_stream)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, preload_stream)
@callback
def update_tokens(time):

View File

@ -11,6 +11,7 @@ from homeassistant.components.light import (
)
from homeassistant.const import (
ATTR_ENTITY_ID,
EVENT_HOMEASSISTANT_START,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_HOME,
@ -59,17 +60,35 @@ CONFIG_SCHEMA = vol.Schema(
async def async_setup(hass, config):
"""Set up the triggers to control lights based on device presence."""
conf = config[DOMAIN]
disable_turn_off = conf[CONF_DISABLE_TURN_OFF]
light_group = conf.get(CONF_LIGHT_GROUP)
light_profile = conf[CONF_LIGHT_PROFILE]
device_group = conf.get(CONF_DEVICE_GROUP)
async def activate_on_start(_):
"""Activate automation."""
await activate_automation(
hass, device_group, light_group, light_profile, disable_turn_off
)
if hass.is_running:
await activate_on_start(None)
else:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, activate_on_start)
return True
async def activate_automation(
hass, device_group, light_group, light_profile, disable_turn_off
):
"""Activate the automation."""
logger = logging.getLogger(__name__)
device_tracker = hass.components.device_tracker
group = hass.components.group
light = hass.components.light
person = hass.components.person
conf = config[DOMAIN]
disable_turn_off = conf[CONF_DISABLE_TURN_OFF]
light_group = conf.get(CONF_LIGHT_GROUP)
light_profile = conf[CONF_LIGHT_PROFILE]
device_group = conf.get(CONF_DEVICE_GROUP)
if device_group is None:
device_entity_ids = hass.states.async_entity_ids(device_tracker.DOMAIN)
@ -79,7 +98,7 @@ async def async_setup(hass, config):
if not device_entity_ids:
logger.error("No devices found to track")
return False
return
# Get the light IDs from the specified group
if light_group is None:
@ -89,7 +108,7 @@ async def async_setup(hass, config):
if not light_ids:
logger.error("No lights found to turn on")
return False
return
@callback
def anyone_home():
@ -219,7 +238,7 @@ async def async_setup(hass, config):
)
if disable_turn_off:
return True
return
@callback
def turn_off_lights_when_all_leave(entity, old_state, new_state):
@ -247,4 +266,4 @@ async def async_setup(hass, config):
STATE_NOT_HOME,
)
return True
return

View File

@ -24,7 +24,7 @@ class APICount(Entity):
def __init__(self):
"""Initialize the API count."""
self.count = None
self.count = 0
async def async_added_to_hass(self):
"""Added to hass."""
@ -38,7 +38,6 @@ class APICount(Entity):
SIGNAL_WEBSOCKET_DISCONNECTED, self._update_count
)
)
self._update_count()
@property
def name(self):

View File

@ -291,7 +291,7 @@ class MiroboVacuum(StateVacuumEntity):
@property
def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return list(self._fan_speeds)
return list(self._fan_speeds) if self._fan_speeds else []
@property
def device_state_attributes(self):

View File

@ -123,15 +123,11 @@ class EntityComponent:
self.config = config
# Look in config for Domain, Domain 2, Domain 3 etc and load them
tasks = []
for p_type, p_config in config_per_platform(config, self.domain):
tasks.append(self.async_setup_platform(p_type, p_config))
if tasks:
await asyncio.gather(*tasks)
self.hass.async_create_task(self.async_setup_platform(p_type, p_config))
# Generic discovery listener for loading platform dynamically
# Refer to: homeassistant.components.discovery.load_platform()
# Refer to: homeassistant.helpers.discovery.async_load_platform()
async def component_platform_discovered(
platform: str, info: Optional[Dict[str, Any]]
) -> None:

View File

@ -4,7 +4,7 @@ from contextvars import ContextVar
from datetime import datetime, timedelta
from logging import Logger
from types import ModuleType
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, cast
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional
from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.core import CALLBACK_TYPE, callback, split_entity_id, valid_entity_id
@ -240,12 +240,9 @@ class EntityPlatform:
) -> None:
"""Schedule adding entities for a single platform async."""
self._tasks.append(
cast(
asyncio.Future,
self.hass.async_add_job(
self.async_add_entities( # type: ignore
new_entities, update_before_add=update_before_add
),
self.hass.async_create_task(
self.async_add_entities(
new_entities, update_before_add=update_before_add
),
)
)

View File

@ -17,6 +17,7 @@ async def test_state(hass):
config = {"air_quality": {"platform": "demo"}}
assert await async_setup_component(hass, "air_quality", config)
await hass.async_block_till_done()
state = hass.states.get("air_quality.demo_air_quality_home")
assert state is not None
@ -29,6 +30,7 @@ async def test_attributes(hass):
config = {"air_quality": {"platform": "demo"}}
assert await async_setup_component(hass, "air_quality", config)
await hass.async_block_till_done()
state = hass.states.get("air_quality.demo_air_quality_office")
assert state is not None

View File

@ -111,8 +111,11 @@ async def test_migration(hass):
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
with patch("pyairvisual.api.API.nearest_city"):
with patch("pyairvisual.api.API.nearest_city"), patch.object(
hass.config_entries, "async_forward_entry_setup"
):
assert await async_setup_component(hass, DOMAIN, {DOMAIN: conf})
await hass.async_block_till_done()
config_entries = hass.config_entries.async_entries(DOMAIN)

View File

@ -55,19 +55,19 @@ def events(hass):
@pytest.fixture
def mock_camera(hass):
async def mock_camera(hass):
"""Initialize a demo camera platform."""
assert hass.loop.run_until_complete(
async_setup_component(hass, "camera", {camera.DOMAIN: {"platform": "demo"}})
assert await async_setup_component(
hass, "camera", {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
@pytest.fixture
def mock_stream(hass):
async def mock_stream(hass):
"""Initialize a demo camera platform with streaming."""
assert hass.loop.run_until_complete(
async_setup_component(hass, "stream", {"stream": {}})
)
assert await async_setup_component(hass, "stream", {"stream": {}})
await hass.async_block_till_done()
def test_create_api_message_defaults(hass):

View File

@ -116,6 +116,7 @@ async def _test_reconnect(hass, caplog, config):
patch_key
], patchers.PATCH_KEYGEN, patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
@ -187,6 +188,7 @@ async def _test_adb_shell_returns_none(hass, config):
patch_key
], patchers.PATCH_KEYGEN, patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
assert state is not None
@ -295,6 +297,7 @@ async def test_setup_with_adbkey(hass):
patch_key
], patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER, patchers.PATCH_ISFILE, patchers.PATCH_ACCESS:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
assert state is not None
@ -315,6 +318,7 @@ async def _test_sources(hass, config0):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
assert state is not None
@ -395,6 +399,7 @@ async def _test_exclude_sources(hass, config0, expected_sources):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
assert state is not None
@ -463,6 +468,7 @@ async def _test_select_source(hass, config0, source, expected_arg, method_patch)
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
assert state is not None
@ -666,6 +672,7 @@ async def _test_setup_fail(hass, config):
patch_key
], patchers.PATCH_KEYGEN, patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
await hass.helpers.entity_component.async_update_entity(entity_id)
state = hass.states.get(entity_id)
assert state is None
@ -698,6 +705,7 @@ async def test_setup_two_devices(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
for entity_id in ["media_player.android_tv", "media_player.fire_tv"]:
await hass.helpers.entity_component.async_update_entity(entity_id)
@ -714,6 +722,7 @@ async def test_setup_same_device_twice(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state is not None
@ -723,6 +732,7 @@ async def test_setup_same_device_twice(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
async def test_adb_command(hass):
@ -735,6 +745,7 @@ async def test_adb_command(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patch(
"androidtv.basetv.BaseTV.adb_shell", return_value=response
@ -762,6 +773,7 @@ async def test_adb_command_unicode_decode_error(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patch(
"androidtv.basetv.BaseTV.adb_shell",
@ -791,6 +803,7 @@ async def test_adb_command_key(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patch(
"androidtv.basetv.BaseTV.adb_shell", return_value=response
@ -819,6 +832,7 @@ async def test_adb_command_get_properties(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patch(
"androidtv.androidtv.AndroidTV.get_properties_dict", return_value=response
@ -844,6 +858,7 @@ async def test_update_lock_not_acquired(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patchers.patch_shell("")[patch_key]:
await hass.helpers.entity_component.async_update_entity(entity_id)
@ -877,6 +892,7 @@ async def test_download(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
# Failed download because path is not whitelisted
with patch("androidtv.basetv.BaseTV.adb_pull") as patch_pull:
@ -919,6 +935,7 @@ async def test_upload(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
# Failed upload because path is not whitelisted
with patch("androidtv.basetv.BaseTV.adb_push") as patch_push:
@ -959,6 +976,7 @@ async def test_androidtv_volume_set(hass):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patch(
"androidtv.basetv.BaseTV.set_volume_level", return_value=0.5
@ -984,6 +1002,7 @@ async def test_get_image(hass, hass_ws_client):
patch_key
], patchers.patch_shell("")[patch_key]:
assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER)
await hass.async_block_till_done()
with patchers.patch_shell("11")[patch_key]:
await hass.helpers.entity_component.async_update_entity(entity_id)

View File

@ -45,6 +45,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
self.hass.block_till_done()
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
state = self.hass.states.get("binary_sensor.test_binary")
assert state.attributes.get("observations")[0]["prob_given_true"] == 0.8
@ -75,6 +76,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
self.hass.block_till_done()
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
state = self.hass.states.get("binary_sensor.test_binary")
assert state.attributes.get("observations") == []
@ -107,6 +109,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", 4)
self.hass.block_till_done()
@ -173,6 +176,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", "on")
@ -227,6 +231,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", "on")
@ -281,6 +286,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", "on")
self.hass.block_till_done()
@ -318,6 +324,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", "off")
@ -401,6 +408,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", "on")
self.hass.block_till_done()
@ -452,6 +460,7 @@ class TestBayesianBinarySensor(unittest.TestCase):
}
assert setup_component(self.hass, "binary_sensor", config)
self.hass.block_till_done()
self.hass.states.set("sensor.test_monitored", "on")
self.hass.block_till_done()

View File

@ -104,6 +104,7 @@ async def test_if_state(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
sensor1 = platform.ENTITIES["battery"]
@ -180,6 +181,7 @@ async def test_if_fires_on_for_condition(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
sensor1 = platform.ENTITIES["battery"]

View File

@ -103,6 +103,7 @@ async def test_if_fires_on_state_change(hass, calls):
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
sensor1 = platform.ENTITIES["battery"]
@ -187,6 +188,7 @@ async def test_if_fires_on_state_change_with_for(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
sensor1 = platform.ENTITIES["battery"]

View File

@ -70,6 +70,7 @@ class TestBOMWeatherSensor(unittest.TestCase):
"""Test the setup with custom settings."""
with assert_setup_component(1, sensor.DOMAIN):
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
fake_entities = [
"bom_fake_feels_like_c",
@ -85,6 +86,7 @@ class TestBOMWeatherSensor(unittest.TestCase):
def test_sensor_values(self, mock_get):
"""Test retrieval of sensor values."""
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
weather = self.hass.states.get("sensor.bom_fake_weather").state
assert "Fine" == weather

View File

@ -19,6 +19,7 @@ BASE_CONFIG = {
async def test_smoke_test_setup_component(hass):
"""Smoke test for successfully set-up with default config."""
assert await async_setup_component(hass, sensor.DOMAIN, BASE_CONFIG)
await hass.async_block_till_done()
for cond in CONDITIONS:
state = hass.states.get(f"sensor.volkel_{cond}")

View File

@ -19,6 +19,7 @@ BASE_CONFIG = {
async def test_smoke_test_setup_component(hass):
"""Smoke test for successfully set-up with default config."""
assert await async_setup_component(hass, weather.DOMAIN, BASE_CONFIG)
await hass.async_block_till_done()
state = hass.states.get("weather.volkel")
assert state.state == "unknown"

View File

@ -8,6 +8,7 @@ import homeassistant.util.dt as dt_util
async def test_events_http_api(hass, hass_client):
"""Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done()
client = await hass_client()
response = await client.get("/api/calendars/calendar.calendar_2")
assert response.status == 400
@ -27,6 +28,7 @@ async def test_events_http_api(hass, hass_client):
async def test_calendars_http_api(hass, hass_client):
"""Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done()
client = await hass_client()
response = await client.get("/api/calendars")
assert response.status == 200

View File

@ -19,11 +19,12 @@ from tests.components.camera import common
@pytest.fixture(name="mock_camera")
def mock_camera_fixture(hass):
async def mock_camera_fixture(hass):
"""Initialize a demo camera platform."""
assert hass.loop.run_until_complete(
async_setup_component(hass, "camera", {camera.DOMAIN: {"platform": "demo"}})
assert await async_setup_component(
hass, "camera", {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
with patch(
"homeassistant.components.demo.camera.Path.read_bytes", return_value=b"Test",
@ -51,6 +52,7 @@ async def image_mock_url_fixture(hass):
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
async def test_get_image_from_camera(hass, image_mock_url):
@ -311,7 +313,10 @@ async def test_preload_stream(hass, mock_stream):
"homeassistant.components.demo.camera.DemoCamera.stream_source",
return_value="http://example.com",
):
await async_setup_component(hass, "camera", {DOMAIN: {"platform": "demo"}})
assert await async_setup_component(
hass, "camera", {DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
assert mock_request_stream.called

View File

@ -36,6 +36,7 @@ class TestCoinMarketCapSensor(unittest.TestCase):
"""Test the setup with custom settings."""
with assert_setup_component(1, sensor.DOMAIN):
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
state = self.hass.states.get("sensor.ethereum")
assert state is not None

View File

@ -68,6 +68,7 @@ async def test_state_value(hass):
)
is True
)
await hass.async_block_till_done()
assert "unknown" == hass.states.get("cover.test").state

View File

@ -43,6 +43,7 @@ class TestCommandSwitch(unittest.TestCase):
}
},
)
self.hass.block_till_done()
state = self.hass.states.get("switch.test")
assert STATE_OFF == state.state
@ -79,6 +80,7 @@ class TestCommandSwitch(unittest.TestCase):
}
},
)
self.hass.block_till_done()
state = self.hass.states.get("switch.test")
assert STATE_OFF == state.state
@ -117,6 +119,7 @@ class TestCommandSwitch(unittest.TestCase):
}
},
)
self.hass.block_till_done()
state = self.hass.states.get("switch.test")
assert STATE_OFF == state.state
@ -152,7 +155,7 @@ class TestCommandSwitch(unittest.TestCase):
}
},
)
self.hass.block_till_done()
state = self.hass.states.get("switch.test")
assert STATE_OFF == state.state

View File

@ -454,6 +454,7 @@ async def test_if_position(hass, calls):
platform.init()
ent = platform.ENTITIES[1]
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
assert await async_setup_component(
hass,
@ -557,6 +558,7 @@ async def test_if_tilt_position(hass, calls):
platform.init()
ent = platform.ENTITIES[2]
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
assert await async_setup_component(
hass,

View File

@ -464,6 +464,7 @@ async def test_if_fires_on_position(hass, calls):
platform.init()
ent = platform.ENTITIES[1]
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
assert await async_setup_component(
hass,
@ -586,6 +587,7 @@ async def test_if_fires_on_tilt_position(hass, calls):
platform.init()
ent = platform.ENTITIES[1]
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
assert await async_setup_component(
hass,

View File

@ -117,6 +117,7 @@ class TestDarkSkySetup(unittest.TestCase):
def test_setup_with_config(self):
"""Test the platform setup with configuration."""
setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
self.hass.block_till_done()
state = self.hass.states.get("sensor.dark_sky_summary")
assert state is not None
@ -124,6 +125,7 @@ class TestDarkSkySetup(unittest.TestCase):
def test_setup_with_invalid_config(self):
"""Test the platform setup with invalid configuration."""
setup_component(self.hass, "sensor", INVALID_CONFIG_MINIMAL)
self.hass.block_till_done()
state = self.hass.states.get("sensor.dark_sky_summary")
assert state is None
@ -135,6 +137,7 @@ class TestDarkSkySetup(unittest.TestCase):
def test_setup_with_language_config(self):
"""Test the platform setup with language configuration."""
setup_component(self.hass, "sensor", VALID_CONFIG_LANG_DE)
self.hass.block_till_done()
state = self.hass.states.get("sensor.dark_sky_summary")
assert state is not None
@ -142,6 +145,7 @@ class TestDarkSkySetup(unittest.TestCase):
def test_setup_with_invalid_language_config(self):
"""Test the platform setup with language configuration."""
setup_component(self.hass, "sensor", INVALID_CONFIG_LANG)
self.hass.block_till_done()
state = self.hass.states.get("sensor.dark_sky_summary")
assert state is None
@ -169,6 +173,7 @@ class TestDarkSkySetup(unittest.TestCase):
def test_setup_with_alerts_config(self):
"""Test the platform setup with alert configuration."""
setup_component(self.hass, "sensor", VALID_CONFIG_ALERTS)
self.hass.block_till_done()
state = self.hass.states.get("sensor.dark_sky_alerts")
assert state.state == "0"
@ -184,6 +189,7 @@ class TestDarkSkySetup(unittest.TestCase):
mock_req.get(re.compile(uri), text=load_fixture("darksky.json"))
assert setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
self.hass.block_till_done()
assert mock_get_forecast.called
assert mock_get_forecast.call_count == 1

View File

@ -43,6 +43,7 @@ class TestDarkSky(unittest.TestCase):
weather.DOMAIN,
{"weather": {"name": "test", "platform": "darksky", "api_key": "foo"}},
)
self.hass.block_till_done()
assert mock_get_forecast.called
assert mock_get_forecast.call_count == 1
@ -59,6 +60,7 @@ class TestDarkSky(unittest.TestCase):
weather.DOMAIN,
{"weather": {"name": "test", "platform": "darksky", "api_key": "foo"}},
)
self.hass.block_till_done()
state = self.hass.states.get("weather.test")
assert state.state == "unavailable"

View File

@ -22,13 +22,12 @@ ENTITY_CAMERA = "camera.demo_camera"
@pytest.fixture(autouse=True)
def demo_camera(hass):
async def demo_camera(hass):
"""Initialize a demo camera platform."""
hass.loop.run_until_complete(
async_setup_component(
hass, CAMERA_DOMAIN, {CAMERA_DOMAIN: {"platform": DOMAIN}}
)
assert await async_setup_component(
hass, CAMERA_DOMAIN, {CAMERA_DOMAIN: {"platform": DOMAIN}}
)
await hass.async_block_till_done()
async def test_init_state_is_streaming(hass):

View File

@ -43,6 +43,7 @@ async def setup_demo_climate(hass):
"""Initialize setup demo climate."""
hass.config.units = METRIC_SYSTEM
assert await async_setup_component(hass, DOMAIN, {"climate": {"platform": "demo"}})
await hass.async_block_till_done()
def test_setup_params(hass):

View File

@ -42,6 +42,7 @@ async def setup_comp(hass):
"""Set up demo cover component."""
with assert_setup_component(1, DOMAIN):
await async_setup_component(hass, DOMAIN, CONFIG)
await hass.async_block_till_done()
async def test_supported_features(hass, setup_comp):

View File

@ -16,11 +16,10 @@ def get_entity(hass):
@pytest.fixture(autouse=True)
def setup_comp(hass):
async def setup_comp(hass):
"""Initialize components."""
hass.loop.run_until_complete(
async_setup_component(hass, fan.DOMAIN, {"fan": {"platform": "demo"}})
)
assert await async_setup_component(hass, fan.DOMAIN, {"fan": {"platform": "demo"}})
await hass.async_block_till_done()
async def test_turn_on(hass):

View File

@ -24,11 +24,12 @@ ENTITY_LIGHT = "light.bed_light"
@pytest.fixture(autouse=True)
def setup_comp(hass):
async def setup_comp(hass):
"""Set up demo component."""
hass.loop.run_until_complete(
async_setup_component(hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": DOMAIN}})
assert await async_setup_component(
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": DOMAIN}}
)
await hass.async_block_till_done()
async def test_state_attributes(hass):

View File

@ -21,11 +21,12 @@ OPENABLE_LOCK = "lock.openable_lock"
@pytest.fixture(autouse=True)
def setup_comp(hass):
async def setup_comp(hass):
"""Set up demo component."""
hass.loop.run_until_complete(
async_setup_component(hass, LOCK_DOMAIN, {LOCK_DOMAIN: {"platform": DOMAIN}})
assert await async_setup_component(
hass, LOCK_DOMAIN, {LOCK_DOMAIN: {"platform": DOMAIN}}
)
await hass.async_block_till_done()
async def test_locking(hass):

View File

@ -29,6 +29,7 @@ async def test_source_select(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.attributes.get("source") == "dvd"
@ -47,6 +48,7 @@ async def test_clear_playlist(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
assert hass.states.is_state(TEST_ENTITY_ID, "playing")
await common.async_clear_playlist(hass, TEST_ENTITY_ID)
@ -58,6 +60,7 @@ async def test_volume_services(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
state = hass.states.get(TEST_ENTITY_ID)
assert state.attributes.get("volume_level") == 1.0
@ -95,6 +98,7 @@ async def test_turning_off_and_on(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
assert hass.states.is_state(TEST_ENTITY_ID, "playing")
await common.async_turn_off(hass, TEST_ENTITY_ID)
@ -114,6 +118,7 @@ async def test_playing_pausing(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
assert hass.states.is_state(TEST_ENTITY_ID, "playing")
await common.async_media_pause(hass, TEST_ENTITY_ID)
@ -134,6 +139,7 @@ async def test_prev_next_track(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
state = hass.states.get(TEST_ENTITY_ID)
assert state.attributes.get("media_track") == 1
@ -152,6 +158,7 @@ async def test_prev_next_track(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
ent_id = "media_player.lounge_room"
state = hass.states.get(ent_id)
assert state.attributes.get("media_episode") == 1
@ -170,6 +177,7 @@ async def test_play_media(hass):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
ent_id = "media_player.living_room"
state = hass.states.get(ent_id)
assert mp.SUPPORT_PLAY_MEDIA & state.attributes.get("supported_features") > 0
@ -192,6 +200,7 @@ async def test_seek(hass, mock_media_seek):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
ent_id = "media_player.living_room"
state = hass.states.get(ent_id)
assert state.attributes["supported_features"] & mp.SUPPORT_SEEK
@ -209,6 +218,7 @@ async def test_media_image_proxy(hass, hass_client):
assert await async_setup_component(
hass, mp.DOMAIN, {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
fake_picture_data = "test.test"

View File

@ -22,6 +22,7 @@ class TestDemoRemote(unittest.TestCase):
assert setup_component(
self.hass, remote.DOMAIN, {"remote": {"platform": "demo"}}
)
self.hass.block_till_done()
# pylint: disable=invalid-name
def tearDown(self):

View File

@ -6,11 +6,10 @@ from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True)
def setup_comp(hass):
async def setup_comp(hass):
"""Set up demo component."""
hass.loop.run_until_complete(
async_setup_component(hass, stt.DOMAIN, {"stt": {"platform": "demo"}})
)
assert await async_setup_component(hass, stt.DOMAIN, {"stt": {"platform": "demo"}})
await hass.async_block_till_done()
async def test_demo_settings(hass_client):

View File

@ -51,6 +51,7 @@ ENTITY_VACUUM_STATE = f"{DOMAIN}.{DEMO_VACUUM_STATE}".lower()
async def setup_demo_vacuum(hass):
"""Initialize setup demo vacuum."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "demo"}})
await hass.async_block_till_done()
async def test_supported_features(hass):

View File

@ -13,14 +13,13 @@ ENTITY_WATER_HEATER_CELSIUS = "water_heater.demo_water_heater_celsius"
@pytest.fixture(autouse=True)
def setup_comp(hass):
async def setup_comp(hass):
"""Set up demo component."""
hass.config.units = IMPERIAL_SYSTEM
hass.loop.run_until_complete(
async_setup_component(
hass, water_heater.DOMAIN, {"water_heater": {"platform": "demo"}}
)
assert await async_setup_component(
hass, water_heater.DOMAIN, {"water_heater": {"platform": "demo"}}
)
await hass.async_block_till_done()
async def test_setup_params(hass):

View File

@ -621,7 +621,7 @@ async def test_automation_with_sub_condition(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
assert await async_setup_component(

View File

@ -14,11 +14,13 @@ from homeassistant.components.device_tracker.const import DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_PLATFORM,
EVENT_HOMEASSISTANT_START,
STATE_HOME,
STATE_NOT_HOME,
STATE_OFF,
STATE_ON,
)
from homeassistant.core import CoreState
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
@ -214,3 +216,19 @@ async def test_lights_turn_on_when_coming_home_after_sun_set_person(hass, scanne
assert hass.states.get(device_1).state == "home"
assert hass.states.get(device_2).state == "home"
assert hass.states.get("person.me").state == "home"
async def test_initialize_start(hass):
"""Test we initialize when HA starts."""
hass.state = CoreState.not_running
assert await async_setup_component(
hass, device_sun_light_trigger.DOMAIN, {device_sun_light_trigger.DOMAIN: {}},
)
with patch(
"homeassistant.components.device_sun_light_trigger.activate_automation"
) as mock_activate:
hass.bus.fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
assert len(mock_activate.mock_calls) == 1

View File

@ -75,6 +75,7 @@ async def test_default_setup(hass, mock_connection_factory):
with assert_setup_component(1):
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
telegram_callback = connection_factory.call_args_list[0][0][2]
@ -171,6 +172,7 @@ async def test_v4_meter(hass, mock_connection_factory):
with assert_setup_component(1):
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
telegram_callback = connection_factory.call_args_list[0][0][2]
@ -215,6 +217,7 @@ async def test_v5_meter(hass, mock_connection_factory):
with assert_setup_component(1):
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
telegram_callback = connection_factory.call_args_list[0][0][2]
@ -259,6 +262,7 @@ async def test_belgian_meter(hass, mock_connection_factory):
with assert_setup_component(1):
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
telegram_callback = connection_factory.call_args_list[0][0][2]
@ -292,6 +296,7 @@ async def test_belgian_meter_low(hass, mock_connection_factory):
with assert_setup_component(1):
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
telegram_callback = connection_factory.call_args_list[0][0][2]
@ -315,6 +320,7 @@ async def test_tcp(hass, mock_connection_factory):
with assert_setup_component(1):
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
assert connection_factory.call_args_list[0][0][0] == "localhost"
assert connection_factory.call_args_list[0][0][1] == "1234"

View File

@ -38,6 +38,7 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
assert setup_component(
self.hass, "sensor", {"sensor": DTE_ENERGY_BRIDGE_CONFIG}
)
self.hass.block_till_done()
assert "0.411" == self.hass.states.get("sensor.current_energy_usage").state
@requests_mock.Mocker()
@ -50,6 +51,7 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
assert setup_component(
self.hass, "sensor", {"sensor": DTE_ENERGY_BRIDGE_CONFIG}
)
self.hass.block_till_done()
assert "0.411" == self.hass.states.get("sensor.current_energy_usage").state
@requests_mock.Mocker()
@ -62,4 +64,5 @@ class TestDteEnergyBridgeSetup(unittest.TestCase):
assert setup_component(
self.hass, "sensor", {"sensor": DTE_ENERGY_BRIDGE_CONFIG}
)
self.hass.block_till_done()
assert "unknown" == self.hass.states.get("sensor.current_energy_usage").state

View File

@ -85,6 +85,7 @@ class TestEfergySensor(unittest.TestCase):
"""Test for successfully setting up the Efergy platform."""
mock_responses(mock)
assert setup_component(self.hass, "sensor", {"sensor": ONE_SENSOR_CONFIG})
self.hass.block_till_done()
assert "38.21" == self.hass.states.get("sensor.energy_consumed").state
assert "1580" == self.hass.states.get("sensor.energy_usage").state
@ -97,6 +98,7 @@ class TestEfergySensor(unittest.TestCase):
"""Test for multiple sensors in one household."""
mock_responses(mock)
assert setup_component(self.hass, "sensor", {"sensor": MULTI_SENSOR_CONFIG})
self.hass.block_till_done()
assert "218" == self.hass.states.get("sensor.efergy_728386").state
assert "1808" == self.hass.states.get("sensor.efergy_0").state

View File

@ -156,6 +156,7 @@ def test_valid_file_path():
async def test_setup_platform(hass, mock_healthybox):
"""Set up platform with one entity."""
await async_setup_component(hass, ip.DOMAIN, VALID_CONFIG)
await hass.async_block_till_done()
assert hass.states.get(VALID_ENTITY_ID)
@ -166,12 +167,14 @@ async def test_setup_platform_with_auth(hass, mock_healthybox):
valid_config_auth[ip.DOMAIN][CONF_PASSWORD] = MOCK_PASSWORD
await async_setup_component(hass, ip.DOMAIN, valid_config_auth)
await hass.async_block_till_done()
assert hass.states.get(VALID_ENTITY_ID)
async def test_process_image(hass, mock_healthybox, mock_image):
"""Test successful processing of an image."""
await async_setup_component(hass, ip.DOMAIN, VALID_CONFIG)
await hass.async_block_till_done()
assert hass.states.get(VALID_ENTITY_ID)
face_events = []
@ -215,6 +218,7 @@ async def test_process_image(hass, mock_healthybox, mock_image):
async def test_process_image_errors(hass, mock_healthybox, mock_image, caplog):
"""Test process_image errors."""
await async_setup_component(hass, ip.DOMAIN, VALID_CONFIG)
await hass.async_block_till_done()
assert hass.states.get(VALID_ENTITY_ID)
# Test connection error.
@ -246,6 +250,7 @@ async def test_teach_service(
):
"""Test teaching of facebox."""
await async_setup_component(hass, ip.DOMAIN, VALID_CONFIG)
await hass.async_block_till_done()
assert hass.states.get(VALID_ENTITY_ID)
# Patch out 'is_allowed_path' as the mock files aren't allowed
@ -319,6 +324,7 @@ async def test_setup_platform_with_name(hass, mock_healthybox):
valid_config_named[ip.DOMAIN][ip.CONF_SOURCE][ip.CONF_NAME] = MOCK_NAME
await async_setup_component(hass, ip.DOMAIN, valid_config_named)
await hass.async_block_till_done()
assert hass.states.get(named_entity_id)
state = hass.states.get(named_entity_id)
assert state.attributes.get(CONF_FRIENDLY_NAME) == MOCK_NAME

View File

@ -76,6 +76,7 @@ async def test_fido_sensor(loop, hass):
}
with assert_setup_component(1):
await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
state = hass.states.get("sensor.fido_1112223344_balance")
assert state.state == "160.12"
assert state.attributes.get("number") == "1112223344"

View File

@ -42,6 +42,7 @@ class TestFileSensor(unittest.TestCase):
create_file(TEST_FILE)
config = {"sensor": {"platform": "filesize", CONF_FILE_PATHS: [TEST_FILE]}}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
assert len(self.hass.states.entity_ids()) == 1
state = self.hass.states.get("sensor.mock_file_test_filesize_txt")
assert state.state == "0.0"

View File

@ -59,6 +59,7 @@ class TestFilterSensor(unittest.TestCase):
}
with assert_setup_component(0):
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
def test_chain(self):
"""Test if filter chaining works."""
@ -77,6 +78,7 @@ class TestFilterSensor(unittest.TestCase):
with assert_setup_component(1, "sensor"):
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
for value in self.values:
self.hass.states.set(config["sensor"]["entity_id"], value.state)
@ -128,6 +130,7 @@ class TestFilterSensor(unittest.TestCase):
):
with assert_setup_component(1, "sensor"):
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
for value in self.values:
self.hass.states.set(config["sensor"]["entity_id"], value.state)
@ -176,6 +179,7 @@ class TestFilterSensor(unittest.TestCase):
):
with assert_setup_component(1, "sensor"):
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
self.hass.block_till_done()
state = self.hass.states.get("sensor.test")

View File

@ -36,7 +36,7 @@ async def test_valid_config(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.flux")
assert state
assert state.state == "off"
@ -57,6 +57,7 @@ async def test_restore_state_last_on(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.flux")
assert state
@ -78,6 +79,7 @@ async def test_restore_state_last_off(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.flux")
assert state
@ -129,6 +131,7 @@ async def test_flux_when_switch_is_off(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -178,6 +181,7 @@ async def test_flux_before_sunrise(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -231,6 +235,7 @@ async def test_flux_before_sunrise_known_location(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -284,6 +289,7 @@ async def test_flux_after_sunrise_before_sunset(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -337,6 +343,7 @@ async def test_flux_after_sunset_before_stop(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -391,6 +398,7 @@ async def test_flux_after_stop_before_sunrise(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -444,6 +452,7 @@ async def test_flux_with_custom_start_stop_times(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -501,6 +510,7 @@ async def test_flux_before_sunrise_stop_next_day(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -559,6 +569,7 @@ async def test_flux_after_sunrise_before_sunset_stop_next_day(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -617,6 +628,7 @@ async def test_flux_after_sunset_before_midnight_stop_next_day(hass, x):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -674,6 +686,7 @@ async def test_flux_after_sunset_after_midnight_stop_next_day(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -731,6 +744,7 @@ async def test_flux_after_stop_before_sunrise_stop_next_day(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -785,6 +799,7 @@ async def test_flux_with_custom_colortemps(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -841,6 +856,7 @@ async def test_flux_with_custom_brightness(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -895,6 +911,7 @@ async def test_flux_with_multiple_lights(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
@ -972,6 +989,7 @@ async def test_flux_with_mired(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]
@ -1023,6 +1041,7 @@ async def test_flux_with_rgb(hass):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
await hass.async_block_till_done()
ent1 = platform.ENTITIES[0]

View File

@ -48,6 +48,7 @@ class TestFolderSensor(unittest.TestCase):
create_file(TEST_FILE)
config = {"sensor": {"platform": "folder", CONF_FOLDER_PATHS: TEST_DIR}}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
assert len(self.hass.states.entity_ids()) == 1
state = self.hass.states.get("sensor.test_folder")
assert state.state == "0.0"

View File

@ -39,6 +39,7 @@ async def test_default_setup(hass, aioclient_mock):
re.compile("api.foobot.io/v2/device/.*"), text=load_fixture("foobot_data.json")
)
assert await async_setup_component(hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
await hass.async_block_till_done()
metrics = {
"co2": ["1232.0", CONCENTRATION_PARTS_PER_MILLION],

View File

@ -91,6 +91,7 @@ async def test_setup(hass):
) as mock_feed_update:
mock_feed_update.return_value = "OK", [mock_entry_1, mock_entry_2, mock_entry_3]
assert await async_setup_component(hass, gdacs.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update and collect events.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -213,6 +214,7 @@ async def test_setup_imperial(hass):
):
mock_feed_update.return_value = "OK", [mock_entry_1]
assert await async_setup_component(hass, gdacs.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update and collect events.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()

View File

@ -76,12 +76,11 @@ async def test_valid_conf(hass):
@pytest.fixture
def setup_comp_1(hass):
async def setup_comp_1(hass):
"""Initialize components."""
hass.config.units = METRIC_SYSTEM
assert hass.loop.run_until_complete(
async_setup_component(hass, "homeassistant", {})
)
assert await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done()
async def test_heater_input_boolean(hass, setup_comp_1):
@ -104,6 +103,7 @@ async def test_heater_input_boolean(hass, setup_comp_1):
}
},
)
await hass.async_block_till_done()
assert STATE_OFF == hass.states.get(heater_switch).state
@ -122,6 +122,7 @@ async def test_heater_switch(hass, setup_comp_1):
assert await async_setup_component(
hass, switch.DOMAIN, {"switch": {"platform": "test"}}
)
await hass.async_block_till_done()
heater_switch = switch_1.entity_id
assert await async_setup_component(
@ -154,27 +155,26 @@ def _setup_sensor(hass, temp):
@pytest.fixture
def setup_comp_2(hass):
async def setup_comp_2(hass):
"""Initialize components."""
hass.config.units = METRIC_SYSTEM
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"away_temp": 16,
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"away_temp": 16,
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
await hass.async_block_till_done()
async def test_setup_defaults_to_unknown(hass):
@ -195,6 +195,7 @@ async def test_setup_defaults_to_unknown(hass):
}
},
)
await hass.async_block_till_done()
assert HVAC_MODE_OFF == hass.states.get(ENTITY).state
@ -288,6 +289,7 @@ async def test_sensor_unknown(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.unknown")
assert state.attributes.get("current_temperature") is None
@ -307,6 +309,7 @@ async def test_sensor_unavailable(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.unavailable")
assert state.attributes.get("current_temperature") is None
@ -438,28 +441,27 @@ def _setup_switch(hass, is_on):
@pytest.fixture
def setup_comp_3(hass):
async def setup_comp_3(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"away_temp": 30,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"away_temp": 30,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_set_target_temp_ac_off(hass, setup_comp_3):
@ -584,28 +586,27 @@ async def test_no_state_change_when_operation_mode_off_2(hass, setup_comp_3):
@pytest.fixture
def setup_comp_4(hass):
async def setup_comp_4(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_not_long_enough(hass, setup_comp_4):
@ -695,28 +696,27 @@ async def test_mode_change_ac_trigger_on_not_long_enough(hass, setup_comp_4):
@pytest.fixture
def setup_comp_5(hass):
async def setup_comp_5(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5):
@ -806,27 +806,26 @@ async def test_mode_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5):
@pytest.fixture
def setup_comp_6(hass):
async def setup_comp_6(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_heater_trigger_off_not_long_enough(hass, setup_comp_6):
@ -916,31 +915,31 @@ async def test_mode_change_heater_trigger_on_not_long_enough(hass, setup_comp_6)
@pytest.fixture
def setup_comp_7(hass):
async def setup_comp_7(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_temp": 25,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_temp": 25,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_long_enough_3(hass, setup_comp_7):
"""Test if turn on signal is sent at keep-alive intervals."""
@ -994,29 +993,28 @@ def _send_time_changed(hass, now):
@pytest.fixture
def setup_comp_8(hass):
async def setup_comp_8(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_heater_trigger_on_long_enough_2(hass, setup_comp_8):
@ -1066,29 +1064,28 @@ async def test_temp_change_heater_trigger_off_long_enough_2(hass, setup_comp_8):
@pytest.fixture
def setup_comp_9(hass):
async def setup_comp_9(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_FAHRENHEIT
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"precision": 0.1,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"precision": 0.1,
}
},
)
await hass.async_block_till_done()
async def test_precision(hass, setup_comp_9):
@ -1116,6 +1113,7 @@ async def test_custom_setup_params(hass):
},
)
assert result
await hass.async_block_till_done()
state = hass.states.get(ENTITY)
assert state.attributes.get("min_temp") == MIN_TEMP
assert state.attributes.get("max_temp") == MAX_TEMP
@ -1150,7 +1148,7 @@ async def test_restore_state(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.test_thermostat")
assert state.attributes[ATTR_TEMPERATURE] == 20
assert state.attributes[ATTR_PRESET_MODE] == PRESET_AWAY
@ -1188,7 +1186,7 @@ async def test_no_restore_state(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.test_thermostat")
assert state.attributes[ATTR_TEMPERATURE] == 22
assert state.state == HVAC_MODE_OFF

View File

@ -73,6 +73,7 @@ async def test_setup(hass):
)
with assert_setup_component(1, geo_location.DOMAIN):
assert await async_setup_component(hass, geo_location.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
# Collect events.
@ -162,6 +163,7 @@ async def test_setup_with_custom_location(hass):
assert await async_setup_component(
hass, geo_location.DOMAIN, CONFIG_WITH_CUSTOM_LOCATION
)
await hass.async_block_till_done()
# Artificially trigger update.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
@ -198,6 +200,7 @@ async def test_setup_race_condition(hass):
) as mock_feed:
with assert_setup_component(1, geo_location.DOMAIN):
assert await async_setup_component(hass, geo_location.DOMAIN, CONFIG)
await hass.async_block_till_done()
mock_feed.return_value.update.return_value = "OK", [mock_entry_1]

View File

@ -67,6 +67,7 @@ async def test_setup(hass):
) as mock_feed_update:
mock_feed_update.return_value = "OK", [mock_entry_1, mock_entry_2, mock_entry_3]
assert await async_setup_component(hass, geonetnz_quakes.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update and collect events.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -172,6 +173,7 @@ async def test_setup_imperial(hass):
):
mock_feed_update.return_value = "OK", [mock_entry_1]
assert await async_setup_component(hass, geonetnz_quakes.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update and collect events.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()

View File

@ -289,6 +289,7 @@ async def test_query_message(hass):
async def test_execute(hass):
"""Test an execute command."""
await async_setup_component(hass, "light", {"light": {"platform": "demo"}})
await hass.async_block_till_done()
await hass.services.async_call(
"light", "turn_off", {"entity_id": "light.ceiling_lights"}, blocking=True

View File

@ -57,6 +57,7 @@ async def setup_comp(hass):
"""Set up group cover component."""
with assert_setup_component(2, DOMAIN):
await async_setup_component(hass, DOMAIN, CONFIG)
await hass.async_block_till_done()
async def test_attributes(hass):
@ -70,6 +71,7 @@ async def test_attributes(hass):
with assert_setup_component(1, DOMAIN):
await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(COVER_GROUP)
assert state.state == STATE_CLOSED

View File

@ -96,6 +96,7 @@ class TestHDDTempSensor(unittest.TestCase):
def test_hddtemp_min_config(self):
"""Test minimal hddtemp configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
self.hass.block_till_done()
entity = self.hass.states.all()[0].entity_id
state = self.hass.states.get(entity)
@ -118,6 +119,7 @@ class TestHDDTempSensor(unittest.TestCase):
def test_hddtemp_rename_config(self):
"""Test hddtemp configuration with different name."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_NAME)
self.hass.block_till_done()
entity = self.hass.states.all()[0].entity_id
state = self.hass.states.get(entity)
@ -130,6 +132,7 @@ class TestHDDTempSensor(unittest.TestCase):
def test_hddtemp_one_disk(self):
"""Test hddtemp one disk configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_ONE_DISK)
self.hass.block_till_done()
state = self.hass.states.get("sensor.hd_temperature_dev_sdd1")
@ -151,6 +154,7 @@ class TestHDDTempSensor(unittest.TestCase):
def test_hddtemp_wrong_disk(self):
"""Test hddtemp wrong disk configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_WRONG_DISK)
self.hass.block_till_done()
assert len(self.hass.states.all()) == 1
state = self.hass.states.get("sensor.hd_temperature_dev_sdx1")
@ -160,6 +164,7 @@ class TestHDDTempSensor(unittest.TestCase):
def test_hddtemp_multiple_disks(self):
"""Test hddtemp multiple disk configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_MULTIPLE_DISKS)
self.hass.block_till_done()
for sensor in [
"sensor.hd_temperature_dev_sda1",
@ -187,10 +192,12 @@ class TestHDDTempSensor(unittest.TestCase):
def test_hddtemp_host_refused(self):
"""Test hddtemp if host unreachable."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_HOST)
self.hass.block_till_done()
assert len(self.hass.states.all()) == 0
@patch("telnetlib.Telnet", new=TelnetMock)
def test_hddtemp_host_unreachable(self):
"""Test hddtemp if host unreachable."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_HOST_UNREACHABLE)
self.hass.block_till_done()
assert len(self.hass.states.all()) == 0

View File

@ -175,6 +175,7 @@ async def test_car(hass, requests_mock_car_disabled_response):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -236,6 +237,7 @@ async def test_traffic_mode_enabled(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -262,6 +264,7 @@ async def test_imperial(hass, requests_mock_car_disabled_response):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -293,6 +296,7 @@ async def test_route_mode_shortest(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -324,6 +328,7 @@ async def test_route_mode_fastest(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -347,6 +352,7 @@ async def test_truck(hass, requests_mock_truck_response):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -378,6 +384,7 @@ async def test_public_transport(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -428,6 +435,7 @@ async def test_public_transport_time_table(hass, requests_mock_credentials_check
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -478,6 +486,7 @@ async def test_pedestrian(hass, requests_mock_credentials_check):
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -529,6 +538,7 @@ async def test_bicycle(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -592,6 +602,7 @@ async def test_location_zone(hass, requests_mock_truck_response):
}
assert await async_setup_component(hass, "zone", zone_config)
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -631,6 +642,7 @@ async def test_location_sensor(hass, requests_mock_truck_response):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -679,6 +691,7 @@ async def test_location_person(hass, requests_mock_truck_response):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -727,6 +740,7 @@ async def test_location_device_tracker(hass, requests_mock_truck_response):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -761,6 +775,7 @@ async def test_location_device_tracker_added_after_update(
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -829,6 +844,7 @@ async def test_location_device_tracker_in_zone(
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -862,6 +878,7 @@ async def test_route_not_found(hass, requests_mock_credentials_check, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -885,7 +902,8 @@ async def test_pattern_origin(hass, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
assert len(caplog.records) == 1
await hass.async_block_till_done()
assert len(caplog.records) == 2
assert "invalid latitude" in caplog.text
@ -904,7 +922,8 @@ async def test_pattern_destination(hass, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
assert len(caplog.records) == 1
await hass.async_block_till_done()
assert len(caplog.records) == 2
assert "invalid latitude" in caplog.text
@ -935,6 +954,7 @@ async def test_invalid_credentials(hass, requests_mock, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
assert len(caplog.records) == 1
assert "Invalid credentials" in caplog.text
@ -964,6 +984,7 @@ async def test_attribution(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -992,6 +1013,7 @@ async def test_pattern_entity_state(hass, requests_mock_truck_response, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -1018,6 +1040,7 @@ async def test_pattern_entity_state_with_space(hass, requests_mock_truck_respons
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
async def test_delayed_update(hass, requests_mock_truck_response, caplog):
@ -1044,6 +1067,7 @@ async def test_delayed_update(hass, requests_mock_truck_response, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
assert await async_setup_component(hass, "sensor", sensor_config)
hass.states.async_set(
"sensor.origin", ",".join([TRUCK_ORIGIN_LATITUDE, TRUCK_ORIGIN_LONGITUDE])
@ -1084,6 +1108,7 @@ async def test_arrival(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -1121,6 +1146,7 @@ async def test_departure(hass, requests_mock_credentials_check):
}
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
@ -1147,7 +1173,8 @@ async def test_arrival_only_allowed_for_timetable(hass, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
assert len(caplog.records) == 1
await hass.async_block_till_done()
assert len(caplog.records) == 2
assert "[arrival] is an invalid option" in caplog.text
@ -1171,5 +1198,6 @@ async def test_exclusive_arrival_and_departure(hass, caplog):
}
}
assert await async_setup_component(hass, DOMAIN, config)
assert len(caplog.records) == 1
await hass.async_block_till_done()
assert len(caplog.records) == 2
assert "two or more values in the same group of exclusion" in caplog.text

View File

@ -45,6 +45,7 @@ class TestHistoryStatsSensor(unittest.TestCase):
}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
state = self.hass.states.get("sensor.test")
assert state.state == STATE_UNKNOWN

View File

@ -39,6 +39,7 @@ async def test_apply_service(hass):
"""Test the apply service."""
assert await async_setup_component(hass, "scene", {})
assert await async_setup_component(hass, "light", {"light": {"platform": "demo"}})
await hass.async_block_till_done()
assert await hass.services.async_call(
"scene", "apply", {"entities": {"light.bed_light": "off"}}, blocking=True
@ -83,6 +84,7 @@ async def test_create_service(hass, caplog):
"scene",
{"scene": {"name": "hallo_2", "entities": {"light.kitchen": "on"}}},
)
await hass.async_block_till_done()
assert hass.states.get("scene.hallo") is None
assert hass.states.get("scene.hallo_2") is not None
@ -155,6 +157,7 @@ async def test_create_service(hass, caplog):
async def test_snapshot_service(hass, caplog):
"""Test the snapshot option."""
assert await async_setup_component(hass, "scene", {"scene": {}})
await hass.async_block_till_done()
hass.states.async_set("light.my_light", "on", {"hs_color": (345, 75)})
assert hass.states.get("scene.hallo") is None
@ -212,6 +215,7 @@ async def test_snapshot_service(hass, caplog):
async def test_ensure_no_intersection(hass):
"""Test that entities and snapshot_entities do not overlap."""
assert await async_setup_component(hass, "scene", {"scene": {}})
await hass.async_block_till_done()
with pytest.raises(vol.MultipleInvalid) as ex:
assert await hass.services.async_call(
@ -245,6 +249,7 @@ async def test_scenes_with_entity(hass):
]
},
)
await hass.async_block_till_done()
assert sorted(ha_scene.scenes_with_entity(hass, "light.kitchen")) == [
"scene.scene_1",
@ -268,6 +273,7 @@ async def test_entities_in_scene(hass):
]
},
)
await hass.async_block_till_done()
for scene_id, entities in (
("scene.scene_1", ["light.kitchen"]),
@ -297,6 +303,7 @@ async def test_config(hass):
]
},
)
await hass.async_block_till_done()
icon = hass.states.get("scene.scene_icon")
assert icon is not None

View File

@ -123,6 +123,7 @@ async def test_camera_stream_source_configured(hass, run_driver, events):
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_id = "camera.demo_camera"
@ -227,6 +228,7 @@ async def test_camera_stream_source_configured_with_failing_ffmpeg(
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_id = "camera.demo_camera"
@ -271,6 +273,7 @@ async def test_camera_stream_source_found(hass, run_driver, events):
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_id = "camera.demo_camera"
@ -313,6 +316,7 @@ async def test_camera_stream_source_fails(hass, run_driver, events):
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_id = "camera.demo_camera"
@ -368,6 +372,7 @@ async def test_camera_stream_source_configured_and_copy_codec(hass, run_driver,
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_id = "camera.demo_camera"
@ -436,6 +441,7 @@ async def test_camera_streaming_fails_after_starting_ffmpeg(hass, run_driver, ev
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_id = "camera.demo_camera"
@ -505,6 +511,7 @@ async def test_camera_with_linked_motion_sensor(hass, run_driver, events):
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
motion_entity_id = "binary_sensor.motion"
hass.states.async_set(
@ -564,6 +571,7 @@ async def test_camera_with_a_missing_linked_motion_sensor(hass, run_driver, even
await async_setup_component(
hass, camera.DOMAIN, {camera.DOMAIN: {"platform": "demo"}}
)
await hass.async_block_till_done()
motion_entity_id = "binary_sensor.motion"
entity_id = "camera.demo_camera"
hass.states.async_set(entity_id, None)

View File

@ -103,6 +103,7 @@ async def test_setup(hass):
)
with assert_setup_component(1, geo_location.DOMAIN):
assert await async_setup_component(hass, geo_location.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
# Collect events.
@ -207,6 +208,7 @@ async def test_setup_with_custom_location(hass):
assert await async_setup_component(
hass, geo_location.DOMAIN, CONFIG_WITH_CUSTOM_LOCATION
)
await hass.async_block_till_done()
# Artificially trigger update.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)

View File

@ -59,6 +59,7 @@ class TestImageProcessing:
config = {ip.DOMAIN: {"platform": "test"}, "camera": {"platform": "demo"}}
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
state = self.hass.states.get("camera.demo_camera")
self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
@ -113,6 +114,7 @@ class TestImageProcessingAlpr:
new_callable=PropertyMock(return_value=False),
):
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
state = self.hass.states.get("camera.demo_camera")
self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
@ -218,6 +220,7 @@ class TestImageProcessingFace:
new_callable=PropertyMock(return_value=False),
):
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
state = self.hass.states.get("camera.demo_camera")
self.url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"

View File

@ -135,7 +135,7 @@ async def test_setup_configuration(hass):
weather.DOMAIN,
{"weather": {"name": "HomeTown", "platform": "ipma", "mode": "hourly"}},
)
await hass.async_block_till_done()
await hass.async_block_till_done()
state = hass.states.get("weather.hometown")
assert state.state == "rainy"
@ -182,7 +182,7 @@ async def test_daily_forecast(hass):
weather.DOMAIN,
{"weather": {"name": "HomeTown", "platform": "ipma", "mode": "daily"}},
)
await hass.async_block_till_done()
await hass.async_block_till_done()
state = hass.states.get("weather.hometown")
assert state.state == "rainy"
@ -208,7 +208,7 @@ async def test_hourly_forecast(hass):
weather.DOMAIN,
{"weather": {"name": "HomeTown", "platform": "ipma", "mode": "hourly"}},
)
await hass.async_block_till_done()
await hass.async_block_till_done()
state = hass.states.get("weather.hometown")
assert state.state == "rainy"

View File

@ -54,6 +54,7 @@ async def test_update_not_playing(hass, lastfm_network):
sensor.DOMAIN,
{"sensor": {"platform": "lastfm", "api_key": "secret-key", "users": ["test"]}},
)
await hass.async_block_till_done()
entity_id = "sensor.test"
@ -74,6 +75,7 @@ async def test_update_playing(hass, lastfm_network):
sensor.DOMAIN,
{"sensor": {"platform": "lastfm", "api_key": "secret-key", "users": ["test"]}},
)
await hass.async_block_till_done()
entity_id = "sensor.test"

View File

@ -203,6 +203,7 @@ async def test_action(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES

View File

@ -96,6 +96,7 @@ async def test_if_state(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
@ -173,6 +174,7 @@ async def test_if_fires_on_for_condition(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES

View File

@ -96,6 +96,7 @@ async def test_if_fires_on_state_change(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
@ -180,6 +181,7 @@ async def test_if_fires_on_state_change_with_for(hass, calls):
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES

View File

@ -123,6 +123,7 @@ class TestLight(unittest.TestCase):
assert setup_component(
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
self.hass.block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
@ -335,6 +336,7 @@ class TestLight(unittest.TestCase):
assert setup_component(
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
self.hass.block_till_done()
ent1, _, _ = platform.ENTITIES
@ -376,12 +378,13 @@ class TestLight(unittest.TestCase):
return real_open(path, *args, **kwargs)
profile_data = "id,x,y,brightness\ngroup.all_lights.default,.4,.6,99\n"
with mock.patch("os.path.isfile", side_effect=_mock_isfile):
with mock.patch("builtins.open", side_effect=_mock_open):
with mock_storage():
assert setup_component(
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
with mock.patch("os.path.isfile", side_effect=_mock_isfile), mock.patch(
"builtins.open", side_effect=_mock_open
), mock_storage():
assert setup_component(
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
self.hass.block_till_done()
ent, _, _ = platform.ENTITIES
common.turn_on(self.hass, ent.entity_id)
@ -413,12 +416,13 @@ class TestLight(unittest.TestCase):
+ "group.all_lights.default,.3,.5,200\n"
+ "light.ceiling_2.default,.6,.6,100\n"
)
with mock.patch("os.path.isfile", side_effect=_mock_isfile):
with mock.patch("builtins.open", side_effect=_mock_open):
with mock_storage():
assert setup_component(
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
with mock.patch("os.path.isfile", side_effect=_mock_isfile), mock.patch(
"builtins.open", side_effect=_mock_open
), mock_storage():
assert setup_component(
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
self.hass.block_till_done()
dev = next(
filter(lambda x: x.entity_id == "light.ceiling_2", platform.ENTITIES)
@ -434,6 +438,7 @@ async def test_light_context(hass, hass_admin_user):
platform = getattr(hass.components, "test.light")
platform.init()
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
await hass.async_block_till_done()
state = hass.states.get("light.ceiling")
assert state is not None
@ -457,6 +462,7 @@ async def test_light_turn_on_auth(hass, hass_admin_user):
platform = getattr(hass.components, "test.light")
platform.init()
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
await hass.async_block_till_done()
state = hass.states.get("light.ceiling")
assert state is not None
@ -481,6 +487,7 @@ async def test_light_brightness_step(hass):
entity.supported_features = light.SUPPORT_BRIGHTNESS
entity.brightness = 100
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
await hass.async_block_till_done()
state = hass.states.get(entity.entity_id)
assert state is not None
@ -515,6 +522,7 @@ async def test_light_brightness_pct_conversion(hass):
entity.supported_features = light.SUPPORT_BRIGHTNESS
entity.brightness = 100
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
await hass.async_block_till_done()
state = hass.states.get(entity.entity_id)
assert state is not None

View File

@ -25,6 +25,7 @@ async def test_loading_file(hass, hass_client):
}
},
)
await hass.async_block_till_done()
client = await hass_client()
@ -57,6 +58,7 @@ async def test_file_not_readable(hass, caplog):
}
},
)
await hass.async_block_till_done()
assert "Could not read" in caplog.text
assert "config_test" in caplog.text
@ -91,6 +93,7 @@ async def test_camera_content_type(hass, hass_client):
"camera",
{"camera": [cam_config_jpg, cam_config_png, cam_config_svg, cam_config_noext]},
)
await hass.async_block_till_done()
client = await hass_client()
@ -143,6 +146,7 @@ async def test_update_file_path(hass):
"file_path": "mock/path_2.jpg",
}
await async_setup_component(hass, "camera", {"camera": [camera_1, camera_2]})
await hass.async_block_till_done()
# Fetch state and check motion detection attribute
state = hass.states.get("camera.local_file")

View File

@ -28,6 +28,7 @@ class TestLondonAirSensor(unittest.TestCase):
"""Test for operational tube_state sensor with proper attributes."""
mock_req.get(URL, text=load_fixture("london_air.json"))
assert setup_component(self.hass, "sensor", {"sensor": self.config})
self.hass.block_till_done()
state = self.hass.states.get("sensor.merton")
assert state.state == "Low"

View File

@ -47,6 +47,7 @@ async def test_arm_home_no_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -73,6 +74,7 @@ async def test_arm_home_no_pending_when_code_not_req(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -98,6 +100,7 @@ async def test_arm_home_with_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -137,6 +140,7 @@ async def test_arm_home_with_invalid_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -162,6 +166,7 @@ async def test_arm_away_no_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -188,6 +193,7 @@ async def test_arm_away_no_pending_when_code_not_req(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -213,6 +219,7 @@ async def test_arm_home_with_template_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -239,6 +246,7 @@ async def test_arm_away_with_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -278,6 +286,7 @@ async def test_arm_away_with_invalid_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -303,6 +312,7 @@ async def test_arm_night_no_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -329,6 +339,7 @@ async def test_arm_night_no_pending_when_code_not_req(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -354,6 +365,7 @@ async def test_arm_night_with_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -398,6 +410,7 @@ async def test_arm_night_with_invalid_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -422,6 +435,7 @@ async def test_trigger_no_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -458,6 +472,7 @@ async def test_trigger_with_delay(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -500,6 +515,7 @@ async def test_trigger_zero_trigger_time(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -525,6 +541,7 @@ async def test_trigger_zero_trigger_time_with_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -550,6 +567,7 @@ async def test_trigger_with_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -602,6 +620,7 @@ async def test_trigger_with_unused_specific_delay(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -646,6 +665,7 @@ async def test_trigger_with_specific_delay(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -689,6 +709,7 @@ async def test_trigger_with_pending_and_delay(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -745,6 +766,7 @@ async def test_trigger_with_pending_and_specific_delay(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -798,6 +820,7 @@ async def test_armed_home_with_specific_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -830,6 +853,7 @@ async def test_armed_away_with_specific_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -862,6 +886,7 @@ async def test_armed_night_with_specific_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -896,6 +921,7 @@ async def test_trigger_with_specific_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -939,6 +965,7 @@ async def test_trigger_with_disarm_after_trigger(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -975,6 +1002,7 @@ async def test_trigger_with_zero_specific_trigger_time(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1001,6 +1029,7 @@ async def test_trigger_with_unused_zero_specific_trigger_time(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1036,6 +1065,7 @@ async def test_trigger_with_specific_trigger_time(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1072,6 +1102,7 @@ async def test_trigger_with_no_disarm_after_trigger(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1112,6 +1143,7 @@ async def test_back_to_back_trigger_with_no_disarm_after_trigger(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1164,6 +1196,7 @@ async def test_disarm_while_pending_trigger(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1203,6 +1236,7 @@ async def test_disarm_during_trigger_with_invalid_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1242,6 +1276,7 @@ async def test_disarm_with_template_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1278,6 +1313,7 @@ async def test_arm_custom_bypass_no_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1304,6 +1340,7 @@ async def test_arm_custom_bypass_no_pending_when_code_not_req(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1329,6 +1366,7 @@ async def test_arm_custom_bypass_with_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1368,6 +1406,7 @@ async def test_arm_custom_bypass_with_invalid_code(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1392,6 +1431,7 @@ async def test_armed_custom_bypass_with_specific_pending(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1428,6 +1468,7 @@ async def test_arm_away_after_disabled_disarmed(hass):
}
},
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -1499,6 +1540,7 @@ async def test_restore_armed_state(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert state
@ -1525,6 +1567,7 @@ async def test_restore_disarmed_state(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert state

View File

@ -86,6 +86,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -114,6 +115,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -141,6 +143,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -184,6 +187,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -211,6 +215,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -239,6 +244,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -266,6 +272,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -294,6 +301,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -337,6 +345,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -364,6 +373,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -392,6 +402,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -419,6 +430,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -468,6 +480,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -494,6 +507,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -535,6 +549,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -583,6 +598,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -610,6 +626,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -637,6 +654,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -693,6 +711,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -734,6 +753,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -762,6 +782,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -802,6 +823,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -842,6 +864,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -904,6 +927,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -949,6 +973,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -996,6 +1021,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1046,6 +1072,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1096,6 +1123,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1162,6 +1190,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1224,6 +1253,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1261,6 +1291,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1298,6 +1329,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1337,6 +1369,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1391,6 +1424,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1465,6 +1499,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1504,6 +1539,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1544,6 +1580,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1584,6 +1621,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1624,6 +1662,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
entity_id = "alarm_control_panel.test"
@ -1656,6 +1695,7 @@ class TestAlarmControlPanelManualMqtt(unittest.TestCase):
}
},
)
self.hass.block_till_done()
# Component should send disarmed alarm state on startup
self.hass.block_till_done()

View File

@ -45,6 +45,7 @@ async def test_get_image_http(hass, aiohttp_client):
await async_setup_component(
hass, "media_player", {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
state = hass.states.get("media_player.bedroom")
assert "entity_picture_local" not in state.attributes
@ -72,6 +73,7 @@ async def test_get_image_http_remote(hass, aiohttp_client):
await async_setup_component(
hass, "media_player", {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
state = hass.states.get("media_player.bedroom")
assert "entity_picture_local" in state.attributes

View File

@ -27,6 +27,17 @@ def mock_controller_client_1():
yield service_mock
@pytest.fixture(autouse=True)
def mock_setup():
"""Prevent setup."""
with patch(
"homeassistant.components.meteo_france.async_setup", return_value=True,
), patch(
"homeassistant.components.meteo_france.async_setup_entry", return_value=True,
):
yield
@pytest.fixture(name="client_2")
def mock_controller_client_2():
"""Mock a successful client."""

View File

@ -64,6 +64,7 @@ class TestMfiSensorSetup(unittest.TestCase):
config = dict(self.GOOD_CONFIG)
del config[self.THING]["port"]
assert setup_component(self.hass, self.COMPONENT.DOMAIN, config)
self.hass.block_till_done()
assert mock_client.call_count == 1
assert mock_client.call_args == mock.call(
"foo", "user", "pass", port=6443, use_tls=True, verify=True
@ -75,6 +76,7 @@ class TestMfiSensorSetup(unittest.TestCase):
config = dict(self.GOOD_CONFIG)
config[self.THING]["port"] = 6123
assert setup_component(self.hass, self.COMPONENT.DOMAIN, config)
self.hass.block_till_done()
assert mock_client.call_count == 1
assert mock_client.call_args == mock.call(
"foo", "user", "pass", port=6123, use_tls=True, verify=True
@ -88,6 +90,7 @@ class TestMfiSensorSetup(unittest.TestCase):
config[self.THING]["ssl"] = False
config[self.THING]["verify_ssl"] = False
assert setup_component(self.hass, self.COMPONENT.DOMAIN, config)
self.hass.block_till_done()
assert mock_client.call_count == 1
assert mock_client.call_args == mock.call(
"foo", "user", "pass", port=6080, use_tls=False, verify=False
@ -105,6 +108,7 @@ class TestMfiSensorSetup(unittest.TestCase):
mock.MagicMock(ports=ports)
]
assert setup_component(self.hass, sensor.DOMAIN, self.GOOD_CONFIG)
self.hass.block_till_done()
for ident, port in ports.items():
if ident != "bad":
mock_sensor.assert_any_call(port, self.hass)

View File

@ -48,6 +48,7 @@ class TestMfiSwitchSetup(unittest.TestCase):
mock.MagicMock(ports=ports)
]
assert setup_component(self.hass, switch.DOMAIN, self.GOOD_CONFIG)
self.hass.block_till_done()
for ident, port in ports.items():
if ident != "bad":
mock_switch.assert_any_call(port)

View File

@ -45,6 +45,7 @@ class TestMicrosoftFaceDetectSetup:
with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
assert self.hass.states.get("image_processing.microsoftface_demo_camera")
@ -65,6 +66,7 @@ class TestMicrosoftFaceDetectSetup:
with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
assert self.hass.states.get("image_processing.test_local")
@ -113,6 +115,7 @@ class TestMicrosoftFaceDetect:
)
setup_component(self.hass, ip.DOMAIN, self.config)
self.hass.block_till_done()
state = self.hass.states.get("camera.demo_camera")
url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"

View File

@ -45,6 +45,7 @@ class TestMicrosoftFaceIdentifySetup:
with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
assert self.hass.states.get("image_processing.microsoftface_demo_camera")
@ -66,6 +67,7 @@ class TestMicrosoftFaceIdentifySetup:
with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, config)
self.hass.block_till_done()
assert self.hass.states.get("image_processing.test_local")
@ -114,6 +116,7 @@ class TestMicrosoftFaceIdentify:
)
setup_component(self.hass, ip.DOMAIN, self.config)
self.hass.block_till_done()
state = self.hass.states.get("camera.demo_camera")
url = f"{self.hass.config.api.base_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"

View File

@ -97,6 +97,7 @@ async def test_restoring_location(hass, create_registrations, webhook_client):
# mobile app doesn't support unloading, so we just reload device tracker
await hass.config_entries.async_forward_entry_unload(config_entry, "device_tracker")
await hass.config_entries.async_forward_entry_setup(config_entry, "device_tracker")
await hass.async_block_till_done()
state_2 = hass.states.get("device_tracker.test_1_2")
assert state_2 is not None

View File

@ -69,6 +69,7 @@ async def run_test(
now = dt_util.utcnow()
with mock.patch("homeassistant.helpers.event.dt_util.utcnow", return_value=now):
assert await async_setup_component(hass, entity_domain, config)
await hass.async_block_till_done()
# Trigger update call with time_changed event
now += timedelta(seconds=scan_interval + 1)

View File

@ -52,7 +52,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
}
},
)
self.hass.block_till_done()
moldind = self.hass.states.get("sensor.mold_indicator")
assert moldind
assert UNIT_PERCENTAGE == moldind.attributes.get("unit_of_measurement")
@ -82,6 +82,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
}
},
)
self.hass.block_till_done()
self.hass.start()
self.hass.block_till_done()
moldind = self.hass.states.get("sensor.mold_indicator")
@ -116,6 +117,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
},
)
self.hass.block_till_done()
self.hass.start()
self.hass.block_till_done()
moldind = self.hass.states.get("sensor.mold_indicator")
@ -159,6 +161,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
}
},
)
self.hass.block_till_done()
self.hass.start()
self.hass.block_till_done()
moldind = self.hass.states.get("sensor.mold_indicator")
@ -196,6 +199,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
}
},
)
self.hass.block_till_done()
self.hass.start()
self.hass.states.set(
@ -268,6 +272,7 @@ class TestSensorMoldIndicator(unittest.TestCase):
}
},
)
self.hass.block_till_done()
self.hass.start()
self.hass.states.set(

View File

@ -29,6 +29,7 @@ class TestMoonSensor(unittest.TestCase):
config = {"sensor": {"platform": "moon", "name": "moon_day1"}}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
state = self.hass.states.get("sensor.moon_day1")
assert state.state == "waxing_crescent"
@ -39,6 +40,7 @@ class TestMoonSensor(unittest.TestCase):
config = {"sensor": {"platform": "moon", "name": "moon_day2"}}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
state = self.hass.states.get("sensor.moon_day2")
assert state.state == "waning_gibbous"

View File

@ -107,6 +107,7 @@ async def test_update_state_via_state_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -132,6 +133,7 @@ async def test_ignore_update_state_if_unknown_via_state_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@ -146,6 +148,7 @@ async def test_arm_home_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_arm_home(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -175,6 +178,7 @@ async def test_arm_home_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
config[alarm_control_panel.DOMAIN]["code_arm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_arm_home(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -187,6 +191,7 @@ async def test_arm_away_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_arm_away(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -216,6 +221,7 @@ async def test_arm_away_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
config[alarm_control_panel.DOMAIN]["code_arm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_arm_away(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -228,6 +234,7 @@ async def test_arm_night_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_arm_night(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -257,6 +264,7 @@ async def test_arm_night_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
config[alarm_control_panel.DOMAIN]["code_arm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_arm_night(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -278,6 +286,7 @@ async def test_arm_custom_bypass_publishes_mqtt(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await common.async_alarm_arm_custom_bypass(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -306,6 +315,7 @@ async def test_arm_custom_bypass_not_publishes_mqtt_with_invalid_code_when_req(
}
},
)
await hass.async_block_till_done()
call_count = mqtt_mock.async_publish.call_count
await common.async_alarm_arm_custom_bypass(hass, "abcd")
@ -331,6 +341,7 @@ async def test_arm_custom_bypass_publishes_mqtt_when_code_not_req(hass, mqtt_moc
}
},
)
await hass.async_block_till_done()
await common.async_alarm_arm_custom_bypass(hass)
mqtt_mock.async_publish.assert_called_once_with(
@ -343,6 +354,7 @@ async def test_disarm_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_disarm(hass)
mqtt_mock.async_publish.assert_called_once_with("alarm/command", "DISARM", 0, False)
@ -359,6 +371,7 @@ async def test_disarm_publishes_mqtt_with_template(hass, mqtt_mock):
'{"action":"{{ action }}",' '"code":"{{ code }}"}'
)
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_disarm(hass, 1234)
mqtt_mock.async_publish.assert_called_once_with(
@ -375,6 +388,7 @@ async def test_disarm_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config[alarm_control_panel.DOMAIN]["code"] = "1234"
config[alarm_control_panel.DOMAIN]["code_disarm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_disarm(hass)
mqtt_mock.async_publish.assert_called_once_with("alarm/command", "DISARM", 0, False)
@ -414,6 +428,7 @@ async def test_update_state_via_state_topic_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert state.state == STATE_UNKNOWN
@ -430,6 +445,7 @@ async def test_attributes_code_number(hass, mqtt_mock):
config[alarm_control_panel.DOMAIN]["code"] = CODE_NUMBER
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert (
@ -444,6 +460,7 @@ async def test_attributes_code_text(hass, mqtt_mock):
config[alarm_control_panel.DOMAIN]["code"] = CODE_TEXT
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert (

View File

@ -71,6 +71,7 @@ async def test_setting_sensor_value_expires_availability_topic(hass, mqtt_mock,
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNAVAILABLE
@ -99,6 +100,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
}
},
)
await hass.async_block_till_done()
# State should be unavailable since expire_after is defined and > 0
state = hass.states.get("binary_sensor.test")
@ -172,6 +174,7 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
@ -201,6 +204,7 @@ async def test_invalid_sensor_value_via_mqtt_message(hass, mqtt_mock, caplog):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
@ -240,6 +244,7 @@ async def test_setting_sensor_value_via_mqtt_message_and_template(hass, mqtt_moc
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.state == STATE_OFF
@ -267,6 +272,7 @@ async def test_valid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.attributes.get("device_class") == "motion"
@ -286,6 +292,7 @@ async def test_invalid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state is None
@ -327,6 +334,7 @@ async def test_force_update_disabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@ -362,6 +370,7 @@ async def test_force_update_enabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@ -398,6 +407,7 @@ async def test_off_delay(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []

View File

@ -49,6 +49,7 @@ async def test_run_camera_setup(hass, aiohttp_client):
"camera",
{"camera": {"platform": "mqtt", "topic": topic, "name": "Test Camera"}},
)
await hass.async_block_till_done()
url = hass.states.get("camera.test_camera").attributes["entity_picture"]

View File

@ -72,6 +72,7 @@ DEFAULT_CONFIG = {
async def test_setup_params(hass, mqtt_mock):
"""Test the initial parameters."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21
@ -85,6 +86,7 @@ async def test_setup_params(hass, mqtt_mock):
async def test_supported_features(hass, mqtt_mock):
"""Test the supported_features."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
support = (
@ -102,6 +104,7 @@ async def test_supported_features(hass, mqtt_mock):
async def test_get_hvac_modes(hass, mqtt_mock):
"""Test that the operation list returns the correct modes."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
modes = state.attributes.get("hvac_modes")
@ -121,6 +124,7 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
Also check the state.
"""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@ -136,6 +140,7 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
async def test_set_operation(hass, mqtt_mock):
"""Test setting of new operation mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@ -151,6 +156,7 @@ async def test_set_operation_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["mode_state_topic"] = "mode-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "unknown"
@ -173,6 +179,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["power_command_topic"] = "power-command"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@ -196,6 +203,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog):
"""Test setting fan mode without required attribute."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low"
@ -213,6 +221,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["fan_mode_state_topic"] = "fan-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") is None
@ -233,6 +242,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
async def test_set_fan_mode(hass, mqtt_mock):
"""Test setting of new fan mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low"
@ -245,6 +255,7 @@ async def test_set_fan_mode(hass, mqtt_mock):
async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
"""Test setting swing mode without required attribute."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off"
@ -262,6 +273,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["swing_mode_state_topic"] = "swing-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") is None
@ -282,6 +294,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
async def test_set_swing(hass, mqtt_mock):
"""Test setting of new swing mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off"
@ -294,6 +307,7 @@ async def test_set_swing(hass, mqtt_mock):
async def test_set_target_temperature(hass, mqtt_mock):
"""Test setting the target temperature."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21
@ -326,6 +340,7 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["temperature_state_topic"] = "temperature-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") is None
@ -346,6 +361,7 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
async def test_set_target_temperature_low_high(hass, mqtt_mock):
"""Test setting the low/high target temperature."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
@ -363,6 +379,7 @@ async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock):
config["climate"]["temperature_low_state_topic"] = "temperature-low-state"
config["climate"]["temperature_high_state_topic"] = "temperature-high-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("target_temp_low") is None
@ -398,6 +415,7 @@ async def test_receive_mqtt_temperature(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["current_temperature_topic"] = "current_temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "current_temperature", "47")
state = hass.states.get(ENTITY_CLIMATE)
@ -409,6 +427,7 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["away_mode_state_topic"] = "away-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -437,6 +456,7 @@ async def test_set_away_mode(hass, mqtt_mock):
config["climate"]["payload_off"] = "AUS"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -467,6 +487,7 @@ async def test_set_hvac_action(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["action_topic"] = "action"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hvac_action") is None
@ -481,6 +502,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["hold_state_topic"] = "hold-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hold_mode") is None
@ -501,6 +523,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
async def test_set_hold(hass, mqtt_mock):
"""Test setting the hold mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -525,6 +548,7 @@ async def test_set_hold(hass, mqtt_mock):
async def test_set_preset_mode_twice(hass, mqtt_mock):
"""Test setting of the same mode twice only publishes once."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -543,6 +567,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["aux_state_topic"] = "aux-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off"
@ -567,6 +592,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
async def test_set_aux(hass, mqtt_mock):
"""Test setting of the aux heating."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off"
@ -612,6 +638,7 @@ async def test_set_target_temperature_low_high_with_templates(hass, mqtt_mock, c
config["climate"]["temperature_high_state_template"] = "{{ value_json.temp_high }}"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
@ -658,6 +685,7 @@ async def test_set_with_templates(hass, mqtt_mock, caplog):
config["climate"]["current_temperature_topic"] = "current-temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
# Operation Mode
state = hass.states.get(ENTITY_CLIMATE)
@ -745,6 +773,7 @@ async def test_min_temp_custom(hass, mqtt_mock):
config["climate"]["min_temp"] = 26
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
min_temp = state.attributes.get("min_temp")
@ -759,6 +788,7 @@ async def test_max_temp_custom(hass, mqtt_mock):
config["climate"]["max_temp"] = 60
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
max_temp = state.attributes.get("max_temp")
@ -773,6 +803,7 @@ async def test_temp_step_custom(hass, mqtt_mock):
config["climate"]["temp_step"] = 0.01
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
temp_step = state.attributes.get("target_temp_step")
@ -788,6 +819,7 @@ async def test_temperature_unit(hass, mqtt_mock):
config["climate"]["current_temperature_topic"] = "current_temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "current_temperature", "77")
@ -945,6 +977,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock):
async def test_precision_default(hass, mqtt_mock):
"""Test that setting precision to tenths works as intended."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@ -959,6 +992,7 @@ async def test_precision_halves(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["precision"] = 0.5
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@ -973,6 +1007,7 @@ async def test_precision_whole(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["precision"] = 1.0
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE

View File

@ -39,6 +39,7 @@ async def help_test_availability_without_topic(hass, mqtt_mock, domain, config):
"""Test availability without defined availability topic."""
assert "availability_topic" not in config[domain]
assert await async_setup_component(hass, domain, config)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state.state != STATE_UNAVAILABLE
@ -61,6 +62,7 @@ async def help_test_default_availability_payload(
config = copy.deepcopy(config)
config[domain]["availability_topic"] = "availability-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state.state == STATE_UNAVAILABLE
@ -108,6 +110,7 @@ async def help_test_custom_availability_payload(
config[domain]["payload_available"] = "good"
config[domain]["payload_not_available"] = "nogood"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state.state == STATE_UNAVAILABLE
@ -147,6 +150,7 @@ async def help_test_setting_attribute_via_mqtt_json_message(
config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "attr-topic", '{ "val": "100" }')
state = hass.states.get(f"{domain}.test")
@ -164,6 +168,7 @@ async def help_test_setting_attribute_with_template(hass, mqtt_mock, domain, con
config[domain]["json_attributes_topic"] = "attr-topic"
config[domain]["json_attributes_template"] = "{{ value_json['Timer1'] | tojson }}"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(
hass, "attr-topic", json.dumps({"Timer1": {"Arm": 0, "Time": "22:18"}})
@ -185,6 +190,7 @@ async def help_test_update_with_json_attrs_not_dict(
config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "attr-topic", '[ "list", "of", "things"]')
state = hass.states.get(f"{domain}.test")
@ -204,6 +210,7 @@ async def help_test_update_with_json_attrs_bad_JSON(
config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "attr-topic", "This is not JSON")
@ -251,7 +258,8 @@ async def help_test_discovery_update_attr(hass, mqtt_mock, caplog, domain, confi
async def help_test_unique_id(hass, domain, config):
"""Test unique id option only creates one entity per unique_id."""
await async_mock_mqtt_component(hass)
assert await async_setup_component(hass, domain, config,)
assert await async_setup_component(hass, domain, config)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(domain)) == 1
@ -459,6 +467,7 @@ async def help_test_entity_id_update_subscriptions(
registry = mock_registry(hass, {})
mock_mqtt = await async_mock_mqtt_component(hass)
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state is not None

View File

@ -76,6 +76,7 @@ async def test_state_via_state_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -112,6 +113,7 @@ async def test_opening_and_closing_state_via_custom_state_payload(hass, mqtt_moc
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -152,6 +154,7 @@ async def test_open_closed_state_from_position_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -199,6 +202,7 @@ async def test_position_via_position_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -236,6 +240,7 @@ async def test_state_via_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -267,6 +272,7 @@ async def test_position_via_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -301,6 +307,7 @@ async def test_optimistic_state_change(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -358,6 +365,7 @@ async def test_optimistic_state_change_with_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -419,6 +427,7 @@ async def test_send_open_cover_command(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -447,6 +456,7 @@ async def test_send_close_cover_command(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -475,6 +485,7 @@ async def test_send_stop__cover_command(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@ -507,6 +518,7 @@ async def test_current_cover_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert not (ATTR_CURRENT_POSITION in state_attributes_dict)
@ -557,6 +569,7 @@ async def test_current_cover_position_inverted(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert not (ATTR_CURRENT_POSITION in state_attributes_dict)
@ -613,6 +626,7 @@ async def test_optimistic_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state is None
@ -638,6 +652,7 @@ async def test_position_update(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert not (ATTR_CURRENT_POSITION in state_attributes_dict)
@ -675,6 +690,7 @@ async def test_set_position_templated(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -706,6 +722,7 @@ async def test_set_position_untemplated(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -737,6 +754,7 @@ async def test_set_position_untemplated_custom_percentage_range(hass, mqtt_mock)
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -766,6 +784,7 @@ async def test_no_command_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("cover.test").attributes["supported_features"] == 240
@ -787,6 +806,7 @@ async def test_no_payload_stop(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("cover.test").attributes["supported_features"] == 3
@ -810,6 +830,7 @@ async def test_with_command_topic_and_tilt(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("cover.test").attributes["supported_features"] == 251
@ -834,6 +855,7 @@ async def test_tilt_defaults(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert ATTR_CURRENT_TILT_POSITION in state_attributes_dict
@ -864,6 +886,7 @@ async def test_tilt_via_invocation_defaults(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -943,6 +966,7 @@ async def test_tilt_given_value(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -1023,6 +1047,7 @@ async def test_tilt_given_value_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -1079,6 +1104,7 @@ async def test_tilt_given_value_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -1145,6 +1171,7 @@ async def test_tilt_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "0")
@ -1184,6 +1211,7 @@ async def test_tilt_via_topic_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "99")
@ -1222,6 +1250,7 @@ async def test_tilt_via_topic_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "0")
@ -1270,6 +1299,7 @@ async def test_tilt_via_topic_template_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "99")
@ -1313,6 +1343,7 @@ async def test_tilt_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -1348,6 +1379,7 @@ async def test_tilt_position_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@ -1738,6 +1770,7 @@ async def test_valid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.attributes.get("device_class") == "garage"
@ -1757,6 +1790,7 @@ async def test_invalid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state is None

View File

@ -50,6 +50,7 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, fan.DOMAIN, {fan.DOMAIN: {"platform": "mqtt", "name": "test"}}
)
await hass.async_block_till_done()
assert hass.states.get("fan.test") is None
@ -79,6 +80,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -141,6 +143,7 @@ async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -207,6 +210,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -300,6 +304,7 @@ async def test_on_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -352,6 +357,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -450,6 +456,7 @@ async def test_attributes(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -537,6 +544,7 @@ async def test_custom_speed_list(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@ -577,6 +585,7 @@ async def test_supported_features(hass, mqtt_mock):
]
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test1")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 0

View File

@ -76,6 +76,7 @@ async def test_default_supported_features(hass, mqtt_mock):
assert await async_setup_component(
hass, vacuum.DOMAIN, {vacuum.DOMAIN: DEFAULT_CONFIG}
)
await hass.async_block_till_done()
entity = hass.states.get("vacuum.mqtttest")
entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0)
assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted(
@ -99,6 +100,7 @@ async def test_all_commands(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await common.async_turn_on(hass, "vacuum.mqtttest")
mqtt_mock.async_publish.assert_called_once_with(
@ -178,6 +180,7 @@ async def test_commands_without_supported_features(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await common.async_turn_on(hass, "vacuum.mqtttest")
mqtt_mock.async_publish.assert_not_called()
@ -225,6 +228,7 @@ async def test_attributes_without_supported_features(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@ -250,6 +254,7 @@ async def test_status(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@ -289,6 +294,7 @@ async def test_status_battery(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54
@ -306,6 +312,7 @@ async def test_status_cleaning(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"cleaning": true
@ -323,6 +330,7 @@ async def test_status_docked(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"docked": true
@ -340,6 +348,7 @@ async def test_status_charging(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"charging": true
@ -357,6 +366,7 @@ async def test_status_fan_speed(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"fan_speed": "max"
@ -374,6 +384,7 @@ async def test_status_fan_speed_list(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == ["min", "medium", "high", "max"]
@ -391,6 +402,7 @@ async def test_status_no_fan_speed_list(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
@ -404,6 +416,7 @@ async def test_status_error(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"error": "Error1"
@ -434,6 +447,7 @@ async def test_battery_template(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "retroroomba/battery_level", "54")
state = hass.states.get("vacuum.mqtttest")
@ -449,6 +463,7 @@ async def test_status_invalid_json(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
state = hass.states.get("vacuum.mqtttest")
@ -462,6 +477,7 @@ async def test_missing_battery_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_BATTERY_LEVEL_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@ -473,6 +489,7 @@ async def test_missing_charging_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_CHARGING_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@ -484,6 +501,7 @@ async def test_missing_cleaning_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_CLEANING_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@ -495,6 +513,7 @@ async def test_missing_docked_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_DOCKED_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@ -506,6 +525,7 @@ async def test_missing_error_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_ERROR_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@ -517,6 +537,7 @@ async def test_missing_fan_speed_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_FAN_SPEED_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None

View File

@ -201,6 +201,7 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {"platform": "mqtt", "name": "test"}}
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
@ -218,6 +219,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(hass, mqt
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -269,6 +271,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -365,6 +368,7 @@ async def test_invalid_state_via_topic(hass, mqtt_mock, caplog):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -456,6 +460,7 @@ async def test_brightness_controlling_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -501,6 +506,7 @@ async def test_brightness_from_rgb_controlling_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -540,6 +546,7 @@ async def test_white_value_controlling_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -599,6 +606,7 @@ async def test_controlling_state_via_topic_with_templates(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -676,6 +684,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
):
with assert_setup_component(1, light.DOMAIN):
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@ -751,6 +760,7 @@ async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -786,6 +796,7 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -818,6 +829,7 @@ async def test_show_brightness_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -843,6 +855,7 @@ async def test_show_color_temp_only_if_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -868,6 +881,7 @@ async def test_show_effect_only_if_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -893,6 +907,7 @@ async def test_show_hs_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -918,6 +933,7 @@ async def test_show_white_value_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -943,6 +959,7 @@ async def test_show_xy_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -968,6 +985,7 @@ async def test_on_command_first(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1002,6 +1020,7 @@ async def test_on_command_last(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1038,6 +1057,7 @@ async def test_on_command_brightness(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1091,6 +1111,7 @@ async def test_on_command_brightness_scaled(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1153,6 +1174,7 @@ async def test_on_command_rgb(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1243,6 +1265,7 @@ async def test_on_command_rgb_template(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1279,6 +1302,7 @@ async def test_effect(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1498,6 +1522,7 @@ async def test_max_mireds(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153

View File

@ -156,6 +156,7 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
light.DOMAIN,
{light.DOMAIN: {"platform": "mqtt", "schema": "json", "name": "test"}},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
@ -174,6 +175,7 @@ async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -222,6 +224,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -346,6 +349,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@ -457,6 +461,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -519,6 +524,7 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -572,6 +578,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -641,6 +648,7 @@ async def test_sending_rgb_color_with_scaled_brightness(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -709,6 +717,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -771,6 +780,7 @@ async def test_effect(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -830,6 +840,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -869,6 +880,7 @@ async def test_transition(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -916,6 +928,7 @@ async def test_brightness_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -959,6 +972,7 @@ async def test_invalid_values(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -1235,6 +1249,7 @@ async def test_max_mireds(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153

View File

@ -84,6 +84,7 @@ async def test_setup_fails(hass, mqtt_mock):
light.DOMAIN,
{light.DOMAIN: {"platform": "mqtt", "schema": "template", "name": "test"}},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
with assert_setup_component(0, light.DOMAIN):
@ -99,6 +100,7 @@ async def test_setup_fails(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
with assert_setup_component(0, light.DOMAIN):
@ -115,6 +117,7 @@ async def test_setup_fails(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
with assert_setup_component(0, light.DOMAIN):
@ -131,6 +134,7 @@ async def test_setup_fails(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
@ -159,6 +163,7 @@ async def test_state_change_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -214,6 +219,7 @@ async def test_state_brightness_color_effect_temp_white_change_via_topic(
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -313,6 +319,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@ -454,6 +461,7 @@ async def test_sending_mqtt_commands_non_optimistic_brightness_template(
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -567,6 +575,7 @@ async def test_effect(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -617,6 +626,7 @@ async def test_flash(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -664,6 +674,7 @@ async def test_transition(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -719,6 +730,7 @@ async def test_invalid_values(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@ -994,6 +1006,7 @@ async def test_max_mireds(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153

View File

@ -58,6 +58,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@ -92,6 +93,7 @@ async def test_controlling_non_default_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@ -127,6 +129,7 @@ async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@ -163,6 +166,7 @@ async def test_controlling_non_default_state_via_topic_and_json_message(
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@ -195,6 +199,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@ -240,6 +245,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED

View File

@ -64,6 +64,7 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "test-topic", "100")
state = hass.states.get("sensor.test")
@ -88,6 +89,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert state.state == "unknown"
@ -155,6 +157,7 @@ async def test_setting_sensor_value_via_mqtt_json_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "test-topic", '{ "val": "100" }')
state = hass.states.get("sensor.test")
@ -176,6 +179,7 @@ async def test_force_update_disabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@ -209,6 +213,7 @@ async def test_force_update_enabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@ -262,6 +267,7 @@ async def test_invalid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert state is None

View File

@ -82,6 +82,7 @@ async def test_default_supported_features(hass, mqtt_mock):
assert await async_setup_component(
hass, vacuum.DOMAIN, {vacuum.DOMAIN: DEFAULT_CONFIG}
)
await hass.async_block_till_done()
entity = hass.states.get("vacuum.mqtttest")
entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0)
assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted(
@ -97,6 +98,7 @@ async def test_all_commands(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True
@ -168,6 +170,7 @@ async def test_commands_without_supported_features(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True
@ -223,6 +226,7 @@ async def test_status(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@ -260,6 +264,7 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@ -309,6 +314,7 @@ async def test_status_invalid_json(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
state = hass.states.get("vacuum.mqtttest")

View File

@ -59,6 +59,7 @@ async def test_controlling_state_via_topic(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
@ -97,6 +98,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_ON
@ -137,6 +139,7 @@ async def test_controlling_state_via_topic_and_json_message(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
@ -213,6 +216,7 @@ async def test_custom_state_payload(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF

View File

@ -68,6 +68,7 @@ async def test_room_update(hass):
}
},
)
await hass.async_block_till_done()
await send_message(hass, BEDROOM_TOPIC, FAR_MESSAGE)
await assert_state(hass, BEDROOM)

View File

@ -49,6 +49,7 @@ async def assert_setup_sensor(hass, config, count=1):
"""Set up the sensor and assert it's been created."""
with assert_setup_component(count):
assert await async_setup_component(hass, sensor.DOMAIN, config)
await hass.async_block_till_done()
@pytest.fixture

View File

@ -92,6 +92,7 @@ class TestNSWFuelStation(unittest.TestCase):
"""Test the setup with custom settings."""
with assert_setup_component(1, sensor.DOMAIN):
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
fake_entities = ["my_fake_station_p95", "my_fake_station_e10"]
@ -106,6 +107,7 @@ class TestNSWFuelStation(unittest.TestCase):
def test_sensor_values(self):
"""Test retrieval of sensor values."""
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
assert "140.0" == self.hass.states.get("sensor.my_fake_station_e10").state
assert "150.0" == self.hass.states.get("sensor.my_fake_station_p95").state

View File

@ -126,6 +126,7 @@ async def test_setup(hass):
)
with assert_setup_component(1, geo_location.DOMAIN):
assert await async_setup_component(hass, geo_location.DOMAIN, CONFIG)
await hass.async_block_till_done()
# Artificially trigger update.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
# Collect events.
@ -242,6 +243,7 @@ async def test_setup_with_custom_location(hass):
assert await async_setup_component(
hass, geo_location.DOMAIN, CONFIG_WITH_CUSTOM_LOCATION
)
await hass.async_block_till_done()
# Artificially trigger update.
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)

Some files were not shown because too many files have changed in this diff Show More