Skip to content

Commit 93c7358

Browse files
authored
Move more sync functions to executor (#159)
* Move more sync functions to executor * Drop explicit default Python version from CI * Oops * Patch the default pin factory in `test_connect`
1 parent f650390 commit 93c7358

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
with:
1212
CODE_FOLDER: zigpy_zigate
1313
CACHE_VERSION: 2
14-
PYTHON_VERSION_DEFAULT: 3.8.14
1514
PRE_COMMIT_CACHE_PATH: ~/.cache/pre-commit
1615
MINIMUM_COVERAGE_PERCENTAGE: 46
1716
secrets:

tests/test_uart.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def gw():
2222
("/dev/null", "pizigate:/dev/ttyAMA0"),
2323
)
2424
async def test_connect(port, monkeypatch):
25+
monkeypatch.setattr(gpiozero.Device, "_default_pin_factory", MagicMock())
26+
2527
api = MagicMock()
2628

2729
async def mock_conn(loop, protocol_factory, url, **kwargs):

zigpy_zigate/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def async_run_in_executor(function):
162162
"""Decorator to make a sync function async."""
163163

164164
async def replacement(*args):
165-
return asyncio.get_running_loop().run_in_executor(None, function, *args)
165+
return await asyncio.get_running_loop().run_in_executor(None, function, *args)
166166

167167
replacement._sync_func = function
168168

@@ -174,3 +174,5 @@ async def replacement(*args):
174174
async_set_pizigate_flashing_mode = async_run_in_executor(set_pizigate_flashing_mode)
175175
async_set_zigatedin_running_mode = async_run_in_executor(set_zigatedin_running_mode)
176176
async_set_zigatedin_flashing_mode = async_run_in_executor(set_zigatedin_flashing_mode)
177+
async_is_pizigate = async_run_in_executor(is_pizigate)
178+
async_is_zigate_din = async_run_in_executor(is_zigate_din)

zigpy_zigate/uart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ async def connect(device_config: Dict[str, Any], api, loop=None):
142142
if port == "auto":
143143
port = await loop.run_in_executor(None, c.discover_port)
144144

145-
if c.is_pizigate(port):
145+
if await c.async_is_pizigate(port):
146146
LOGGER.debug("PiZiGate detected")
147147
await c.async_set_pizigate_running_mode()
148148
# in case of pizigate:/dev/ttyAMA0 syntax
149149
if port.startswith("pizigate:"):
150150
port = port.replace("pizigate:", "", 1)
151-
elif c.is_zigate_din(port):
151+
elif await c.async_is_zigate_din(port):
152152
LOGGER.debug("ZiGate USB DIN detected")
153153
await c.async_set_zigatedin_running_mode()
154154
elif c.is_zigate_wifi(port):

zigpy_zigate/zigbee/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ async def load_network_info(self, *, load_devices: bool = False):
8383

8484
if c.is_zigate_wifi(port):
8585
model = "ZiGate WiFi"
86-
elif c.is_pizigate(port):
86+
elif await c.async_is_pizigate(port):
8787
model = "PiZiGate"
88-
elif c.is_zigate_din(port):
88+
elif await c.async_is_zigate_din(port):
8989
model = "ZiGate USB-DIN"
9090
else:
9191
model = "ZiGate USB-TTL"

0 commit comments

Comments
 (0)