2022-11-16 16:38:07 +00:00
|
|
|
"""Test fixtures for the Home Assistant Hardware integration."""
|
2024-03-08 13:50:04 +00:00
|
|
|
|
2024-07-01 10:09:11 +00:00
|
|
|
from collections.abc import Generator
|
2022-11-22 10:17:23 +00:00
|
|
|
from typing import Any
|
2023-06-01 10:32:14 +00:00
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
2022-11-16 16:38:07 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2022-11-22 10:17:23 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2024-06-06 15:28:59 +00:00
|
|
|
def mock_zha_config_flow_setup() -> Generator[None]:
|
2022-11-22 10:17:23 +00:00
|
|
|
"""Mock the radio connection and probing of the ZHA config flow."""
|
|
|
|
|
2024-07-19 14:44:03 +00:00
|
|
|
def mock_probe(config: dict[str, Any]) -> dict[str, Any]:
|
2022-11-22 10:17:23 +00:00
|
|
|
# The radio probing will return the correct baudrate
|
|
|
|
return {**config, "baudrate": 115200}
|
|
|
|
|
|
|
|
mock_connect_app = MagicMock()
|
|
|
|
mock_connect_app.__aenter__.return_value.backups.backups = [MagicMock()]
|
|
|
|
mock_connect_app.__aenter__.return_value.backups.create_backup.return_value = (
|
|
|
|
MagicMock()
|
|
|
|
)
|
|
|
|
|
2024-03-25 23:02:16 +00:00
|
|
|
with (
|
|
|
|
patch(
|
|
|
|
"bellows.zigbee.application.ControllerApplication.probe",
|
|
|
|
side_effect=mock_probe,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.zha.radio_manager.ZhaRadioManager.connect_zigpy_app",
|
|
|
|
return_value=mock_connect_app,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.zha.async_setup_entry",
|
|
|
|
return_value=True,
|
|
|
|
),
|
2022-11-22 10:17:23 +00:00
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2023-06-01 10:32:14 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2024-06-06 15:28:59 +00:00
|
|
|
def mock_zha_get_last_network_settings() -> Generator[None]:
|
2023-06-01 10:32:14 +00:00
|
|
|
"""Mock zha.api.async_get_last_network_settings."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zha.api.async_get_last_network_settings",
|
|
|
|
AsyncMock(return_value=None),
|
|
|
|
):
|
|
|
|
yield
|