Skip to content

Reset imap email content state if no email#35123

Merged
MartinHjelmare merged 3 commits intohome-assistant:devfrom
isk0001y:feature/imap_email_content/nomessage0
May 6, 2020
Merged

Reset imap email content state if no email#35123
MartinHjelmare merged 3 commits intohome-assistant:devfrom
isk0001y:feature/imap_email_content/nomessage0

Conversation

@isk0001y
Copy link
Copy Markdown
Contributor

@isk0001y isk0001y commented May 3, 2020

Breaking change

There is a breaking change: The state of the imap_email_content is replaced when there is no email found. The current implementation does not change state if there is no matching email; meaning even if one deletes the matching email, the state still shows that email. This is IMHO wrong and annoying and makes it very complicated to use this sensor. With this change any other thing like an automation can react onto the arrival of an email

Proposed change

Replace the state of the sensor with unknown if there is no matching email at all.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

if email_message is None:
self._message = "unknown"
self._state_attributes = {
ATTR_FROM: "unknown",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our standard is to not add the item at all to state attributes if the value is unknown.

email_message = self._email_reader.read_next()

if email_message is None:
self._message = "unknown"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use None to represent unknown state.

@MartinHjelmare MartinHjelmare changed the title no-message: If there is no message at all, replace internal state Reset imap email content state if no email May 3, 2020
@isk0001y
Copy link
Copy Markdown
Contributor Author

isk0001y commented May 3, 2020

Ok, I will work on this. It will require time, because I have to test if all also works with None. :-D

@amelchio
Copy link
Copy Markdown
Contributor

amelchio commented May 3, 2020

With this change any other thing like an automation can react onto the arrival of an email

I think this sensor is inherently hard to use. How about firing new emails as events?

@isk0001y
Copy link
Copy Markdown
Contributor Author

isk0001y commented May 6, 2020

I am not deep inside this application. I can do the event thing at a later stage...

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MartinHjelmare MartinHjelmare merged commit 541b666 into home-assistant:dev May 6, 2020
@lock lock Bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

imap_email_content: sensor could consider not existence of any email

5 participants