fix(win32): handle missing asyncio protocol methods in _MethodProxy#97
Conversation
On Windows, when a serial port closes or disconnects, asyncio's proactor event loop calls eof_received() on the transport's protocol. _MethodProxy looks this up via __getattr__ from a fixed _mapping dict, but eof_received is not in that mapping, so a KeyError is raised:
Fatal error: protocol.eof_received() call failed.
...
File ".../serialx/platforms/serial_win32.py", line 434, in __getattr__
return self._mapping[name]
KeyError: 'eof_received'
This surfaces as a noisy Fatal error log on every HA shutdown/restart cycle when a Zigbee or other serial device is connected on Windows.
|
Thanks for the PR. I think it would be better to just proxy |
|
Fair point — it's more explicit and doesn't silently swallow arbitrary unknown attribute access. The correct behaviour for So the mapping entry would be: "eof_received": lambda: False,That's more honest than a catch-all no-op: it documents exactly which asyncio protocol method was missing and returns the semantically correct value rather than Update the PR description accordingly — replace the proposed |
Change the __getattr__ method to raise an AttributeError instead of returning a no-op lambda for missing attributes.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #97 +/- ##
==========================================
- Coverage 92.23% 92.16% -0.08%
==========================================
Files 22 22
Lines 3632 3637 +5
==========================================
+ Hits 3350 3352 +2
- Misses 282 285 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add eof_received method to handle EOF in asyncio proactor
Add return type annotation for eof_received method.
|
Thanks! |
On Windows, when a serial port closes or disconnects, asyncio's proactor event loop calls eof_received() on the transport's protocol. _MethodProxy looks this up via getattr from a fixed _mapping dict, but eof_received is not in that mapping, so a KeyError is raised: Fatal error: protocol.eof_received() call failed.
...
File ".../serialx/platforms/serial_win32.py", line 434, in getattr
return self._mapping[name]
KeyError: 'eof_received'
This surfaces as a noisy Fatal error log on every HA shutdown/restart cycle when a Zigbee or other serial device is connected on Windows.