mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 15:31:52 -05:00
Wait for background tasks in shelly tests (#169301)
This commit is contained in:
@@ -67,7 +67,7 @@ async def init_integration(
|
||||
|
||||
if not skip_setup:
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
return entry
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for Shelly binary sensor platform."""
|
||||
|
||||
from copy import deepcopy
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aioshelly.const import (
|
||||
MODEL_BLU_GATEWAY_G3,
|
||||
@@ -10,6 +10,7 @@ from aioshelly.const import (
|
||||
MODEL_MOTION,
|
||||
MODEL_PLUS_SMOKE,
|
||||
)
|
||||
from aioshelly.exceptions import DeviceConnectionError
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
@@ -335,7 +336,8 @@ async def test_rpc_sleeping_binary_sensor(
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_cloud"
|
||||
monkeypatch.setattr(mock_rpc_device, "connected", False)
|
||||
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 1000)
|
||||
config_entry = await init_integration(hass, 2, sleep_period=1000)
|
||||
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
|
||||
config_entry = await init_integration(hass, 2, sleep_period=1000)
|
||||
|
||||
# Sensor should be created when device is online
|
||||
assert hass.states.get(entity_id) is None
|
||||
@@ -376,7 +378,8 @@ async def test_rpc_sleeping_binary_sensor_with_channel_name(
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_test_channel_name_smoke"
|
||||
monkeypatch.setattr(mock_rpc_device, "connected", False)
|
||||
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 1000)
|
||||
await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE)
|
||||
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
|
||||
await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE)
|
||||
|
||||
# Sensor should be created when device is online
|
||||
assert hass.states.get(entity_id) is None
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for Shelly button platform."""
|
||||
|
||||
from copy import deepcopy
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aioshelly.const import MODEL_BLU_GATEWAY_G3, MODEL_PLUS_SMOKE, MODEL_WALL_DISPLAY
|
||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
|
||||
@@ -494,7 +494,8 @@ async def test_rpc_smoke_mute_alarm_button(
|
||||
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 1000)
|
||||
monkeypatch.setattr(mock_rpc_device, "config", {"smoke:0": {"id": 0, "name": None}})
|
||||
monkeypatch.setattr(mock_rpc_device, "connected", False)
|
||||
await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE)
|
||||
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
|
||||
await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE)
|
||||
|
||||
# Sensor should be created when device is online
|
||||
assert hass.states.get(entity_id) is None
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Tests for Shelly update platform."""
|
||||
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
@@ -420,7 +420,8 @@ async def test_rpc_sleeping_update(
|
||||
},
|
||||
)
|
||||
entity_id = f"{UPDATE_DOMAIN}.test_name_firmware"
|
||||
await init_integration(hass, 2, sleep_period=1000)
|
||||
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
|
||||
await init_integration(hass, 2, sleep_period=1000)
|
||||
|
||||
# Entity should be created when device is online
|
||||
assert hass.states.get(entity_id) is None
|
||||
|
||||
Reference in New Issue
Block a user