Skip to content

Commit 0c0ffaa

Browse files
committed
consistent interfaces
1 parent 7bdf0ef commit 0c0ffaa

15 files changed

+867
-517
lines changed

tests/conftest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@
2424
import zigpy.zdo.types as zdo_t
2525

2626
from zha.application import Platform
27-
from zha.application.gateway import Gateway, WebSocketServerGateway
27+
from zha.application.gateway import (
28+
Gateway,
29+
WebSocketClientGateway,
30+
WebSocketServerGateway,
31+
)
2832
from zha.application.helpers import (
2933
AlarmControlPanelOptions,
3034
CoordinatorConfiguration,
3135
LightOptions,
32-
ServerConfiguration,
36+
WebsocketClientConfiguration,
37+
WebsocketServerConfiguration,
3338
ZHAConfiguration,
3439
ZHAData,
3540
)
3641
from zha.async_ import ZHAJob
37-
from zha.websocket.client.controller import Controller
3842

3943
FIXTURE_GRP_ID = 0x1001
4044
FIXTURE_GRP_NAME = "fixture group"
@@ -287,11 +291,14 @@ def zha_data_fixture() -> ZHAData:
287291
failed_tries=2,
288292
),
289293
),
290-
server_config=ServerConfiguration(
294+
ws_server_config=WebsocketServerConfiguration(
291295
host="localhost",
292296
port=port,
293297
network_auto_start=False,
294298
),
299+
ws_client_config=WebsocketClientConfiguration(
300+
host="localhost", port=port, aiohttp_session=None
301+
),
295302
)
296303

297304

@@ -326,7 +333,7 @@ async def connected_client_and_server(
326333
zha_data: ZHAData,
327334
zigpy_app_controller: ControllerApplication,
328335
caplog: pytest.LogCaptureFixture, # pylint: disable=unused-argument
329-
) -> AsyncGenerator[tuple[Controller, WebSocketServerGateway], None]:
336+
) -> AsyncGenerator[tuple[WebSocketClientGateway, WebSocketServerGateway], None]:
330337
"""Return the connected client and server fixture."""
331338

332339
with (
@@ -345,7 +352,7 @@ async def connected_client_and_server(
345352
await ws_gateway.async_initialize_devices_and_entities()
346353
async with (
347354
ws_gateway as gateway,
348-
Controller(f"ws://localhost:{zha_data.server_config.port}") as controller,
355+
WebSocketClientGateway(zha_data) as controller,
349356
):
350357
await controller.clients.listen()
351358
yield controller, gateway

tests/websocket/test_alarm_control_panel.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import zigpy.zcl.foundation as zcl_f
1010

1111
from zha.application import Platform
12-
from zha.application.gateway import WebSocketServerGateway as Server
12+
from zha.application.gateway import WebSocketClientGateway, WebSocketServerGateway
1313
from zha.application.platforms.model import AlarmControlPanelEntity
14-
from zha.websocket.client.controller import Controller
15-
from zha.websocket.client.proxy import DeviceProxy
14+
from zha.zigbee.device import WebSocketClientDevice
1615

1716
from ..common import (
1817
SIG_EP_INPUT,
@@ -31,7 +30,7 @@
3130
new=AsyncMock(return_value=[sentinel.data, zcl_f.Status.SUCCESS]),
3231
)
3332
async def test_alarm_control_panel(
34-
connected_client_and_server: tuple[Controller, Server],
33+
connected_client_and_server: tuple[WebSocketClientGateway, WebSocketServerGateway],
3534
) -> None:
3635
"""Test zhaws alarm control panel platform."""
3736
controller, server = connected_client_and_server
@@ -51,9 +50,11 @@ async def test_alarm_control_panel(
5150
zhaws_device = await join_zigpy_device(server, zigpy_device)
5251

5352
cluster: security.IasAce = zigpy_device.endpoints.get(1).ias_ace
54-
client_device: Optional[DeviceProxy] = controller.devices.get(zhaws_device.ieee)
53+
client_device: Optional[WebSocketClientDevice] = controller.devices.get(
54+
zhaws_device.ieee
55+
)
5556
assert client_device is not None
56-
alarm_entity: AlarmControlPanelEntity = client_device.device_model.entities.get(
57+
alarm_entity: AlarmControlPanelEntity = client_device.platform_entities.get(
5758
(Platform.ALARM_CONTROL_PANEL, "00:0d:6f:00:0a:90:69:e7-1")
5859
)
5960
assert alarm_entity is not None
@@ -223,8 +224,8 @@ async def test_alarm_control_panel(
223224

224225

225226
async def reset_alarm_panel(
226-
server: Server,
227-
controller: Controller,
227+
server: WebSocketServerGateway,
228+
controller: WebSocketClientGateway,
228229
cluster: security.IasAce,
229230
entity: AlarmControlPanelEntity,
230231
) -> None:

tests/websocket/test_binary_sensor.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
from zigpy.zcl.clusters import general, measurement, security
99

1010
from zha.application.discovery import Platform
11-
from zha.application.gateway import WebSocketServerGateway as Server
11+
from zha.application.gateway import WebSocketClientGateway, WebSocketServerGateway
1212
from zha.application.platforms.model import BasePlatformEntity, BinarySensorEntity
13-
from zha.websocket.client.controller import Controller
14-
from zha.websocket.client.proxy import DeviceProxy
13+
from zha.zigbee.device import WebSocketClientDevice
1514

1615
from ..common import (
1716
SIG_EP_INPUT,
@@ -26,10 +25,10 @@
2625

2726

2827
def find_entity(
29-
device_proxy: DeviceProxy, platform: Platform
28+
device_proxy: WebSocketClientDevice, platform: Platform
3029
) -> Optional[BasePlatformEntity]:
3130
"""Find an entity for the specified platform on the given device."""
32-
for entity in device_proxy.device_model.entities.values():
31+
for entity in device_proxy.platform_entities.values():
3332
if entity.platform == platform:
3433
return entity
3534
return None
@@ -56,7 +55,7 @@ def find_entity(
5655

5756

5857
async def async_test_binary_sensor_on_off(
59-
server: Server, cluster: general.OnOff, entity: BinarySensorEntity
58+
server: WebSocketServerGateway, cluster: general.OnOff, entity: BinarySensorEntity
6059
) -> None:
6160
"""Test getting on and off messages for binary sensors."""
6261
# binary sensor on
@@ -69,7 +68,9 @@ async def async_test_binary_sensor_on_off(
6968

7069

7170
async def async_test_iaszone_on_off(
72-
server: Server, cluster: security.IasZone, entity: BinarySensorEntity
71+
server: WebSocketServerGateway,
72+
cluster: security.IasZone,
73+
entity: BinarySensorEntity,
7374
) -> None:
7475
"""Test getting on and off messages for iaszone binary sensors."""
7576
# binary sensor on
@@ -91,7 +92,7 @@ async def async_test_iaszone_on_off(
9192
],
9293
)
9394
async def test_binary_sensor(
94-
connected_client_and_server: tuple[Controller, Server],
95+
connected_client_and_server: tuple[WebSocketClientGateway, WebSocketServerGateway],
9596
device: dict,
9697
on_off_test: Callable[..., Awaitable[None]],
9798
cluster_name: str,
@@ -104,7 +105,9 @@ async def test_binary_sensor(
104105

105106
await server.async_block_till_done()
106107

107-
client_device: Optional[DeviceProxy] = controller.devices.get(zhaws_device.ieee)
108+
client_device: Optional[WebSocketClientDevice] = controller.devices.get(
109+
zhaws_device.ieee
110+
)
108111
assert client_device is not None
109112
entity: BinarySensorEntity = find_entity(client_device, Platform.BINARY_SENSOR) # type: ignore
110113
assert entity is not None

tests/websocket/test_button.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import zigpy.zcl.foundation as zcl_f
1010

1111
from zha.application.discovery import Platform
12-
from zha.application.gateway import WebSocketServerGateway as Server
12+
from zha.application.gateway import WebSocketClientGateway, WebSocketServerGateway
1313
from zha.application.platforms.model import BasePlatformEntity, ButtonEntity
14-
from zha.websocket.client.controller import Controller
15-
from zha.websocket.client.proxy import DeviceProxy
14+
from zha.zigbee.device import WebSocketClientDevice
1615

1716
from ..common import (
1817
SIG_EP_INPUT,
@@ -25,17 +24,17 @@
2524

2625

2726
def find_entity(
28-
device_proxy: DeviceProxy, platform: Platform
27+
device_proxy: WebSocketClientDevice, platform: Platform
2928
) -> Optional[BasePlatformEntity]:
3029
"""Find an entity for the specified platform on the given device."""
31-
for entity in device_proxy.device_model.entities.values():
30+
for entity in device_proxy.platform_entities.values():
3231
if entity.platform == platform:
3332
return entity
3433
return None
3534

3635

3736
async def test_button(
38-
connected_client_and_server: tuple[Controller, Server],
37+
connected_client_and_server: tuple[WebSocketClientGateway, WebSocketServerGateway],
3938
) -> None:
4039
"""Test zha button platform."""
4140
controller, server = connected_client_and_server
@@ -58,7 +57,9 @@ async def test_button(
5857
cluster = zigpy_device.endpoints[1].identify
5958

6059
assert cluster is not None
61-
client_device: Optional[DeviceProxy] = controller.devices.get(zhaws_device.ieee)
60+
client_device: Optional[WebSocketClientDevice] = controller.devices.get(
61+
zhaws_device.ieee
62+
)
6263
assert client_device is not None
6364
entity: ButtonEntity = find_entity(client_device, Platform.BUTTON) # type: ignore
6465
assert entity is not None

0 commit comments

Comments
 (0)