Suppress imap logging on reconnect and presume state (#90826)
This commit is contained in:
parent
58ac8404ef
commit
94817f61e5
2 changed files with 8 additions and 11 deletions
|
@ -209,10 +209,9 @@ class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]):
|
|||
await self.imap_client.stop_wait_server_push()
|
||||
await self.imap_client.close()
|
||||
await self.imap_client.logout()
|
||||
except (AioImapException, asyncio.TimeoutError) as ex:
|
||||
except (AioImapException, asyncio.TimeoutError):
|
||||
if log_error:
|
||||
self.async_set_update_error(ex)
|
||||
_LOGGER.warning("Error while cleaning up imap connection")
|
||||
_LOGGER.debug("Error while cleaning up imap connection")
|
||||
self.imap_client = None
|
||||
|
||||
async def shutdown(self, *_) -> None:
|
||||
|
@ -276,30 +275,30 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
|
|||
try:
|
||||
number_of_messages = await self._async_fetch_number_of_messages()
|
||||
except InvalidAuth as ex:
|
||||
await self._cleanup()
|
||||
_LOGGER.warning(
|
||||
"Username or password incorrect, starting reauthentication"
|
||||
)
|
||||
self.config_entry.async_start_reauth(self.hass)
|
||||
self.async_set_update_error(ex)
|
||||
await self._cleanup()
|
||||
await asyncio.sleep(BACKOFF_TIME)
|
||||
except InvalidFolder as ex:
|
||||
_LOGGER.warning("Selected mailbox folder is invalid")
|
||||
await self._cleanup()
|
||||
self.config_entry.async_set_state(
|
||||
self.hass,
|
||||
ConfigEntryState.SETUP_ERROR,
|
||||
"Selected mailbox folder is invalid.",
|
||||
)
|
||||
self.async_set_update_error(ex)
|
||||
await self._cleanup()
|
||||
await asyncio.sleep(BACKOFF_TIME)
|
||||
except (
|
||||
UpdateFailed,
|
||||
AioImapException,
|
||||
asyncio.TimeoutError,
|
||||
) as ex:
|
||||
self.async_set_update_error(ex)
|
||||
await self._cleanup()
|
||||
self.async_set_update_error(ex)
|
||||
await asyncio.sleep(BACKOFF_TIME)
|
||||
continue
|
||||
else:
|
||||
|
@ -312,13 +311,11 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
|
|||
await idle
|
||||
|
||||
except (AioImapException, asyncio.TimeoutError):
|
||||
_LOGGER.warning(
|
||||
_LOGGER.debug(
|
||||
"Lost %s (will attempt to reconnect after %s s)",
|
||||
self.config_entry.data[CONF_SERVER],
|
||||
BACKOFF_TIME,
|
||||
)
|
||||
self.async_set_update_error(UpdateFailed("Lost connection"))
|
||||
await self._cleanup()
|
||||
await asyncio.sleep(BACKOFF_TIME)
|
||||
|
||||
async def shutdown(self, *_) -> None:
|
||||
|
|
|
@ -313,9 +313,9 @@ async def test_lost_connection_with_imap_push(
|
|||
assert "Lost imap.server.com (will attempt to reconnect after 10 s)" in caplog.text
|
||||
|
||||
state = hass.states.get("sensor.imap_email_email_com")
|
||||
# we should have an entity with an unavailable state
|
||||
# Our entity should keep its current state as this
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert state.state == "0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("imap_has_capability", [True], ids=["push"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue