Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/api/test_network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,35 @@
BaseZStack1CC2531,
FormedLaunchpadCC26X2R1,
FormedZStack3CC2531,
FormedZStack3WithModel,
)


@pytest.mark.parametrize(
"reported_model, expected_model",
[
pytest.param(None, "CC2652", id="unsupported"),
pytest.param(b"", "CC2652", id="empty"),
pytest.param(b"CC2674P10", "CC2674P10", id="cc2674p10"),
pytest.param(b"Caf\xc3\xa9", "Caf\u00e9", id="utf8"),
],
)
async def test_load_network_info_model(
reported_model, expected_model, make_connected_znp
):
if reported_model is None:
znp, _ = await make_connected_znp(server_cls=FormedLaunchpadCC26X2R1)
else:
znp, znp_server = await make_connected_znp(server_cls=FormedZStack3WithModel)
znp_server.reported_model = reported_model

await znp.load_network_info()

assert znp.node_info.model == expected_model

await znp.disconnect()


@pytest.mark.parametrize("to_device", ALL_DEVICES)
@pytest.mark.parametrize("from_device", FORMED_DEVICES)
async def test_state_transfer(from_device, to_device, make_connected_znp):
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,13 +1365,28 @@ def led_responder(self, req):
return req.Rsp(Status=t.Status.SUCCESS)


class BaseZStack3WithModel(BaseLaunchpadCC26X2R1):
reported_model = b"CC2674P10"

@reply_to(c.SYS.Model.Req())
def model_responder(self, req):
return req.Rsp(Model=self.reported_model)


class FormedLaunchpadCC26X2R1(BaseLaunchpadCC26X2R1):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._nvram = load_nvram_json("CC2652R-ZStack4.formed.json")
self._orig_nvram = simple_deepcopy(self._nvram)


class FormedZStack3WithModel(BaseZStack3WithModel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._nvram = load_nvram_json("CC2652R-ZStack4.formed.json")
self._orig_nvram = simple_deepcopy(self._nvram)


class ResetLaunchpadCC26X2R1(BaseLaunchpadCC26X2R1):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
9 changes: 9 additions & 0 deletions zigpy_znp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ async def _load_network_info(self, *, load_devices=False):
model = "CC2538" if self.nvram.align_structs else "CC2531"
fw_variant = "Z-Stack Home 1.2" if self.version == 1.2 else "Z-Stack 3.0.x"

try:
model_rsp = (await self.request(c.SYS.Model.Req())).Model.decode(
"utf-8", errors="replace"
)
except CommandNotRecognized:
model_rsp = None
if model_rsp:
model = model_rsp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code currently is untested. Can you add a test? See BaseZStack3CC2531 as an example. I think adding a new base class that has the LED command would allow you to simulate behavior both with and without this command to ensure both branches are exercised.


version = await self.request(c.SYS.Version.Req())
node_info = zigpy.state.NodeInfo(
ieee=ieee,
Expand Down
7 changes: 7 additions & 0 deletions zigpy_znp/commands/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ class SYS(t.CommandsBase, subsystem=t.Subsystem.SYS):
rsp_schema=t.STATUS_SCHEMA,
)

Model = t.CommandDef(
t.CommandType.SREQ,
0x40,
req_schema=(),
rsp_schema=(t.Param("Model", t.ShortBytes, "Chip Model"),),
)

# MT SYS Callbacks
# This command is sent by the device to indicate the reset
ResetInd = t.CommandDef(
Expand Down