Fix bug with imap sensor (#2546)

Fixed bug where the new connection was not saved when a reconnect
attempt was made; broadended the exception catching.
pull/2550/head
Dan 2016-07-17 16:02:14 -04:00 committed by Paulus Schoutsen
parent a8f34eb728
commit 1da94928c6
1 changed files with 2 additions and 3 deletions

View File

@ -90,12 +90,11 @@ class ImapSensor(Entity):
self.connection.select()
self._unread_count = len(self.connection.search(
None, 'UnSeen')[1][0].split())
except imaplib.IMAP4.abort:
except imaplib.IMAP4.error:
_LOGGER.info("Connection to %s lost, attempting to reconnect",
self._server)
try:
self._login()
self.update()
self.connection = self._login()
except imaplib.IMAP4.error:
_LOGGER.error("Failed to reconnect.")