Fix ESPHome transport by subscribing serial proxy instance#29
Merged
puddly merged 1 commit intoMar 6, 2026
Merged
Conversation
Owner
|
If it runs on a real device then it's good enough for me 😄. We're still iterating on the |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## puddly/esphome #29 +/- ##
==================================================
- Coverage 63.20% 59.51% -3.70%
==================================================
Files 11 13 +2
Lines 1166 1408 +242
==================================================
+ Hits 737 838 +101
- Misses 429 570 +141 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was messing around with the ESPHome proxy PR with serialx and ran into an issue.
Below is written by AI:
Summary
Fix
esphome://serial transports so they explicitly subscribe to the selected serial-proxy instance before expecting RX data.This restores end-to-end behavior for ESPHome serial proxy setups where writes succeed but no inbound bytes are delivered unless
serial_proxy_subscribe(instance)is called.Problem
With recent ESPHome serial proxy behavior, connecting and configuring a serial proxy instance is not enough to receive data events. The client must explicitly subscribe to that instance.
serialxcurrently:subscribe_serial_proxy_data(...)callback…but never sends
serial_proxy_subscribe(instance).Observed failure mode
On a live setup (
connect-proxy-sendspinat192.168.1.227, Denon AVR-X2700H on RS232):serialx.open_serial_connection("esphome://192.168.1.227/1", baudrate=9600)writer.write(b"PW?\\r")reader.read(...)timed out with empty bytes repeatedlyAt the same time, the exact same command path worked immediately when sending
api.serial_proxy_subscribe(1)manually first.Root Cause
subscribe_serial_proxy_data(...)registers a callback for data events, but does not itself request that the server begin streaming a specific serial instance.The explicit instance request is done via:
serial_proxy_subscribe(instance)serial_proxy_unsubscribe(instance)on close.Changes
serialx/platforms/serial_esphome.pyself._instance_subscribed_subscribe_instance()_unsubscribe_instance()_subscribe_instance()before setting the data callback_unsubscribe_instance()before API disconnectESPHomeSerialpathESPHomeSerialTransportpathBackward compatibility
Some older
aioesphomeapivariants may not expose subscribe/unsubscribe helpers.To avoid regressions, this patch uses
getattr(...)and no-ops when those methods are unavailable.Tests
Added:
tests/test_serial_esphome.pytest_transport_subscribes_instance_and_unsubscribes_on_closeserial_proxy_subscribe(instance)is called on connectserial_proxy_unsubscribe(instance)is called on closetest_transport_works_without_instance_subscribe_apiVerification
Unit
pytest -q -o addopts='' tests/test_serial_esphome.py2 passedManual (live hardware)
On the setup above:
Before patch:
esphome://.../1writes sent, but RX stayed empty.After patch:
PW?\roverserialxreturnsPWON\rPowerState.ONThis confirms the fix in real-world traffic and not only mocked tests.