forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
145 lines (123 loc) · 4.13 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""Provide common fixtures."""
from __future__ import annotations
import asyncio
from collections.abc import AsyncGenerator
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from matter_server.client.models.node import MatterNode
from matter_server.common.const import SCHEMA_VERSION
from matter_server.common.models import ServerInfoMessage
import pytest
from homeassistant.core import HomeAssistant
from .common import setup_integration_with_node_fixture
from tests.common import MockConfigEntry
MOCK_FABRIC_ID = 12341234
MOCK_COMPR_FABRIC_ID = 1234
@pytest.fixture(name="matter_client")
async def matter_client_fixture() -> AsyncGenerator[MagicMock]:
"""Fixture for a Matter client."""
with patch(
"homeassistant.components.matter.MatterClient", autospec=True
) as client_class:
client = client_class.return_value
async def connect() -> None:
"""Mock connect."""
await asyncio.sleep(0)
async def listen(init_ready: asyncio.Event | None) -> None:
"""Mock listen."""
if init_ready is not None:
init_ready.set()
listen_block = asyncio.Event()
await listen_block.wait()
pytest.fail("Listen was not cancelled!")
client.connect = AsyncMock(side_effect=connect)
client.start_listening = AsyncMock(side_effect=listen)
client.server_info = ServerInfoMessage(
fabric_id=MOCK_FABRIC_ID,
compressed_fabric_id=MOCK_COMPR_FABRIC_ID,
schema_version=1,
sdk_version="2022.11.1",
wifi_credentials_set=True,
thread_credentials_set=True,
min_supported_schema_version=SCHEMA_VERSION,
bluetooth_enabled=False,
)
yield client
@pytest.fixture(name="integration")
async def integration_fixture(
hass: HomeAssistant, matter_client: MagicMock
) -> MockConfigEntry:
"""Set up the Matter integration."""
entry = MockConfigEntry(domain="matter", data={"url": "ws://localhost:5580/ws"})
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry
@pytest.fixture(
params=[
"air_purifier",
"air_quality_sensor",
"color_temperature_light",
"dimmable_light",
"dimmable_plugin_unit",
"door_lock",
"door_lock_with_unbolt",
"eve_contact_sensor",
"eve_energy_plug",
"eve_energy_plug_patched",
"eve_thermo",
"eve_weather_sensor",
"extended_color_light",
"fan",
"flow_sensor",
"generic_switch",
"generic_switch_multi",
"humidity_sensor",
"leak_sensor",
"light_sensor",
"microwave_oven",
"multi_endpoint_light",
"occupancy_sensor",
"on_off_plugin_unit",
"onoff_light",
"onoff_light_alt_name",
"onoff_light_no_name",
"onoff_light_with_levelcontrol_present",
"pressure_sensor",
"room_airconditioner",
"silabs_dishwasher",
"silabs_laundrywasher",
"smoke_detector",
"switch_unit",
"temperature_sensor",
"thermostat",
"vacuum_cleaner",
"valve",
"window_covering_full",
"window_covering_lift",
"window_covering_pa_lift",
"window_covering_pa_tilt",
"window_covering_tilt",
"yandex_smart_socket",
]
)
async def matter_devices(
hass: HomeAssistant, matter_client: MagicMock, request: pytest.FixtureRequest
) -> MatterNode:
"""Fixture for a Matter device."""
return await setup_integration_with_node_fixture(hass, request.param, matter_client)
@pytest.fixture
def attributes() -> dict[str, Any]:
"""Return common attributes for all nodes."""
return {}
@pytest.fixture
async def matter_node(
hass: HomeAssistant,
matter_client: MagicMock,
node_fixture: str,
attributes: dict[str, Any],
) -> MatterNode:
"""Fixture for a Matter node."""
return await setup_integration_with_node_fixture(
hass, node_fixture, matter_client, attributes
)