From 110b738686df0360154a04151afc88850cb57458 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Mon, 25 Sep 2023 21:34:14 +0100 Subject: [PATCH] Upgrade to watchfiles (#66) --- hid_devices.py | 9 ++------- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/hid_devices.py b/hid_devices.py index 63948dd..f1b4945 100644 --- a/hid_devices.py +++ b/hid_devices.py @@ -10,7 +10,7 @@ from typing import Awaitable, Callable, Literal, Optional, TypedDict, cast import evdev -from watchgod import awatch, AllWatcher +from watchfiles import awatch from a1314_message_filter import A1314MessageFilter from bluetooth_devices import BluetoothDeviceRegistry @@ -165,11 +165,6 @@ def __del__(self) -> None: print("HID Device ",self.device_id," removed") -class DeviceDirWatcher(AllWatcher): - def should_watch_dir(self, entry: os.DirEntry[str]) -> bool: - return entry.path.count('/') == 3 - - class HIDDeviceRegistry: def __init__(self, loop: asyncio.AbstractEventLoop): self.loop = loop @@ -198,7 +193,7 @@ async def send_message_to_devices(self, msg: bytes) -> None: await device.send_message(msg) async def __watch_device_changes(self) -> None: - async for changes in awatch('/dev/input', watcher_cls=DeviceDirWatcher): + async for changes in awatch("/dev/input/", recursive=False): self.__scan_devices() if self.on_devices_changed_handler is not None: await self.on_devices_changed_handler() diff --git a/requirements.txt b/requirements.txt index fb0bed6..a82a619 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,4 @@ hid-tools!=0.4 mypy==1.5.1 PyGObject pyudev -watchgod +watchfiles