From 1166711926b4afb244a1da66751de4bb1bb7bdc5 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:37:51 -0400 Subject: [PATCH] Fix blocking event loop calls (#156) * Run port discovery in thread (does anything use this?) * Do not iterate over serial ports when probing --- zigpy_zigate/api.py | 10 ---------- zigpy_zigate/uart.py | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/zigpy_zigate/api.py b/zigpy_zigate/api.py index 6f4ab3b..178b065 100644 --- a/zigpy_zigate/api.py +++ b/zigpy_zigate/api.py @@ -592,15 +592,5 @@ async def probe(cls, device_config: Dict[str, Any]) -> bool: async def _probe(self) -> None: """Open port and try sending a command""" - try: - device = next( - serial.tools.list_ports.grep( - self._config[zigpy_zigate.config.CONF_DEVICE_PATH] - ) - ) - if device.description == "ZiGate": - return - except StopIteration: - pass await self.connect() await self.set_raw_mode() diff --git a/zigpy_zigate/uart.py b/zigpy_zigate/uart.py index d0ca340..364576a 100644 --- a/zigpy_zigate/uart.py +++ b/zigpy_zigate/uart.py @@ -141,7 +141,7 @@ async def connect(device_config: Dict[str, Any], api, loop=None): port = device_config[CONF_DEVICE_PATH] if port == "auto": - port = c.discover_port() + port = await loop.run_in_executor(None, c.discover_port) if c.is_pizigate(port): LOGGER.debug("PiZiGate detected")