Skip to content

Migrate serial backend from pyserial to serialx#13

Open
balloob wants to merge 2 commits into
etsinko:masterfrom
balloob:master
Open

Migrate serial backend from pyserial to serialx#13
balloob wants to merge 2 commits into
etsinko:masterfrom
balloob:master

Conversation

@balloob
Copy link
Copy Markdown

@balloob balloob commented Feb 27, 2026

Hey,

With the Open Home Foundation we're working on adding serial proxies to ESPHome. It will allow users to connect an ESPHome device to the serial port, and then connect to it via Home Assistant. Seamlessly :-)

Because python serial land has been quite stale (with fixes not getting published), we've been working on our own serial library serialx which is a drop-in replacement for python-serial. It is already used inside Home Assistant for things like Zigbee.

We will soon add support for the ESPHome serial proxies to serialx (PR) and HA (TBD), and so are looking into getting interesting integrations in HA ready to be able to leverage this.

I've asked AI to migrate this lib to serialx, so that when ESPHome support lands, it can just be a dep bump.

Would you be open for switching the serial library and test this PR?

~Paulus

(below written by AI)

CoPilot summary

This updates the library to use serialx as the serial transport backend instead of pyserial/pyserial-asyncio-fast, covering both sync and asyncio paths. The migration keeps the existing pymonoprice API behavior intact while switching underlying serial implementation.

  • Runtime migration (sync + async)

    • Replaced serial and serial_asyncio_fast usage with serialx in core runtime code.
    • Switched sync port construction from serial_for_url(...) to serialx.Serial(...) with equivalent serial settings.
    • Switched async connection creation to serialx.create_serial_connection(...).
    • Updated transport type references to serialx.SerialTransport.
  • Timeout/error compatibility

    • Introduced a module-level SerialTimeoutException and raised it on sync read timeout, preserving the package-level timeout contract used by callers/tests.
  • Dependency updates

    • Replaced pyserial and pyserial-asyncio-fast requirements with serialx>=0.7.0 in packaging and requirements files.
    • Removed now-obsolete mypy ignore entries for removed serial modules.
  • Tests aligned with new backend contract

    • Updated timeout assertion imports in tests to reference pymonoprice.SerialTimeoutException instead of serial.SerialTimeoutException.
# before
import serial
from serial_asyncio_fast import create_serial_connection

self._port = serial.serial_for_url(port_url, do_not_open=True)

# after
import serialx

self._port = serialx.Serial(
    port_url,
    baudrate=9600,
    stopbits=serialx.StopBits.ONE,
    byte_size=8,
    parity=serialx.Parity.NONE,
)
_, protocol = await serialx.create_serial_connection(loop, MonopriceProtocol, port_url, baudrate=9600)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

* Initial plan

* feat: migrate serial backend to serialx

Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>

* docs: clarify serialx port initialization

Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>
Comment thread pymonoprice/__init__.py
@balloob
Copy link
Copy Markdown
Author

balloob commented Apr 22, 2026

Home Assistant 2026.5 will have full support for ESPHome proxies and a new Serial Port selector that the Monoprice integration could leverage when migrating to serialx.

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