mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Set up the config entry in Elexa Guardian test fixtures (#195556)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
b9b7c39d5e
commit
0a5fb475ba
@@ -1,6 +1,6 @@
|
||||
"""Define fixtures for Elexa Guardian tests."""
|
||||
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from collections.abc import Generator
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
@@ -10,7 +10,6 @@ from pytest_homeassistant.common import MockConfigEntry, load_json_object_fixtur
|
||||
from homeassistant.components.guardian import CONF_UID, DOMAIN
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.json import JsonObjectType
|
||||
|
||||
|
||||
@@ -102,10 +101,8 @@ def platforms_fixture() -> list[Platform]:
|
||||
return []
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_guardian")
|
||||
async def setup_guardian_fixture(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
@pytest.fixture(name="patch_guardian")
|
||||
def patch_guardian_fixture(
|
||||
platforms: list[Platform],
|
||||
data_sensor_pair_dump: JsonObjectType,
|
||||
data_sensor_pair_sensor: JsonObjectType,
|
||||
@@ -115,8 +112,8 @@ async def setup_guardian_fixture(
|
||||
data_system_ping: JsonObjectType,
|
||||
data_valve_status: JsonObjectType,
|
||||
data_wifi_status: JsonObjectType,
|
||||
) -> AsyncGenerator[None]:
|
||||
"""Define a fixture to set up Guardian."""
|
||||
) -> Generator[None]:
|
||||
"""Patch the Guardian library."""
|
||||
with (
|
||||
patch("aioguardian.client.Client.connect"),
|
||||
patch(
|
||||
@@ -159,11 +156,18 @@ async def setup_guardian_fixture(
|
||||
platforms,
|
||||
),
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_guardian")
|
||||
async def setup_guardian_fixture(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, patch_guardian: None
|
||||
) -> None:
|
||||
"""Define a fixture to set up Guardian."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.fixture(name="unique_id")
|
||||
def unique_id_fixture() -> str:
|
||||
"""Define a config entry unique ID fixture."""
|
||||
|
||||
@@ -43,7 +43,7 @@ async def test_duplicate_error(hass: HomeAssistant, config: dict[str, Any]) -> N
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_guardian")
|
||||
@pytest.mark.usefixtures("patch_guardian")
|
||||
async def test_connect_error(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||
"""Test that the config entry errors out if the device cannot connect."""
|
||||
|
||||
@@ -83,7 +83,7 @@ async def test_get_pin_from_uid() -> None:
|
||||
assert pin == "3456"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_guardian")
|
||||
@pytest.mark.usefixtures("patch_guardian")
|
||||
async def test_step_user(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||
"""Test the user step."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -107,7 +107,7 @@ async def test_step_user(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||
assert result["result"].unique_id == "guardian_3456"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_guardian")
|
||||
@pytest.mark.usefixtures("patch_guardian")
|
||||
async def test_step_zeroconf(hass: HomeAssistant) -> None:
|
||||
"""Test the zeroconf step."""
|
||||
zeroconf_data = ZeroconfServiceInfo(
|
||||
@@ -164,7 +164,7 @@ async def test_step_zeroconf_already_in_progress(hass: HomeAssistant) -> None:
|
||||
assert result["reason"] == "already_in_progress"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("setup_guardian")
|
||||
@pytest.mark.usefixtures("patch_guardian")
|
||||
async def test_step_dhcp(hass: HomeAssistant) -> None:
|
||||
"""Test the dhcp step."""
|
||||
dhcp_data = DhcpServiceInfo(
|
||||
|
||||
@@ -13,7 +13,7 @@ async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
setup_guardian: None, # relies on config_entry fixture
|
||||
setup_guardian: None,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
data: GuardianData = config_entry.runtime_data
|
||||
|
||||
@@ -23,7 +23,7 @@ async def test_paired_sensor_via_device_id(
|
||||
freezer: FrozenDateTimeFactory,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
config_entry: MockConfigEntry,
|
||||
setup_guardian: None, # relies on config_entry fixture
|
||||
setup_guardian: None,
|
||||
) -> None:
|
||||
"""Test that a paired sensor is linked to the valve controller via via_device_id."""
|
||||
# Advance time so the sensor pair dump coordinator refreshes and discovers the
|
||||
|
||||
Reference in New Issue
Block a user