Skip to content

feat: Add USB and direct-attach device detection#28

Merged
iamh2o merged 1 commit intomainfrom
feature/device-detection
Feb 3, 2026
Merged

feat: Add USB and direct-attach device detection#28
iamh2o merged 1 commit intomainfrom
feature/device-detection

Conversation

@iamh2o
Copy link
Contributor

@iamh2o iamh2o commented Feb 3, 2026

Summary

Implements automatic discovery of locally connected devices (USB and direct-attach) on the local machine.

Changes

New CLI Command: marvain devices detect

# Detect all devices
marvain devices detect

# Filter by device type
marvain devices detect --type video
marvain devices detect --type audio_input
marvain devices detect --type audio_output
marvain devices detect --type serial

# Filter by connection type
marvain devices detect --connection usb
marvain devices detect --connection direct

# JSON output
marvain devices detect --format json

Device Detection

  • Video devices: Cameras, webcams (AVFoundation on macOS, /dev/video* on Linux)
  • Audio input: Microphones (CoreAudio on macOS)
  • Audio output: Speakers (CoreAudio on macOS)
  • Serial ports: USB-to-serial adapters (/dev/tty., /dev/cu.)

Implementation

  • DetectedDevice dataclass in marvain_cli/ops.py
  • detect_local_devices() aggregates all detection methods
  • list_detected_devices() provides filtering and dict output
  • Platform-specific detection using macOS APIs (AVFoundation, CoreAudio)

Tests

  • 8 new tests in tests/test_ops.py::TestDeviceDetection
  • All tests passing

Testing

# Run device detection tests
python -m pytest tests/test_ops.py::TestDeviceDetection -v

# Manual test
marvain devices detect

Files Changed

  • marvain_cli/ops.py: Device detection functions
  • marvain_cli/typer_app.py: devices detect command
  • marvain_cli/argparse_app.py: devices detect command (fallback)
  • tests/test_ops.py: 8 new tests

Pull Request opened by Augment Code with guidance from the PR author

- Add detect_local_devices() to scan for video, audio, serial devices
- Add marvain devices detect CLI command with filtering options
- Support table and JSON output formats
- Platform-specific detection: AVFoundation/CoreAudio on macOS
- Filter by device type (video, audio_input, audio_output, serial)
- Filter by connection type (usb, direct)
- Add 8 comprehensive tests for device detection
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 052afd87cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2571 to +2574
# Check if USB device
conn_type = "usb" if "usb" in video_path.lower() or os.path.exists(
f"/sys/class/video4linux/{os.path.basename(video_path)}/device/driver"
) else "direct"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a real USB check for Linux video devices

On Linux, conn_type is set to "usb" whenever /sys/class/video4linux/<device>/device/driver exists. That path exists for essentially every v4l2 device (PCI, platform, virtual, etc.), so non‑USB cameras will still be marked as USB. In practice this makes --connection direct return no results even when direct‑attach devices are present, and mislabels devices in the output. Consider checking the sysfs device ancestry for a USB bus (e.g., via /sys/class/video4linux/<device>/device/subsystem or udevadm) instead of only the driver path.

Useful? React with 👍 / 👎.

@iamh2o iamh2o merged commit 9424053 into main Feb 3, 2026
3 checks passed
@iamh2o iamh2o deleted the feature/device-detection branch February 6, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant