Detected blocking call to load_verify_locations - fix#213
Conversation
Summary of ChangesHello @Paja-git, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the responsiveness and stability of the Toyota Connected Services integration by resolving a blocking operation during the configuration flow. By offloading potentially blocking I/O operations to a separate thread, the integration prevents freezing the Home Assistant user interface and ensures a smoother setup and reauthentication process. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a blocking call in the config flow by correctly moving the MyT client instantiation and login call to the Home Assistant executor. This prevents blocking the event loop, improving overall system responsiveness. The version is also bumped accordingly.
My review focuses on improving the implementation's maintainability. I've suggested a simplification for running the async login method in the executor, which makes the code more concise and leverages the standard library more effectively.
| def _sync_login(): | ||
| loop = asyncio.new_event_loop() | ||
| try: | ||
| return loop.run_until_complete(client.login()) | ||
| finally: | ||
| loop.close() | ||
|
|
||
| await self.hass.async_add_executor_job(_sync_login) |
There was a problem hiding this comment.
The nested _sync_login function can be simplified. Instead of defining a function to create a new event loop and run the coroutine, you can use asyncio.run. This function is designed for this exact purpose and makes the code more concise and readable. It's available since Python 3.7, and your project requires Python >= 3.13.
Using asyncio.run also helps to avoid code duplication, as a similar pattern with a new event loop is used elsewhere in the codebase (e.g., in __init__.py).
await self.hass.async_add_executor_job(asyncio.run, client.login())The "Detected blocking call to load_verify_locations" warning occurs when SSL certificate verification happens synchronously in the async event loop. This typically happens during HTTP client initialization or SSL context setup.
for more information, see https://pre-commit.ci
Add return type annotation (-> Any)
for more information, see https://pre-commit.ci
config_flow.py - fix
bump version 2.1.1