-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support v2 manifests and Simplicity SDK builds #17
Open
tl-sl
wants to merge
8
commits into
NabuCasa:dev
Choose a base branch
from
tl-sl:v24
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−53
Conversation
This file contains 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
You can mock out sqlite3, we don't use it. |
We've also adjusted the serial API to properly close ports asynchronously. Untested: diff --git a/src/webserial_transport.py b/src/webserial_transport.py
index 02da299..0d80c7e 100644
--- a/src/webserial_transport.py
+++ b/src/webserial_transport.py
@@ -21,7 +21,7 @@ except ImportError:
_SERIAL_PORT = None
-_SERIAL_PORT_CLOSING_QUEUE = []
+_SERIAL_PORT_CLOSING_TASKS = []
_LOGGER = logging.getLogger(__name__)
@@ -106,14 +106,23 @@ class WebSerialTransport(asyncio.Transport):
self._js_writer.releaseLock()
self._js_writer = None
+ closing_task = None
+
if self._port is not None:
- _SERIAL_PORT_CLOSING_QUEUE.append(
- asyncio.create_task(close_port(self._port))
- )
+ closing_task = asyncio.create_task(close_port(self._port))
self._port = None
if self._protocol is not None:
- self._protocol.connection_lost(exception)
+ if closing_task is None:
+ self._protocol.connection_lost(exception)
+ else:
+ closing_task.add_done_callback(
+ lambda _: self._protocol.connection_lost(exception)
+ )
+ closing_task.add_done_callback(
+ lambda _: _SERIAL_PORT_CLOSING_TASKS.remove(closing_task)
+ )
+
self._protocol = None
def close(self) -> None:
@@ -136,11 +145,12 @@ async def create_serial_connection(
rtscts=False,
xonxoff=False,
) -> tuple[WebSerialTransport, asyncio.Protocol]:
- # XXX: Since asyncio's `transport.close` is synchronous but JavaScript's is not, we
- # must delegate closing to a task and then "block" at the next asynchronous entry
- # point to allow the serial port to be re-opened immediately after being closed
- while _SERIAL_PORT_CLOSING_QUEUE:
- await _SERIAL_PORT_CLOSING_QUEUE.pop()
+ while _SERIAL_PORT_CLOSING_TASKS:
+ _LOGGER.warning(
+ "Serial connection was not closed before a new one was opened!"
+ " Waiting before opening a new one."
+ )
+ await _SERIAL_PORT_CLOSING_TASKS.pop()
# `url` is ignored, `_SERIAL_PORT` is used instead
await _SERIAL_PORT.open( |
I have mocked sqlite3 and imported your patch with minor fixes, seems to be working. |
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.
Bump universal-silabs-flasher == 0.0.24 and make various adjustments to enums for new manifest formats.
This allows the web flasher to work with v2 manifests from template builder and Simplicity SDK builds.
NB: Zigpy is pulling in sqlite3, not sure that is really needed or can just be mocked?