This commit is contained in:
Home Assistant Version Control
2026-07-25 02:41:58 +00:00
parent 3dc00b2d26
commit b84bc6688e
52 changed files with 2002 additions and 219 deletions
@@ -1,5 +1,6 @@
"""Image processing and management utilities for Mail and Packages."""
import contextlib
import datetime
import hashlib
import logging
@@ -56,9 +57,12 @@ def default_image_path(
"""
storage = None
try:
storage = config_entry.get(CONF_STORAGE)
storage = config_entry.options.get(CONF_STORAGE) or config_entry.data.get(
CONF_STORAGE
)
except AttributeError:
storage = config_entry.data[CONF_STORAGE]
with contextlib.suppress(AttributeError):
storage = config_entry.get(CONF_STORAGE)
if storage:
return storage
@@ -178,7 +178,25 @@ async def login(
if account.protocol.state == NONAUTH:
try:
if oauth_token:
await account.xoauth2(user, oauth_token)
try:
res = await asyncio.wait_for(
account.xoauth2(user, oauth_token),
timeout=min(timeout, 15.0),
)
if account.protocol.state not in {AUTH, SELECTED}:
_LOGGER.error(
"OAuth login failed. Result: %s, Lines: %s",
getattr(res, "result", None),
getattr(res, "lines", None),
)
except TimeoutError as err:
_LOGGER.error(
"OAuth authentication timed out for %s. This typically indicates invalid OAuth credentials, missing 'https://mail.google.com/' scope, or a mismatched email address.",
user,
)
raise InvalidAuth(
"OAuth authentication timed out or failed"
) from err
else:
await account.login(user, pwd)
except TimeoutError:
@@ -188,7 +206,9 @@ async def login(
raise InvalidAuth from err
if account.protocol.state not in {AUTH, SELECTED}:
_LOGGER.error("Error logging in to IMAP Server")
_LOGGER.error(
"Error logging in to IMAP Server. State: %s", account.protocol.state
)
raise InvalidAuth
return account