From 7f4b56104d9fe2f2ad779aa75ab2b692a5f0ea7f Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Fri, 28 Nov 2025 11:32:41 +0200 Subject: [PATCH] Update Shelly utils coverage to 100% (#157478) --- tests/components/shelly/test_switch.py | 2 +- tests/components/shelly/test_utils.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/components/shelly/test_switch.py b/tests/components/shelly/test_switch.py index 9fea11ce878..8fc574440e2 100644 --- a/tests/components/shelly/test_switch.py +++ b/tests/components/shelly/test_switch.py @@ -568,6 +568,7 @@ async def test_wall_display_relay_mode( """Test Wall Display in relay mode.""" climate_entity_id = "climate.test_name" switch_entity_id = "switch.test_name_test_switch_0" + monkeypatch.delitem(mock_rpc_device.status, "cover:0") config_entry = await init_integration(hass, 2, model=MODEL_WALL_DISPLAY) @@ -577,7 +578,6 @@ async def test_wall_display_relay_mode( new_status = deepcopy(mock_rpc_device.status) new_status["sys"]["relay_in_thermostat"] = False new_status.pop("thermostat:0") - new_status.pop("cover:0") monkeypatch.setattr(mock_rpc_device, "status", new_status) await hass.config_entries.async_reload(config_entry.entry_id) diff --git a/tests/components/shelly/test_utils.py b/tests/components/shelly/test_utils.py index 481dbcf4afa..8ca212eb5c1 100644 --- a/tests/components/shelly/test_utils.py +++ b/tests/components/shelly/test_utils.py @@ -1,8 +1,9 @@ """Tests for Shelly utils.""" from typing import Any -from unittest.mock import Mock +from unittest.mock import AsyncMock, Mock +from aiohttp.web import Request from aioshelly.const import ( MODEL_1, MODEL_1L, @@ -14,6 +15,7 @@ from aioshelly.const import ( MODEL_PLUS_2PM_V2, MODEL_WALL_DISPLAY, ) +from aioshelly.rpc_device import WsServer import pytest from homeassistant.components.shelly.const import ( @@ -23,6 +25,7 @@ from homeassistant.components.shelly.const import ( UPTIME_DEVIATION, ) from homeassistant.components.shelly.utils import ( + ShellyReceiver, get_block_device_sleep_period, get_block_input_triggers, get_block_number_of_channels, @@ -303,3 +306,16 @@ def test_get_host(host: str, expected: str) -> None: def test_mac_address_from_name(name: str, result: str | None) -> None: """Test mac_address_from_name() function.""" assert mac_address_from_name(name) == result + + +async def test_shelly_receiver_get() -> None: + """Test ShellyReceiver get method.""" + ws_server = Mock(spec=WsServer) + ws_server.websocket_handler = AsyncMock(return_value="test_response") + receiver = ShellyReceiver(ws_server) + mock_request = Mock(spec=Request) + + response = await receiver.get(mock_request) + + ws_server.websocket_handler.assert_awaited_once_with(mock_request) + assert response == "test_response"