Skip to content

Commit 7f4b561

Browse files
authored
Update Shelly utils coverage to 100% (home-assistant#157478)
1 parent ab8135b commit 7f4b561

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/components/shelly/test_switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ async def test_wall_display_relay_mode(
568568
"""Test Wall Display in relay mode."""
569569
climate_entity_id = "climate.test_name"
570570
switch_entity_id = "switch.test_name_test_switch_0"
571+
monkeypatch.delitem(mock_rpc_device.status, "cover:0")
571572

572573
config_entry = await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
573574

@@ -577,7 +578,6 @@ async def test_wall_display_relay_mode(
577578
new_status = deepcopy(mock_rpc_device.status)
578579
new_status["sys"]["relay_in_thermostat"] = False
579580
new_status.pop("thermostat:0")
580-
new_status.pop("cover:0")
581581
monkeypatch.setattr(mock_rpc_device, "status", new_status)
582582

583583
await hass.config_entries.async_reload(config_entry.entry_id)

tests/components/shelly/test_utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Tests for Shelly utils."""
22

33
from typing import Any
4-
from unittest.mock import Mock
4+
from unittest.mock import AsyncMock, Mock
55

6+
from aiohttp.web import Request
67
from aioshelly.const import (
78
MODEL_1,
89
MODEL_1L,
@@ -14,6 +15,7 @@
1415
MODEL_PLUS_2PM_V2,
1516
MODEL_WALL_DISPLAY,
1617
)
18+
from aioshelly.rpc_device import WsServer
1719
import pytest
1820

1921
from homeassistant.components.shelly.const import (
@@ -23,6 +25,7 @@
2325
UPTIME_DEVIATION,
2426
)
2527
from homeassistant.components.shelly.utils import (
28+
ShellyReceiver,
2629
get_block_device_sleep_period,
2730
get_block_input_triggers,
2831
get_block_number_of_channels,
@@ -303,3 +306,16 @@ def test_get_host(host: str, expected: str) -> None:
303306
def test_mac_address_from_name(name: str, result: str | None) -> None:
304307
"""Test mac_address_from_name() function."""
305308
assert mac_address_from_name(name) == result
309+
310+
311+
async def test_shelly_receiver_get() -> None:
312+
"""Test ShellyReceiver get method."""
313+
ws_server = Mock(spec=WsServer)
314+
ws_server.websocket_handler = AsyncMock(return_value="test_response")
315+
receiver = ShellyReceiver(ws_server)
316+
mock_request = Mock(spec=Request)
317+
318+
response = await receiver.get(mock_request)
319+
320+
ws_server.websocket_handler.assert_awaited_once_with(mock_request)
321+
assert response == "test_response"

0 commit comments

Comments
 (0)