mirror of
https://github.com/home-assistant/core.git
synced 2025-05-13 02:19:16 +00:00

* Update tests to avoid patching internals * * Use fixtures for tests * Update variable names in tests for clarity * Use hass.config_entries.async_setup instead of setup.async_setup_component
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Test configuration for opentherm_gw."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
from pyotgw.vars import OTGW, OTGW_ABOUT
|
|
import pytest
|
|
|
|
VERSION_TEST = "4.2.5"
|
|
MINIMAL_STATUS = {OTGW: {OTGW_ABOUT: f"OpenTherm Gateway {VERSION_TEST}"}}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
"""Override async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.opentherm_gw.async_setup_entry",
|
|
return_value=True,
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_pyotgw() -> Generator[MagicMock]:
|
|
"""Mock a pyotgw.OpenThermGateway object."""
|
|
with (
|
|
patch(
|
|
"homeassistant.components.opentherm_gw.OpenThermGateway",
|
|
return_value=MagicMock(
|
|
connect=AsyncMock(return_value=MINIMAL_STATUS),
|
|
set_control_setpoint=AsyncMock(),
|
|
set_max_relative_mod=AsyncMock(),
|
|
disconnect=AsyncMock(),
|
|
),
|
|
) as mock_gateway,
|
|
patch(
|
|
"homeassistant.components.opentherm_gw.config_flow.pyotgw.OpenThermGateway",
|
|
new=mock_gateway,
|
|
),
|
|
):
|
|
yield mock_gateway
|