From 3e544212649eb80e652c07ab51102b06a6137a31 Mon Sep 17 00:00:00 2001 From: TimL Date: Thu, 11 Jul 2024 00:16:25 +1000 Subject: [PATCH] Disable skip_bootloader when the config is set to False (#249) * Skip bootloader when the config is set to skip On SMLIGHT SLZB-06 devices in USB mode the skip bootloader sequence causes the esp32 in these devices to reset. While there is a config option to disable skip bootloader, it is not hooked up. Ensure that it is possible to disable skip bootloader. * Add test for config to disable skip bootloader --- tests/api/test_connect.py | 21 +++++++++++++++++++++ zigpy_znp/api.py | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/api/test_connect.py b/tests/api/test_connect.py index 3630437e..c4de8891 100644 --- a/tests/api/test_connect.py +++ b/tests/api/test_connect.py @@ -115,6 +115,27 @@ async def test_connect_skip_bootloader_rts_dtr_pins(make_znp_server, mocker): znp.close() +async def test_connect_skip_bootloader_config(make_znp_server, mocker): + znp_server = make_znp_server(server_cls=BaseServerZNP) + znp = ZNP(config_for_port_path(znp_server.port_path)) + znp._znp_config["skip_bootloader"] = False + + mocker.patch.object(znp.nvram, "determine_alignment", new=CoroutineMock()) + mocker.patch.object(znp, "detect_zstack_version", new=CoroutineMock()) + + znp_server.reply_to( + c.SYS.Ping.Req(), responses=[c.SYS.Ping.Rsp(Capabilities=t.MTCapabilities.SYS)] + ) + + await znp.connect(test_port=True) + + serial = znp._uart._transport + assert serial._mock_dtr_prop.called is False + assert serial._mock_rts_prop.called is False + + znp.close() + + async def test_api_close(connected_znp, mocker): znp, znp_server = connected_znp uart = znp._uart diff --git a/zigpy_znp/api.py b/zigpy_znp/api.py index 941314da..555c6b52 100644 --- a/zigpy_znp/api.py +++ b/zigpy_znp/api.py @@ -734,7 +734,12 @@ async def connect(self, *, test_port=True) -> None: # prevent any data from being sent if test_port: # The reset indication callback is sent when some sticks start up - self.capabilities = (await self._skip_bootloader()).Capabilities + if self._znp_config[conf.CONF_SKIP_BOOTLOADER]: + self.capabilities = (await self._skip_bootloader()).Capabilities + else: + self.capabilities = ( + await self.request(c.SYS.Ping.Req()) + ).Capabilities # We need to know how structs are packed to deserialize frames correctly await self.nvram.determine_alignment()