diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddebd6e..4b2ec6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,6 @@ jobs: with: CODE_FOLDER: zigpy_zigate CACHE_VERSION: 2 - PYTHON_VERSION_DEFAULT: 3.8.14 PRE_COMMIT_CACHE_PATH: ~/.cache/pre-commit MINIMUM_COVERAGE_PERCENTAGE: 46 secrets: diff --git a/tests/test_uart.py b/tests/test_uart.py index 824a2db..463692b 100644 --- a/tests/test_uart.py +++ b/tests/test_uart.py @@ -22,6 +22,8 @@ def gw(): ("/dev/null", "pizigate:/dev/ttyAMA0"), ) async def test_connect(port, monkeypatch): + monkeypatch.setattr(gpiozero.Device, "_default_pin_factory", MagicMock()) + api = MagicMock() async def mock_conn(loop, protocol_factory, url, **kwargs): diff --git a/zigpy_zigate/common.py b/zigpy_zigate/common.py index 2951176..8322652 100644 --- a/zigpy_zigate/common.py +++ b/zigpy_zigate/common.py @@ -162,7 +162,7 @@ def async_run_in_executor(function): """Decorator to make a sync function async.""" async def replacement(*args): - return asyncio.get_running_loop().run_in_executor(None, function, *args) + return await asyncio.get_running_loop().run_in_executor(None, function, *args) replacement._sync_func = function @@ -174,3 +174,5 @@ async def replacement(*args): async_set_pizigate_flashing_mode = async_run_in_executor(set_pizigate_flashing_mode) async_set_zigatedin_running_mode = async_run_in_executor(set_zigatedin_running_mode) async_set_zigatedin_flashing_mode = async_run_in_executor(set_zigatedin_flashing_mode) +async_is_pizigate = async_run_in_executor(is_pizigate) +async_is_zigate_din = async_run_in_executor(is_zigate_din) diff --git a/zigpy_zigate/uart.py b/zigpy_zigate/uart.py index 1401561..57b455a 100644 --- a/zigpy_zigate/uart.py +++ b/zigpy_zigate/uart.py @@ -142,13 +142,13 @@ async def connect(device_config: Dict[str, Any], api, loop=None): if port == "auto": port = await loop.run_in_executor(None, c.discover_port) - if c.is_pizigate(port): + if await c.async_is_pizigate(port): LOGGER.debug("PiZiGate detected") await c.async_set_pizigate_running_mode() # in case of pizigate:/dev/ttyAMA0 syntax if port.startswith("pizigate:"): port = port.replace("pizigate:", "", 1) - elif c.is_zigate_din(port): + elif await c.async_is_zigate_din(port): LOGGER.debug("ZiGate USB DIN detected") await c.async_set_zigatedin_running_mode() elif c.is_zigate_wifi(port): diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index 6dd49ac..9b7718c 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -83,9 +83,9 @@ async def load_network_info(self, *, load_devices: bool = False): if c.is_zigate_wifi(port): model = "ZiGate WiFi" - elif c.is_pizigate(port): + elif await c.async_is_pizigate(port): model = "PiZiGate" - elif c.is_zigate_din(port): + elif await c.async_is_zigate_din(port): model = "ZiGate USB-DIN" else: model = "ZiGate USB-TTL"