Allow ESPHome transport to be used across threads and event loops#65
Merged
Allow ESPHome transport to be used across threads and event loops#65
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #65 +/- ##
==========================================
+ Coverage 90.21% 90.49% +0.27%
==========================================
Files 19 19
Lines 3087 3145 +58
==========================================
+ Hits 2785 2846 +61
+ Misses 302 299 -3 ☔ 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.
On async transports, we expose a
.serialproperty that references the sync serial interface. This is strictly for backwards compatibility, as some packages rely on accessing modem pins or the serial port name from this sync API.Zigpy unfortunately has two weird uses:
transport.serial.dtr = Trueto set modem lines (once we migrate zigpy to use serialx strictly, this will be transformed intoawait transport.set_modem_lines(dtr=True)). This calls a sync API from an async context, which runs an async operation synchronously in the parent event loop using the parent event loop. This is an instant asyncio deadlock. Worse yet, Home Assistant registers signal handlers and makes this deadlock worse by being unkillable withCTRL-Cand logging absolutely nothing past this point.To work around these issues, I've made some tweaks:
asyncio.run_coroutine_threadsafe, etc. This change has optimizations for when the API instance's loop is the same as the current loop.set_modem_pinscan now be called from an async context but it no longer blocks at all, returning instantly. We log a deprecation warning here.get_modem_pinsthrows aRuntimeError. There's no sensible way to implement this.