Add additional debug logging for imap (#98877)

pull/98935/head
Jan Bouwhuis 2023-08-24 01:02:52 +02:00 committed by GitHub
parent f1fb28aad5
commit a1307e117d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 2 deletions

View File

@ -65,14 +65,28 @@ async def connect_to_server(data: Mapping[str, Any]) -> IMAP4_SSL:
else:
ssl_context = create_no_verify_ssl_context()
client = IMAP4_SSL(data[CONF_SERVER], data[CONF_PORT], ssl_context=ssl_context)
_LOGGER.debug(
"Wait for hello message from server %s on port %s, verify_ssl: %s",
data[CONF_SERVER],
data[CONF_PORT],
data.get(CONF_VERIFY_SSL, True),
)
await client.wait_hello_from_server()
if client.protocol.state == NONAUTH:
_LOGGER.debug(
"Authenticating with %s on server %s",
data[CONF_USERNAME],
data[CONF_SERVER],
)
await client.login(data[CONF_USERNAME], data[CONF_PASSWORD])
if client.protocol.state not in {AUTH, SELECTED}:
raise InvalidAuth("Invalid username or password")
if client.protocol.state == AUTH:
_LOGGER.debug(
"Selecting mail folder %s on server %s",
data[CONF_FOLDER],
data[CONF_SERVER],
)
await client.select(data[CONF_FOLDER])
if client.protocol.state != SELECTED:
raise InvalidFolder(f"Folder {data[CONF_FOLDER]} is invalid")
@ -312,6 +326,9 @@ class ImapPollingDataUpdateCoordinator(ImapDataUpdateCoordinator):
self, hass: HomeAssistant, imap_client: IMAP4_SSL, entry: ConfigEntry
) -> None:
"""Initiate imap client."""
_LOGGER.debug(
"Connected to server %s using IMAP polling", entry.data[CONF_SERVER]
)
super().__init__(hass, imap_client, entry, timedelta(seconds=10))
async def _async_update_data(self) -> int | None:
@ -354,6 +371,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
self, hass: HomeAssistant, imap_client: IMAP4_SSL, entry: ConfigEntry
) -> None:
"""Initiate imap client."""
_LOGGER.debug("Connected to server %s using IMAP push", entry.data[CONF_SERVER])
super().__init__(hass, imap_client, entry, None)
self._push_wait_task: asyncio.Task[None] | None = None