diff --git a/tests/components/shelly/__init__.py b/tests/components/shelly/__init__.py index 8ded53a6f583..4b79fe9b79db 100644 --- a/tests/components/shelly/__init__.py +++ b/tests/components/shelly/__init__.py @@ -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 diff --git a/tests/components/shelly/test_binary_sensor.py b/tests/components/shelly/test_binary_sensor.py index 695e0a11eb23..1b02f3f8d631 100644 --- a/tests/components/shelly/test_binary_sensor.py +++ b/tests/components/shelly/test_binary_sensor.py @@ -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 diff --git a/tests/components/shelly/test_button.py b/tests/components/shelly/test_button.py index a32ab642df08..5f40221488bd 100644 --- a/tests/components/shelly/test_button.py +++ b/tests/components/shelly/test_button.py @@ -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 diff --git a/tests/components/shelly/test_update.py b/tests/components/shelly/test_update.py index 8007ecc36153..5890bd06aecb 100644 --- a/tests/components/shelly/test_update.py +++ b/tests/components/shelly/test_update.py @@ -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