Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Oct 16, 2024
1 parent 8dc2b84 commit 1b82997
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
29 changes: 18 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ def __repr__(self):
return f"<{type(self).__name__} to {self.protocol}>"


def config_for_port_path(path):
return conf.CONFIG_SCHEMA(
{
conf.CONF_DEVICE: {conf.CONF_DEVICE_PATH: path},
zigpy.config.CONF_NWK_BACKUP_ENABLED: False,
}
)
def config_for_port_path(path, apply_schema: bool = True):
config = {
conf.CONF_DEVICE: {conf.CONF_DEVICE_PATH: path},
zigpy.config.CONF_NWK_BACKUP_ENABLED: False,
}

if apply_schema:
return conf.CONFIG_SCHEMA(config)

return config


@pytest.fixture
Expand Down Expand Up @@ -272,10 +275,14 @@ def inner(
server_config=None,
**kwargs,
):
default = config_for_port_path(FAKE_SERIAL_PORT)

client_config = merge_dicts(default, client_config or {})
server_config = merge_dicts(default, server_config or {})
client_config = merge_dicts(
config_for_port_path(FAKE_SERIAL_PORT, apply_schema=False),
client_config or {},
)
server_config = merge_dicts(
config_for_port_path(FAKE_SERIAL_PORT),
server_config or {},
)

app = ControllerApplication(client_config)

Expand Down
22 changes: 13 additions & 9 deletions zigpy_znp/zigbee/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

import zigpy.zdo
import zigpy.types
import zigpy.device
import zigpy.application

Expand All @@ -22,7 +23,7 @@ def manufacturer(self):
def model(self):
return "Coordinator"

def request(
async def request(
self,
profile,
cluster,
Expand All @@ -31,22 +32,25 @@ def request(
sequence,
data,
expect_reply=True,
# Extend the default timeout
timeout=2 * zigpy.device.APS_REPLY_TIMEOUT,
use_ieee=False,
ask_for_ack: bool | None = None,
priority: int = zigpy.types.PacketPriority.NORMAL,
):
"""
Normal `zigpy.device.Device:request` except its default timeout is longer.
"""

return super().request(
profile,
cluster,
src_ep,
dst_ep,
sequence,
data,
return await super().request(
profile=profile,
cluster=cluster,
src_ep=src_ep,
dst_ep=dst_ep,
sequence=sequence,
data=data,
expect_reply=expect_reply,
timeout=timeout,
use_ieee=use_ieee,
ask_for_ack=ask_for_ack,
priority=priority,
)

0 comments on commit 1b82997

Please sign in to comment.