mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 09:38:58 +01:00
Update Shelly utils coverage to 100% (#157478)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user