mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
88 lines
2.4 KiB
Python
88 lines
2.4 KiB
Python
"""Fixtures for Gentex HomeLink tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from homelink.model.button import Button
|
|
import homelink.model.device
|
|
import pytest
|
|
|
|
from homeassistant.components.gentex_homelink import DOMAIN
|
|
|
|
from . import TEST_ACCESS_JWT
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_srp_auth() -> Generator[AsyncMock]:
|
|
"""Mock SRP authentication."""
|
|
with patch(
|
|
"homeassistant.components.gentex_homelink.config_flow.SRPAuth"
|
|
) as mock_srp_auth:
|
|
instance = mock_srp_auth.return_value
|
|
instance.async_get_access_token.return_value = {
|
|
"AuthenticationResult": {
|
|
"AccessToken": TEST_ACCESS_JWT,
|
|
"RefreshToken": "refresh",
|
|
"TokenType": "bearer",
|
|
"ExpiresIn": 3600,
|
|
}
|
|
}
|
|
yield instance
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_mqtt_provider(mock_device: AsyncMock) -> Generator[AsyncMock]:
|
|
"""Mock MQTT provider."""
|
|
with patch(
|
|
"homeassistant.components.gentex_homelink.MQTTProvider", autospec=True
|
|
) as mock_mqtt_provider:
|
|
instance = mock_mqtt_provider.return_value
|
|
instance.discover.return_value = [mock_device]
|
|
yield instance
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_device() -> AsyncMock:
|
|
"""Mock Device instance."""
|
|
device = AsyncMock(spec=homelink.model.device.Device, autospec=True)
|
|
buttons = [
|
|
Button(id="1", name="Button 1", device=device),
|
|
Button(id="2", name="Button 2", device=device),
|
|
Button(id="3", name="Button 3", device=device),
|
|
]
|
|
device.id = "TestDevice"
|
|
device.name = "TestDevice"
|
|
device.buttons = buttons
|
|
return device
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
"""Mock setup entry."""
|
|
return MockConfigEntry(
|
|
unique_id="some-uuid",
|
|
version=1,
|
|
domain=DOMAIN,
|
|
data={
|
|
"auth_implementation": "gentex_homelink",
|
|
"token": {
|
|
"access_token": "access",
|
|
"refresh_token": "refresh",
|
|
"expires_in": 3600,
|
|
"token_type": "bearer",
|
|
"expires_at": 1234567890,
|
|
},
|
|
},
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
"""Mock setup entry."""
|
|
with patch(
|
|
"homeassistant.components.gentex_homelink.async_setup_entry", return_value=True
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|