Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): use move flags in aionotify for modules #14345

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/src/opentrons/hardware_control/backends/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ def _build_event_watcher() -> aionotify.Watcher:
watcher.watch(
alias="modules",
path="/dev",
flags=(aionotify.Flags.CREATE | aionotify.Flags.DELETE),
flags=(
aionotify.Flags.CREATE
| aionotify.Flags.DELETE
| aionotify.Flags.MOVED_FROM
| aionotify.Flags.MOVED_TO
),
)
return watcher

Expand Down
10 changes: 8 additions & 2 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,12 @@ def _build_event_watcher() -> aionotify.Watcher:
watcher.watch(
alias="modules",
path="/dev",
flags=(aionotify.Flags.CREATE | aionotify.Flags.DELETE),
flags=(
aionotify.Flags.CREATE
| aionotify.Flags.DELETE
| aionotify.Flags.MOVED_FROM
| aionotify.Flags.MOVED_TO
),
)
return watcher

Expand All @@ -1105,9 +1110,10 @@ async def _handle_watch_event(self) -> None:
log.debug("incomplete read error when quitting watcher")
return
if event is not None:
flags = aionotify.Flags.parse(event.flags)
log.debug(f"aionotify: {flags} {event.name}")
if "ot_module" in event.name:
event_name = event.name
flags = aionotify.Flags.parse(event.flags)
event_description = AionotifyEvent.build(event_name, flags)
await self.module_controls.handle_module_appearance(event_description)

Expand Down
14 changes: 10 additions & 4 deletions api/src/opentrons/hardware_control/module_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@

log = logging.getLogger(__name__)

MODULE_PORT_REGEX = re.compile("|".join(modules.MODULE_TYPE_BY_NAME.keys()), re.I)
MODULE_PORT_REGEX = re.compile(
# capture all modules by name using alternation
"(" + "|".join(modules.MODULE_TYPE_BY_NAME.keys()) + ")"
# add a negative lookahead to suppress matches on tempfiles udev creates
+ r"\d+(?!\.tmp-c\d+:\d+)",
re.I,
)


class AttachedModulesControl:
Expand Down Expand Up @@ -183,7 +189,7 @@ def get_module_at_port(port: str) -> Optional[modules.ModuleAtPort]:
"""
match = MODULE_PORT_REGEX.search(port)
if match:
name = match.group().lower()
name = match.group(1).lower()
if name not in modules.MODULE_TYPE_BY_NAME:
log.warning(f"Unexpected module connected: {name} on {port}")
return None
Expand All @@ -205,10 +211,10 @@ async def handle_module_appearance(self, event: AionotifyEvent) -> None:
new_modules = None
removed_modules = None
if maybe_module_at_port is not None:
if hasattr(event.flags, "DELETE"):
if hasattr(event.flags, "DELETE") or hasattr(event.flags, "MOVED_FROM"):
removed_modules = [maybe_module_at_port]
log.info(f"Module Removed: {maybe_module_at_port}")
elif hasattr(event.flags, "CREATE"):
elif hasattr(event.flags, "CREATE") or hasattr(event.flags, "MOVED_TO"):
new_modules = [maybe_module_at_port]
log.info(f"Module Added: {maybe_module_at_port}")
try:
Expand Down
Loading