mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix google_mail doing blocking i/o in the event loop (take 2) (#118441)
This commit is contained in:
parent
e50defa7f5
commit
ef79842c2f
@ -32,7 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Google Mail from a config entry."""
|
||||
implementation = await async_get_config_entry_implementation(hass, entry)
|
||||
session = OAuth2Session(hass, entry, implementation)
|
||||
auth = AsyncConfigEntryAuth(session)
|
||||
auth = AsyncConfigEntryAuth(hass, session)
|
||||
await auth.check_and_refresh_token()
|
||||
hass.data[DOMAIN][entry.entry_id] = auth
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""API for Google Mail bound to Home Assistant OAuth."""
|
||||
|
||||
from functools import partial
|
||||
|
||||
from aiohttp.client_exceptions import ClientError, ClientResponseError
|
||||
from google.auth.exceptions import RefreshError
|
||||
from google.oauth2.credentials import Credentials
|
||||
@ -7,6 +9,7 @@ from googleapiclient.discovery import Resource, build
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import (
|
||||
ConfigEntryAuthFailed,
|
||||
ConfigEntryNotReady,
|
||||
@ -20,9 +23,11 @@ class AsyncConfigEntryAuth:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
oauth2_session: config_entry_oauth2_flow.OAuth2Session,
|
||||
) -> None:
|
||||
"""Initialize Google Mail Auth."""
|
||||
self._hass = hass
|
||||
self.oauth_session = oauth2_session
|
||||
|
||||
@property
|
||||
@ -58,4 +63,6 @@ class AsyncConfigEntryAuth:
|
||||
async def get_resource(self) -> Resource:
|
||||
"""Get current resource."""
|
||||
credentials = Credentials(await self.check_and_refresh_token())
|
||||
return build("gmail", "v1", credentials=credentials)
|
||||
return await self._hass.async_add_executor_job(
|
||||
partial(build, "gmail", "v1", credentials=credentials)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user