From a1307e117dd4ff466ed1e19068021db29bf3d0bc Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Thu, 24 Aug 2023 01:02:52 +0200 Subject: [PATCH] Add additional debug logging for imap (#98877) --- homeassistant/components/imap/coordinator.py | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/imap/coordinator.py b/homeassistant/components/imap/coordinator.py index b9b541997a3..72be5e9bcf0 100644 --- a/homeassistant/components/imap/coordinator.py +++ b/homeassistant/components/imap/coordinator.py @@ -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