From 8ac859f2538e2320657d9eaa607abe7fb9fef223 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:45:26 +0000 Subject: [PATCH 1/4] Fix more Shelly tests for Python 3.14.3 --- tests/components/shelly/test_config_flow.py | 28 ++++++++++----------- tests/components/shelly/test_coordinator.py | 5 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index d1cb61dd8dc63..5614253757902 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -2758,8 +2758,9 @@ 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", 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 +2812,11 @@ 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", side_effect=DeviceConnectionError): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done(wait_background_tasks=True) + + assert "Error connecting to Shelly device" in caplog.text mock_rpc_device.mock_online() await hass.async_block_till_done(wait_background_tasks=True) @@ -2877,10 +2879,9 @@ 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", 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 +2944,9 @@ 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", 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 d0d41dda76b7e..6013111a2007d 100644 --- a/tests/components/shelly/test_coordinator.py +++ b/tests/components/shelly/test_coordinator.py @@ -1099,8 +1099,9 @@ 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", 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() From d060b2b47b507539111f7ead1db9c1661045de21 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:47:16 +0200 Subject: [PATCH 2/4] Apply suggestion from @epenet --- tests/components/shelly/test_config_flow.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index 5614253757902..6fe896318f67f 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -2816,8 +2816,6 @@ async def test_zeroconf_sleeping_device_attempts_configure( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done(wait_background_tasks=True) - assert "Error connecting to Shelly device" in caplog.text - mock_rpc_device.mock_online() await hass.async_block_till_done(wait_background_tasks=True) From c4b5f9cf8f2c66a3c316ca1f1d6a778ecaa9aaf9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:08:42 +0000 Subject: [PATCH 3/4] Update --- tests/components/shelly/test_config_flow.py | 28 ++++++++++++++++++--- tests/components/shelly/test_coordinator.py | 7 +++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index 6fe896318f67f..391b85b35c079 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -2758,7 +2758,12 @@ async def test_zeroconf_sleeping_device_not_triggers_refresh( }, ) entry.add_to_hass(hass) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + 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) @@ -2812,7 +2817,12 @@ async def test_zeroconf_sleeping_device_attempts_configure( }, ) entry.add_to_hass(hass) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + 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) @@ -2877,7 +2887,12 @@ async def test_zeroconf_sleeping_device_attempts_configure_ws_disabled( }, ) entry.add_to_hass(hass) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + 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) @@ -2942,7 +2957,12 @@ async def test_zeroconf_sleeping_device_attempts_configure_no_url_available( }, ) entry.add_to_hass(hass) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + 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) diff --git a/tests/components/shelly/test_coordinator.py b/tests/components/shelly/test_coordinator.py index 6013111a2007d..19dd50edb2cfa 100644 --- a/tests/components/shelly/test_coordinator.py +++ b/tests/components/shelly/test_coordinator.py @@ -1099,7 +1099,12 @@ 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) - with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError): + 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) From 0b604ff0af6eaed557e3026d1e9e5667d501accc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:09:44 +0000 Subject: [PATCH 4/4] Update --- tests/components/shelly/test_binary_sensor.py | 16 +++++++++++++--- tests/components/shelly/test_button.py | 9 +++++++-- tests/components/shelly/test_update.py | 7 ++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/components/shelly/test_binary_sensor.py b/tests/components/shelly/test_binary_sensor.py index 1b02f3f8d631b..9fe05b75bb0d8 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 5f40221488bd1..c82e71eacccf5 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_update.py b/tests/components/shelly/test_update.py index 5890bd06aecb2..f418b7a34a9f6 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