Skip to content

Commit

Permalink
Upgrade to watchfiles (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Sep 25, 2023
1 parent bb1151d commit 110b738
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions hid_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ hid-tools!=0.4
mypy==1.5.1
PyGObject
pyudev
watchgod
watchfiles

0 comments on commit 110b738

Please sign in to comment.