-
Notifications
You must be signed in to change notification settings - Fork 101
Python 3.14 compatibility + EZSP-over-TCP stability fixes #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 2 commits
2374548
3f34b5c
7cf20c0
3ad85ef
f43c38f
384975d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,9 @@ def is_tcp_serial_port(self) -> bool: | |
|
|
||
| async def _startup_reset(self) -> None: | ||
| """Start EZSP and reset the stack.""" | ||
| if self._gw is None: | ||
| raise EzspError("Gateway is not connected") | ||
|
|
||
| # `zigbeed` resets on startup | ||
| if self.is_tcp_serial_port: | ||
| try: | ||
|
|
@@ -220,8 +223,21 @@ async def get_xncp_features(self) -> xncp.FirmwareFeatures: | |
|
|
||
| async def disconnect(self): | ||
| self.stop_ezsp() | ||
| if self._gw: | ||
| await self._gw.disconnect() | ||
| if self._gw is not None: | ||
| try: | ||
| await self._gw.disconnect() | ||
| except ConnectionError: | ||
| # The secondary event loop is dead. Force-close the | ||
| # underlying TCP socket so ser2net (or similar) releases | ||
| # the serial port for subsequent connection attempts. | ||
| try: | ||
| ash = self._gw._obj._transport | ||
| if ash is not None and ash._transport is not None: | ||
| sock = ash._transport.get_extra_info("socket") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if sock is not None: | ||
| sock.close() | ||
| except Exception: | ||
| pass | ||
| self._gw = None | ||
|
|
||
| async def _command(self, name: str, *args: Any, **kwargs: Any) -> Any: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,8 @@ def error_received(self, code: t.NcpResetCode) -> None: | |
|
|
||
| async def wait_for_startup_reset(self) -> None: | ||
| """Wait for the first reset frame on startup.""" | ||
| assert self._startup_reset_future is None | ||
| self._startup_reset_future = asyncio.get_running_loop().create_future() | ||
| if self._startup_reset_future is None: | ||
| self._startup_reset_future = asyncio.get_running_loop().create_future() | ||
|
|
||
| try: | ||
| await self._startup_reset_future | ||
|
|
@@ -98,21 +98,26 @@ async def reset(self): | |
| return await self._reset_future | ||
|
|
||
| self._transport.send_reset() | ||
| self._reset_future = asyncio.get_event_loop().create_future() | ||
| self._reset_future = asyncio.get_running_loop().create_future() | ||
| self._reset_future.add_done_callback(self._reset_cleanup) | ||
|
|
||
| async with asyncio_timeout(RESET_TIMEOUT): | ||
| return await self._reset_future | ||
|
|
||
|
|
||
| async def _connect(config, api): | ||
| loop = asyncio.get_event_loop() | ||
| loop = asyncio.get_running_loop() | ||
|
|
||
| connection_done_future = loop.create_future() | ||
|
|
||
| gateway = Gateway(api, connection_done_future) | ||
| protocol = AshProtocol(gateway) | ||
|
|
||
| # Pre-create the startup reset future before opening the connection so that | ||
| # reset frames arriving immediately after connect are captured by | ||
| # reset_received() instead of triggering enter_failed_state(). | ||
| gateway._startup_reset_future = loop.create_future() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be simpler to have |
||
|
|
||
| if config[zigpy.config.CONF_DEVICE_FLOW_CONTROL] is None: | ||
| xon_xoff, rtscts = True, False | ||
| else: | ||
|
|
@@ -135,7 +140,7 @@ async def _connect(config, api): | |
|
|
||
| async def connect(config, api, use_thread=True): | ||
| if use_thread: | ||
| api = ThreadsafeProxy(api, asyncio.get_event_loop()) | ||
| api = ThreadsafeProxy(api, asyncio.get_running_loop()) | ||
| thread = EventLoopThread() | ||
| await thread.start() | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the remote signal EOF without closing? The asyncio docs state machine shows:
And the docs state:
I don't think this change is right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. I borrowed that hunk from #711's commit body (the closed-unmerged PR by @aautem this one rebased from) without validating its premise myself, it claimed an init-time spurious EOF on serial-over-TCP. You're right that the asyncio docs are clear, and honestly I don't have a reproduction of that scenario on my own setup either: stock 0.49.1 on Python 3.14.2 against the ZBT-2 over
stream_servercompletes EZSP startup cleanly on first connect (log in the gist as01-stock-probe.log).Dropping it and deferring to you on this one. You know this code far better than I do, and I'd rather get it right than push something speculative. Door's open if a concrete EOF-during-init case surfaces later for some bridge config.
Reverted in
f43c38f.