forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
82 lines (63 loc) · 2.23 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Fixtures for anthemav integration tests."""
from collections.abc import Callable
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from homeassistant.components.anthemav.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_MODEL, CONF_PORT
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
@pytest.fixture
def mock_anthemav() -> AsyncMock:
"""Return the default mocked anthemav."""
avr = AsyncMock()
avr.protocol.macaddress = "000000000001"
avr.protocol.model = "MRX 520"
avr.reconnect = AsyncMock()
avr.protocol.wait_for_device_initialised = AsyncMock()
avr.close = MagicMock()
avr.protocol.input_list = []
avr.protocol.audio_listening_mode_list = []
avr.protocol.zones = {1: get_zone(), 2: get_zone()}
return avr
def get_zone() -> MagicMock:
"""Return a mocked zone."""
zone = MagicMock()
zone.power = False
return zone
@pytest.fixture
def mock_connection_create(mock_anthemav: AsyncMock) -> AsyncMock:
"""Return the default mocked connection.create."""
with patch(
"anthemav.Connection.create",
return_value=mock_anthemav,
) as mock:
yield mock
@pytest.fixture
def update_callback(mock_connection_create: AsyncMock) -> Callable[[str], None]:
"""Return the update_callback used when creating the connection."""
return mock_connection_create.call_args[1]["update_callback"]
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
domain=DOMAIN,
title="Anthem AV",
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 14999,
CONF_MAC: "00:00:00:00:00:01",
CONF_MODEL: "MRX 520",
},
unique_id="00:00:00:00:00:01",
)
@pytest.fixture
async def init_integration(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_connection_create: AsyncMock,
) -> MockConfigEntry:
"""Set up the AnthemAv integration for testing."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
return mock_config_entry