diff --git a/tests/components/shelly/test_binary_sensor.py b/tests/components/shelly/test_binary_sensor.py index 1b02f3f8d631bd..9fe05b75bb0d80 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, patch +from unittest.mock import AsyncMock, Mock, patch from aioshelly.const import ( MODEL_BLU_GATEWAY_G3, @@ -336,7 +336,12 @@ 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) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): config_entry = await init_integration(hass, 2, sleep_period=1000) # Sensor should be created when device is online @@ -378,7 +383,12 @@ 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) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE) # Sensor should be created when device is online diff --git a/tests/components/shelly/test_button.py b/tests/components/shelly/test_button.py index 5f40221488bd11..c82e71eacccf54 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, patch +from unittest.mock import AsyncMock, 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,12 @@ 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) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE) # Sensor should be created when device is online diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index d1cb61dd8dc63c..391b85b35c079d 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -2758,8 +2758,14 @@ async def test_zeroconf_sleeping_device_not_triggers_refresh( }, ) entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done(wait_background_tasks=True) mock_rpc_device.mock_online() await hass.async_block_till_done(wait_background_tasks=True) @@ -2811,10 +2817,14 @@ async def test_zeroconf_sleeping_device_attempts_configure( }, ) entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - mock_rpc_device.mock_disconnected() - await hass.async_block_till_done() + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done(wait_background_tasks=True) mock_rpc_device.mock_online() await hass.async_block_till_done(wait_background_tasks=True) @@ -2877,10 +2887,14 @@ async def test_zeroconf_sleeping_device_attempts_configure_ws_disabled( }, ) entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - mock_rpc_device.mock_disconnected() - await hass.async_block_till_done() + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done(wait_background_tasks=True) mock_rpc_device.mock_online() await hass.async_block_till_done(wait_background_tasks=True) @@ -2943,10 +2957,14 @@ async def test_zeroconf_sleeping_device_attempts_configure_no_url_available( }, ) entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - mock_rpc_device.mock_disconnected() - await hass.async_block_till_done() + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done(wait_background_tasks=True) mock_rpc_device.mock_online() await hass.async_block_till_done(wait_background_tasks=True) diff --git a/tests/components/shelly/test_coordinator.py b/tests/components/shelly/test_coordinator.py index d0d41dda76b7e7..19dd50edb2cfa0 100644 --- a/tests/components/shelly/test_coordinator.py +++ b/tests/components/shelly/test_coordinator.py @@ -1099,8 +1099,14 @@ async def test_rpc_sleeping_device_late_setup( register_device(device_registry, entry) monkeypatch.setattr(mock_rpc_device, "connected", False) monkeypatch.setattr(mock_rpc_device, "initialized", False) - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done(wait_background_tasks=True) monkeypatch.setattr(mock_rpc_device, "initialized", True) mock_rpc_device.mock_online() diff --git a/tests/components/shelly/test_update.py b/tests/components/shelly/test_update.py index 5890bd06aecb29..f418b7a34a9f61 100644 --- a/tests/components/shelly/test_update.py +++ b/tests/components/shelly/test_update.py @@ -420,7 +420,12 @@ async def test_rpc_sleeping_update( }, ) entity_id = f"{UPDATE_DOMAIN}.test_name_firmware" - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + with patch.object( + mock_rpc_device, + "initialize", + new_callable=AsyncMock, + side_effect=DeviceConnectionError, + ): await init_integration(hass, 2, sleep_period=1000) # Entity should be created when device is online