-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imap email parser #13362
Imap email parser #13362
Conversation
Kodi media_content_type attribute display fix
fixes attribute display for unknown media
"""Initialize the sensor.""" | ||
self.hass = hass | ||
self._email_reader = email_reader | ||
self._name = name | ||
self._allowed_senders = [sender.upper() for sender in allowed_senders] | ||
self._value_template = value_template | ||
self._body_regex = re.compile(body_regex) if body_regex is not None else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (85 > 79 characters)
Why does this change the |
it doesn't. I do not use Git often, so forgot to learn what does rebase mean ))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the two inline comments: This PR does include changes to the file homeassistant/components/media_player/kodi.py
- which it shouldn't. Please remove that from this PR.
EmailContentSensor.get_msg_text(email_message)) | ||
if parsed_body is not None: | ||
for attr in parsed_body.groupdict().keys(): | ||
self._state_attributes[attr] = parsed_body.\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that the names of the groups should just be used as keys here. What if a user has the bright idea of calling his group last_updated
? Or friendly_name
? I'm not sure in which subtle way this will break HA. How about instead having some ATTR_PARSED_BODY
or something, and then set self._state_attributes[ATTR_PARSED_BODY] = {attr : parsed_body.group(attr) for attr in parsed_body.groupdict().keys()}
"""Initialize the sensor.""" | ||
self.hass = hass | ||
self._email_reader = email_reader | ||
self._name = name | ||
self._allowed_senders = [sender.upper() for sender in allowed_senders] | ||
self._value_template = value_template | ||
self._body_regex = re.compile(body_regex) if body_regex is not None \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user does specify an invalid regex, this should not simply crash. Either an error should be emitted here, or (even better) validation should take care of this. I don't see a regex validator in config_validation.py
, but that shouldn't be too hard.
We should not add regex support. We should use a value_template, like in the rest of Home Assistant. |
Well, I agree that system should be as simple as possible, but how could look my case with several values in msg body? Is it possible to use Python string routines for such parsing? |
I think that's too complex to expose via configuration. This should be kept in a custom component or something. |
@kuzin2006 Can you just email yourself json and use value_template? |
I'm going to close this as it's too complicated to be part of Home Assistant. Consider using a custom component. |
Description:
This PR adds email body parsing functionality with use of regular expressions. If option 'body_regex' is present, the named groups of given regexp are exposed as sensor attributes, so further processing of complex email responses is possible.
My case was to process Surveillance DVR's response. The only way to retrieve data is email, in unchangeable format:
Example entry for
configuration.yaml
:As a result, sensor attributes 'event', 'time', 'channel', 'device', 'ip' appear.
Checklist:
tox
. Your PR cannot be merged unless tests pass