-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: dev
Are you sure you want to change the base?
Conversation
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( |
7e9fa0b
to
358672b
Compare
I have mocked sqlite3 and imported your patch with minor fixes, seems to be working. |
Sorry this took so long to review! The router firmware code is present was released in 0.0.26, could you bump the flasher and add some defaults for the router firmware as well? |
Yes, sure. Have merged the router support into this PR. I have been testing this for a while via live deploy via my darkxst web flasher. Also a minor bug fix to universal-silabs-flasher in NabuCasa/universal-silabs-flasher#92 |
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?