Skip to content

Detected blocking call to load_verify_locations - fix#213

Open
Paja-git wants to merge 7 commits into
pytoyoda:mainfrom
Paja-git:main
Open

Detected blocking call to load_verify_locations - fix#213
Paja-git wants to merge 7 commits into
pytoyoda:mainfrom
Paja-git:main

Conversation

@Paja-git
Copy link
Copy Markdown
Contributor

config_flow.py - fix
bump version 2.1.1

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Blocking Call Fix: The primary change addresses a blocking call related to load_verify_locations within the config_flow.py file. This was resolved by moving the MyT client instantiation and the client.login() call into self.hass.async_add_executor_job, ensuring these operations run in a separate thread and do not block the Home Assistant event loop.
  • Version Bump: The integration's version has been updated from v2.1.0 to v2.1.1 in both manifest.json and pyproject.toml to reflect the implemented fix.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread custom_components/toyota/config_flow.py Outdated
Comment on lines +79 to +86
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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())

Paja-git and others added 7 commits March 5, 2026 13:08
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.
Add return type annotation (-> Any)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants