Skip to content

Fix serial port listing with unknown serial subsystems (Linux)#54

Merged
puddly merged 9 commits intodevfrom
puddly/fix-list-serial-ports-when-empty
Apr 10, 2026
Merged

Fix serial port listing with unknown serial subsystems (Linux)#54
puddly merged 9 commits intodevfrom
puddly/fix-list-serial-ports-when-empty

Conversation

@puddly
Copy link
Copy Markdown
Owner

@puddly puddly commented Apr 10, 2026

Caught (again) in https://github.com/home-assistant/core/actions/runs/24216216900/job/70698025832?pr=167615.

                    product=None,
                    bcd_device=None,
                    interface_description=None,
                    interface_num=None,
                )
            else:
                LOGGER.warning(
                    "Unknown serial device subsystem %r for device %r",
                    subsystem,
                    device,
                )
    
>           results.append(info)
                           ^^^^
E           UnboundLocalError: cannot access local variable 'info' where it is not associated with a value

A follow-up PR will enable as much of mypy as we can to catch things like this in the future.


The underlying issue is that Path.resolve() on a nonexistent path will return the same path unless called with strict=True. The GitHub Actions runner VM seems to have a custom device with TTYs whose platform symlink is missing, causing an the "unknown serial device subsystem" branch to be taken erroneously.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.05%. Comparing base (65d0c62) to head (be7dac0).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #54      +/-   ##
==========================================
+ Coverage   89.00%   89.05%   +0.05%     
==========================================
  Files          19       19              
  Lines        2800     2804       +4     
==========================================
+ Hits         2492     2497       +5     
+ Misses        308      307       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@puddly puddly changed the title Fix listing serial ports with no ports Fix listing serial ports with an unknown subsystem Apr 10, 2026
@puddly puddly changed the title Fix listing serial ports with an unknown subsystem Fix serial port listing with unknown serial subsystems (Linux) Apr 10, 2026
@puddly puddly requested a review from Copilot April 10, 2026 14:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Linux serial port enumeration crash when encountering TTY devices whose sysfs entries lack a resolvable subsystem symlink (as seen on GitHub Actions runner VMs). It hardens linux_list_serial_ports() to skip broken/nonexistent sysfs paths and adds regression coverage to prevent UnboundLocalError from recurring.

Changes:

  • Use Path.resolve(strict=True) when resolving tty devices and their subsystem, skipping entries that can’t be resolved.
  • Ensure the “unknown subsystem” branch no longer falls through to results.append(info) by explicitly continuing.
  • Add Linux tests for devices with no subsystem and for an empty sysfs tree; run serialx.tools.list_ports in CI to surface enumeration failures early.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
serialx/platforms/serial_linux.py Makes sysfs resolution strict and avoids appending undefined info for unknown subsystems.
tests/test_list_serial_ports_linux.py Adds regression tests for missing-subsystem TTYs and empty listings.
.github/workflows/ci.yml Updates Python setup to check-latest: true and runs port listing in test jobs to catch runtime enumeration issues.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@puddly puddly merged commit 65c9745 into dev Apr 10, 2026
51 of 53 checks passed
@puddly puddly deleted the puddly/fix-list-serial-ports-when-empty branch April 10, 2026 18:28
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.

2 participants