Skip to content

Move IMAP Email Content body to an attribute#11096

Merged
balloob merged 2 commits into
home-assistant:devfrom
notoriousbdg:imap_body_to_attribute
Jan 2, 2018
Merged

Move IMAP Email Content body to an attribute#11096
balloob merged 2 commits into
home-assistant:devfrom
notoriousbdg:imap_body_to_attribute

Conversation

@notoriousbdg
Copy link
Copy Markdown
Contributor

@notoriousbdg notoriousbdg commented Dec 11, 2017

Description:

This change to IMAP Email Content sensor makes the state the email subject and moves the body to an attribute. This is to work around the new 255 character limit for states.

Related issue (if applicable): fixes #10512

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4199

Example entry for configuration.yaml (if applicable):

- platform: imap_email_content
  server: imap.gmail.com
  port: 993
  username: !secret imap_username
  password: !secret imap_password
  senders:
    - !secret imap_email1
    - !secret imap_email2

Checklist:

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.


if self.sender_allowed(email_message):
message_body = EmailContentSensor.get_msg_text(email_message)
message_body = EmailContentSensor.get_msg_subject(email_message)
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.

The variable name is no longer accurate.

@notoriousbdg
Copy link
Copy Markdown
Contributor Author

Thanks for catching that. I've fixed the variable name.

Technically this is a breaking change since the default state value is now the email subject instead of the email body, but only if value_template is not specified in the sensor config. What's the proper way to flag this as a breaking change?

@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Dec 13, 2017

@balloob I think this sensor should not be a sensor and just fire events. At the moment it's a wired stuff.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 2, 2018

@pvizeli you are right. We should convert this to just fire events. But for now, this PR is fine.

@balloob balloob merged commit e2cec9b into home-assistant:dev Jan 2, 2018
@randellhodges
Copy link
Copy Markdown
Contributor

Is this issue because of the schema design of the states table?

With more and more things adding attributes for display type of purposes, do you see the need for either a properties object that isn't logged, or maybe configuration on the recorder that allows you to ignore or filter out attributes before it is written to the database?

@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 2, 2018

No, if the sensor was meant to show the last item, it doesn't do that. Instead it cycles through 1 each time so people can listen for state changes of each email. This means they just want events when email arrives, making automation go faster too because you're not waiting for older email to be cycled through the state.

@balloob balloob mentioned this pull request Jan 11, 2018
@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
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 fails in 0.57.2 due to state being larger than 255 characters

5 participants