From 314b5fa0576bcaabc9b19312fa94ab3d44a28f8c Mon Sep 17 00:00:00 2001 From: "z2m@coolkit.cn" Date: Mon, 16 Nov 2026 16:39:02 +0800 Subject: [PATCH 1/3] Add `SYS.Model` SREQ to report the actual chip model The node model is currently inferred from the stack version and NV struct alignment: every Z-Stack 3.x device becomes a generic "CC2652", and older devices are either a "CC2531" or a "CC2538". This cannot distinguish between chips like the CC2652R, CC2652P, and CC2652RB, and is wrong for coordinators running customized Z-Stack builds on other hardware. Add a `SYS.Model` SREQ command (0x40) that returns the chip model as a length-prefixed UTF-8 string, and probe it while loading network info. The command is a firmware extension, not part of TI's documented MT SYS command set, so the probe degrades gracefully: firmware that does not recognize it (stock Z-Stack replies with `RPCError.CommandNotRecognized`) or does not answer within 5 seconds falls back to the existing inference. Stock firmware is unaffected and incurs no additional startup delay. --- zigpy_znp/api.py | 9 +++++++++ zigpy_znp/commands/sys.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/zigpy_znp/api.py b/zigpy_znp/api.py index e55d5a7..4fde405 100644 --- a/zigpy_znp/api.py +++ b/zigpy_znp/api.py @@ -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(), timeout=5) + ).Model.decode("utf-8", errors="replace") + except (CommandNotRecognized, TimeoutError): + model_rsp = None + if model_rsp: + model = model_rsp + version = await self.request(c.SYS.Version.Req()) node_info = zigpy.state.NodeInfo( ieee=ieee, diff --git a/zigpy_znp/commands/sys.py b/zigpy_znp/commands/sys.py index 8dcf08e..e24c04e 100644 --- a/zigpy_znp/commands/sys.py +++ b/zigpy_znp/commands/sys.py @@ -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( From 43ee80417ac6245ca0217c8ba26dea5b6e3bf44c Mon Sep 17 00:00:00 2001 From: "z2m@coolkit.cn" Date: Mon, 23 Nov 2026 16:06:52 +0800 Subject: [PATCH 2/3] Do not suppress request timeouts --- zigpy_znp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zigpy_znp/api.py b/zigpy_znp/api.py index 4fde405..a239d86 100644 --- a/zigpy_znp/api.py +++ b/zigpy_znp/api.py @@ -133,7 +133,7 @@ async def _load_network_info(self, *, load_devices=False): model_rsp = ( await self.request(c.SYS.Model.Req(), timeout=5) ).Model.decode("utf-8", errors="replace") - except (CommandNotRecognized, TimeoutError): + except CommandNotRecognized: model_rsp = None if model_rsp: model = model_rsp From 8e98247e43939d0945d012d42c446cee229a4723 Mon Sep 17 00:00:00 2001 From: "z2m@coolkit.cn" Date: Tue, 24 Nov 2026 15:33:13 +0800 Subject: [PATCH 3/3] Use the default SYS.Model timeout and add tests Remove the explicit timeout override so SYS.Model uses the configured SREQ timeout. Add a simulated firmware base class with SYS.Model support and test: - CC2674P10 model reporting - Fallback when the command is unsupported or returns an empty model - UTF-8 response decoding --- tests/api/test_network_state.py | 26 ++++++++++++++++++++++++++ tests/conftest.py | 15 +++++++++++++++ zigpy_znp/api.py | 6 +++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/api/test_network_state.py b/tests/api/test_network_state.py index da6fa3d..ed71d65 100644 --- a/tests/api/test_network_state.py +++ b/tests/api/test_network_state.py @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index 8c1b8bf..c75c6bf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1365,6 +1365,14 @@ 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) @@ -1372,6 +1380,13 @@ def __init__(self, *args, **kwargs): 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) diff --git a/zigpy_znp/api.py b/zigpy_znp/api.py index a239d86..78a3b2f 100644 --- a/zigpy_znp/api.py +++ b/zigpy_znp/api.py @@ -130,9 +130,9 @@ async def _load_network_info(self, *, load_devices=False): 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(), timeout=5) - ).Model.decode("utf-8", errors="replace") + model_rsp = (await self.request(c.SYS.Model.Req())).Model.decode( + "utf-8", errors="replace" + ) except CommandNotRecognized: model_rsp = None if model_rsp: