mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Re-read last imap_email_content email when no change (#36065)
This commit is contained in:
parent
2375e00029
commit
71ebf8738f
@ -103,6 +103,8 @@ class EmailReader:
|
|||||||
|
|
||||||
if message_data is None:
|
if message_data is None:
|
||||||
return None
|
return None
|
||||||
|
if message_data[0] is None:
|
||||||
|
return None
|
||||||
raw_email = message_data[0][1]
|
raw_email = message_data[0][1]
|
||||||
email_message = email.message_from_bytes(raw_email)
|
email_message = email.message_from_bytes(raw_email)
|
||||||
return email_message
|
return email_message
|
||||||
@ -126,13 +128,22 @@ class EmailReader:
|
|||||||
self._last_id = int(message_uid)
|
self._last_id = int(message_uid)
|
||||||
return self._fetch_message(message_uid)
|
return self._fetch_message(message_uid)
|
||||||
|
|
||||||
|
return self._fetch_message(str(self._last_id))
|
||||||
|
|
||||||
except imaplib.IMAP4.error:
|
except imaplib.IMAP4.error:
|
||||||
_LOGGER.info("Connection to %s lost, attempting to reconnect", self._server)
|
_LOGGER.info("Connection to %s lost, attempting to reconnect", self._server)
|
||||||
try:
|
try:
|
||||||
self.connect()
|
self.connect()
|
||||||
|
_LOGGER.info(
|
||||||
|
"Reconnect to %s succeeded, trying last message", self._server
|
||||||
|
)
|
||||||
|
if self._last_id is not None:
|
||||||
|
return self._fetch_message(str(self._last_id))
|
||||||
except imaplib.IMAP4.error:
|
except imaplib.IMAP4.error:
|
||||||
_LOGGER.error("Failed to reconnect")
|
_LOGGER.error("Failed to reconnect")
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class EmailContentSensor(Entity):
|
class EmailContentSensor(Entity):
|
||||||
"""Representation of an EMail sensor."""
|
"""Representation of an EMail sensor."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user