1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-21 10:27:52 +00:00
Files
core/tests/components/liebherr/conftest.py

119 lines
3.0 KiB
Python

"""Common fixtures for the liebherr tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch
from pyliebherrhomeapi import (
Device,
DeviceState,
DeviceType,
TemperatureControl,
TemperatureUnit,
ZonePosition,
)
import pytest
from homeassistant.components.liebherr.const import DOMAIN
from homeassistant.const import CONF_API_KEY, Platform
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
# Complete multi-zone device for comprehensive testing
MOCK_DEVICE = Device(
device_id="test_device_id",
nickname="Test Fridge",
device_type=DeviceType.COMBI,
device_name="CBNes1234",
)
MOCK_DEVICE_STATE = DeviceState(
device=MOCK_DEVICE,
controls=[
TemperatureControl(
zone_id=1,
zone_position=ZonePosition.TOP,
name="Fridge",
type="fridge",
value=5,
target=4,
min=2,
max=8,
unit=TemperatureUnit.CELSIUS,
),
TemperatureControl(
zone_id=2,
zone_position=ZonePosition.BOTTOM,
name="Freezer",
type="freezer",
value=-18,
target=-18,
min=-24,
max=-16,
unit=TemperatureUnit.CELSIUS,
),
],
)
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.liebherr.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Return a mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
data={CONF_API_KEY: "test-api-key"},
title="Liebherr",
)
@pytest.fixture
def mock_liebherr_client() -> Generator[MagicMock]:
"""Return a mocked Liebherr client."""
with (
patch(
"homeassistant.components.liebherr.LiebherrClient",
autospec=True,
) as mock_client,
patch(
"homeassistant.components.liebherr.config_flow.LiebherrClient",
new=mock_client,
),
):
client = mock_client.return_value
client.get_devices.return_value = [MOCK_DEVICE]
client.get_device_state.return_value = MOCK_DEVICE_STATE
client.set_temperature = AsyncMock()
yield client
@pytest.fixture
def platforms() -> list[Platform]:
"""Fixture to specify platforms to test."""
return [Platform.SENSOR]
@pytest.fixture
async def init_integration(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_liebherr_client: MagicMock,
platforms: list[Platform],
) -> MockConfigEntry:
"""Set up the Liebherr integration for testing."""
mock_config_entry.add_to_hass(hass)
with patch("homeassistant.components.liebherr.PLATFORMS", platforms):
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
return mock_config_entry