2020-05-26 13:47:25 +00:00
|
|
|
"""Define fixtures for Elexa Guardian tests."""
|
2024-03-08 13:50:04 +00:00
|
|
|
|
2024-07-04 09:53:49 +00:00
|
|
|
from collections.abc import AsyncGenerator, Generator
|
|
|
|
from typing import Any
|
2023-03-09 21:57:16 +00:00
|
|
|
from unittest.mock import AsyncMock, patch
|
2020-05-26 13:47:25 +00:00
|
|
|
|
2021-01-01 21:31:56 +00:00
|
|
|
import pytest
|
2020-07-03 18:29:35 +00:00
|
|
|
|
2022-01-21 07:12:36 +00:00
|
|
|
from homeassistant.components.guardian import CONF_UID, DOMAIN
|
2022-01-21 03:32:07 +00:00
|
|
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
|
2024-07-04 09:53:49 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-01-21 03:32:07 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2024-07-04 09:53:49 +00:00
|
|
|
from homeassistant.util.json import JsonObjectType
|
2020-05-26 13:47:25 +00:00
|
|
|
|
2024-07-04 09:53:49 +00:00
|
|
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
2022-01-21 03:32:07 +00:00
|
|
|
|
|
|
|
|
2023-03-09 21:57:16 +00:00
|
|
|
@pytest.fixture
|
2024-06-06 15:28:59 +00:00
|
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
2023-03-09 21:57:16 +00:00
|
|
|
"""Override async_setup_entry."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.guardian.async_setup_entry", return_value=True
|
|
|
|
) as mock_setup_entry:
|
|
|
|
yield mock_setup_entry
|
|
|
|
|
|
|
|
|
2022-01-21 03:32:07 +00:00
|
|
|
@pytest.fixture(name="config_entry")
|
2024-07-04 09:53:49 +00:00
|
|
|
def config_entry_fixture(
|
|
|
|
hass: HomeAssistant, config: dict[str, Any], unique_id: str
|
|
|
|
) -> MockConfigEntry:
|
2022-01-21 03:32:07 +00:00
|
|
|
"""Define a config entry fixture."""
|
2022-01-21 07:12:36 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
unique_id=unique_id,
|
|
|
|
data={CONF_UID: "3456", **config},
|
|
|
|
)
|
2022-01-21 03:32:07 +00:00
|
|
|
entry.add_to_hass(hass)
|
|
|
|
return entry
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="config")
|
2024-07-04 09:53:49 +00:00
|
|
|
def config_fixture() -> dict[str, Any]:
|
2022-01-21 03:32:07 +00:00
|
|
|
"""Define a config entry data fixture."""
|
|
|
|
return {
|
|
|
|
CONF_IP_ADDRESS: "192.168.1.100",
|
|
|
|
CONF_PORT: 7777,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_sensor_pair_dump", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_sensor_pair_dump_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful sensor_pair_dump response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("sensor_pair_dump_data.json", "guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_sensor_pair_sensor", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_sensor_pair_sensor_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful sensor_pair_sensor response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("sensor_pair_sensor_data.json", "guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_sensor_paired_sensor_status", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_sensor_paired_sensor_status_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful sensor_paired_sensor_status response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("sensor_paired_sensor_status_data.json", "guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_system_diagnostics", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_system_diagnostics_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful system_diagnostics response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("system_diagnostics_data.json", "guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_system_onboard_sensor_status", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_system_onboard_sensor_status_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful system_onboard_sensor_status response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture(
|
|
|
|
"system_onboard_sensor_status_data.json", "guardian"
|
2022-01-21 07:12:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_system_ping", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_system_ping_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful system_ping response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("system_ping_data.json", "guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_valve_status", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_valve_status_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful valve_status response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("valve_status_data.json", "guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
|
|
|
|
|
2022-10-18 16:06:23 +00:00
|
|
|
@pytest.fixture(name="data_wifi_status", scope="package")
|
2024-07-04 09:53:49 +00:00
|
|
|
def data_wifi_status_fixture() -> JsonObjectType:
|
2022-01-21 07:12:36 +00:00
|
|
|
"""Define data from a successful wifi_status response."""
|
2024-07-04 09:53:49 +00:00
|
|
|
return load_json_object_fixture("wifi_status_data.json", "guardian")
|
2022-01-21 03:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="setup_guardian")
|
2022-01-21 07:12:36 +00:00
|
|
|
async def setup_guardian_fixture(
|
2024-07-04 09:53:49 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
config: dict[str, Any],
|
|
|
|
data_sensor_pair_dump: JsonObjectType,
|
|
|
|
data_sensor_pair_sensor: JsonObjectType,
|
|
|
|
data_sensor_paired_sensor_status: JsonObjectType,
|
|
|
|
data_system_diagnostics: JsonObjectType,
|
|
|
|
data_system_onboard_sensor_status: JsonObjectType,
|
|
|
|
data_system_ping: JsonObjectType,
|
|
|
|
data_valve_status: JsonObjectType,
|
|
|
|
data_wifi_status: JsonObjectType,
|
|
|
|
) -> AsyncGenerator[None]:
|
2022-01-21 03:32:07 +00:00
|
|
|
"""Define a fixture to set up Guardian."""
|
2024-03-25 23:02:16 +00:00
|
|
|
with (
|
|
|
|
patch("aioguardian.client.Client.connect"),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.sensor.SensorCommands.pair_dump",
|
|
|
|
return_value=data_sensor_pair_dump,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.sensor.SensorCommands.pair_sensor",
|
|
|
|
return_value=data_sensor_pair_sensor,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.sensor.SensorCommands.paired_sensor_status",
|
|
|
|
return_value=data_sensor_paired_sensor_status,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.system.SystemCommands.diagnostics",
|
|
|
|
return_value=data_system_diagnostics,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.system.SystemCommands.onboard_sensor_status",
|
|
|
|
return_value=data_system_onboard_sensor_status,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.system.SystemCommands.ping",
|
|
|
|
return_value=data_system_ping,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.valve.ValveCommands.status",
|
|
|
|
return_value=data_valve_status,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.commands.wifi.WiFiCommands.status",
|
|
|
|
return_value=data_wifi_status,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"aioguardian.client.Client.disconnect",
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.guardian.PLATFORMS",
|
|
|
|
[],
|
|
|
|
),
|
2020-05-26 13:47:25 +00:00
|
|
|
):
|
2022-01-21 03:32:07 +00:00
|
|
|
assert await async_setup_component(hass, DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
2020-05-26 13:47:25 +00:00
|
|
|
yield
|
2022-01-21 03:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="unique_id")
|
2024-07-04 09:53:49 +00:00
|
|
|
def unique_id_fixture() -> str:
|
2022-01-21 03:32:07 +00:00
|
|
|
"""Define a config entry unique ID fixture."""
|
|
|
|
return "guardian_3456"
|