Re-read last imap_email_content email when no change#36065
Merged
frenck merged 3 commits intohome-assistant:devfrom May 25, 2020
Merged
Re-read last imap_email_content email when no change#36065frenck merged 3 commits intohome-assistant:devfrom
frenck merged 3 commits intohome-assistant:devfrom
Conversation
Member
MartinHjelmare
left a comment
There was a problem hiding this comment.
It would be good to add explicit return None in the read_next method at all places where the method can exit.
…ture/imap_email_content/nomessage1
Contributor
Author
|
What is your proposal for reconnect case? It will also return None but theoretically it could be fixed in a better way. I am unsure what is the best way. |
Member
|
For now just |
Contributor
Author
|
The more I look at it, the more the method looks annoying... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
In the Bug #35975 it is stated an issue that the state changes to Unknown after some time. This is actually not dependent on time, but on arrival of emails. So basically if no email arrives, the code will not find any unread email at all and default to returning None out of the read_next() method. However, this now is obviously undesired behavior if people decide to keep the emails in the mailbox.
This basically restores the original intent of staying in the previous state by trying to return the last detected email, if no change of emails occur at all, but supports still the deleted email usecase, because in that case email would become None, and state would turn to None again.
I assume that this matches more the initial intent of this piece of code
Type of change
Additional information
There is another change, which is related to the python imap library. If you for example archive emails, the uid() method returns an empty list. Looks like it was initially expected to return None, but to prevent subscript exceptions in the following line, I treat this empty list also as None.
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: