1
0
mirror of https://github.com/home-assistant/core.git synced 2026-03-01 22:30:12 +00:00
Files
core/tests/components/niko_home_control/conftest.py
Glenn Vandeuren (aka Iondependent) b5ae04605a Add climate platform for niko_home_control (#138087)
Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: VandeurenGlenn <8685280+VandeurenGlenn@users.noreply.github.com>
2025-11-10 16:27:59 +01:00

131 lines
3.1 KiB
Python

"""niko_home_control integration tests configuration."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from nhc.cover import NHCCover
from nhc.light import NHCLight
from nhc.scene import NHCScene
from nhc.thermostat import NHCThermostat
import pytest
from homeassistant.components.niko_home_control.const import DOMAIN
from homeassistant.const import CONF_HOST
from tests.common import MockConfigEntry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override integration setup."""
with patch(
"homeassistant.components.niko_home_control.async_setup_entry",
return_value=True,
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def light() -> NHCLight:
"""Return a light mock."""
mock = AsyncMock(spec=NHCLight)
mock.id = 1
mock.type = 1
mock.is_dimmable = False
mock.name = "light"
mock.suggested_area = "room"
mock.state = 100
return mock
@pytest.fixture
def dimmable_light() -> NHCLight:
"""Return a dimmable light mock."""
mock = AsyncMock(spec=NHCLight)
mock.id = 2
mock.type = 2
mock.is_dimmable = True
mock.name = "dimmable light"
mock.suggested_area = "room"
mock.state = 100
return mock
@pytest.fixture
def cover() -> NHCCover:
"""Return a cover mock."""
mock = AsyncMock(spec=NHCCover)
mock.id = 3
mock.type = 4
mock.name = "cover"
mock.suggested_area = "room"
mock.state = 100
return mock
@pytest.fixture
def climate() -> NHCThermostat:
"""Return a thermostat mock."""
mock = AsyncMock(spec=NHCThermostat)
mock.id = 5
mock.name = "thermostat"
mock.suggested_area = "room"
mock.state = 0
mock.measured = 180
mock.setpoint = 200
mock.overrule = 0
mock.overruletime = 0
mock.ecosave = 0
return mock
@pytest.fixture
def scene() -> NHCScene:
"""Return a scene mock."""
mock = AsyncMock(spec=NHCScene)
mock.id = 4
mock.type = 0
mock.name = "scene"
mock.suggested_area = "room"
mock.state = 0
return mock
@pytest.fixture
def mock_niko_home_control_connection(
light: NHCLight,
dimmable_light: NHCLight,
cover: NHCCover,
climate: NHCThermostat,
scene: NHCScene,
) -> Generator[AsyncMock]:
"""Mock a NHC client."""
with (
patch(
"homeassistant.components.niko_home_control.NHCController",
autospec=True,
) as mock_client,
patch(
"homeassistant.components.niko_home_control.config_flow.NHCController",
new=mock_client,
),
):
client = mock_client.return_value
client.lights = [light, dimmable_light]
client.covers = [cover]
client.thermostats = {"thermostat-5": climate}
client.scenes = [scene]
client.connect = AsyncMock(return_value=True)
yield client
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
domain=DOMAIN,
title="Niko Home Control",
data={CONF_HOST: "192.168.0.123"},
entry_id="01JFN93M7KRA38V5AMPCJ2JYYV",
)