Allow Twitter notifications to include media#8282
Conversation
|
It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
|
@MikeChristianson, thanks for your PR! By analyzing the history of the files in this pull request, we identified @pvizeli, @balloob and @fabaff to be potential reviewers. |
f05bb1f to
ffc7794
Compare
0184932 to
7e93af4
Compare
There was a problem hiding this comment.
Other notify platforms are using ATTR_DATA for it. That way if a platform requires extra metadata, we don't need to add extra fields. So please add it to Twitter via ATTR_DATA.
There was a problem hiding this comment.
I attempted that approach, initially, but was not successful. I'll give it another try and look for examples.
There was a problem hiding this comment.
Please remove this file. We fixed the issue in our tests that left this artifact.
There was a problem hiding this comment.
Media path has to be allowed by hass.config.is_allowed_path
There was a problem hiding this comment.
This is very inefficient. You are now generating up to 99 values. Prefer
if 199 > resp.status_code < 300:There was a problem hiding this comment.
Shouldn't this method not be called if media_path is not set ?
Also, prefer a guard clause:
if not media_path:
return
media_type, _ = mimetipes.guess_type(…)There was a problem hiding this comment.
Since media_id is going to be None, why not just return None and you can remove the else.
…mentation. The Twitter notifier uses the Twitter-recommended async chunked media/upload approach and tries to convey the correct mime type of the media. Twitter implementation based on https://github.com/geduldig/TwitterAPI/blob/master/examples/upload_video.py.
7e93af4 to
81a3be6
Compare
balloob: "Please remove this file. We fixed the issue in our tests that left this artifact." balloob: "…prefer a guard clause" balloob: "This is very inefficient. You are now generating up to 99 values." balloob: "Since media_id is going to be None, why not just return None and you can remove the else."
… if a platform requires extra metadata, we don't need to add extra fields. So please add it to Twitter via ATTR_DATA."
|
@balloob Please have another look, thanks. |
|
Awesome! 🐬 🎉 |
|
Thanks, @balloob! 🎊 Glad I could help the community, too. |
data may be None if twitter data property unconfigured:
File "/opt/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/notify/twitter.py", line 63, in send_message
media = data.get(ATTR_MEDIA)
|
Can you please update the component page to include the correct formatting for images, can send txt tweet no problems, yet with the above example using both a local path and http:// I can not get the notify to work once I add the include media code. |
* Allow notifications to include media, with Twitter as the first implementation. The Twitter notifier uses the Twitter-recommended async chunked media/upload approach and tries to convey the correct mime type of the media. Twitter implementation based on https://github.com/geduldig/TwitterAPI/blob/master/examples/upload_video.py. * Changes based on balloob's review: balloob: "Please remove this file. We fixed the issue in our tests that left this artifact." balloob: "…prefer a guard clause" balloob: "This is very inefficient. You are now generating up to 99 values." balloob: "Since media_id is going to be None, why not just return None and you can remove the else." * balloob: "Other notify platforms are using ATTR_DATA for it. That way if a platform requires extra metadata, we don't need to add extra fields. So please add it to Twitter via ATTR_DATA."
…ome-assistant#8513) data may be None if twitter data property unconfigured: File "/opt/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/notify/twitter.py", line 63, in send_message media = data.get(ATTR_MEDIA)
Allow Twitter notifications to include media.
The notifier uses the Twitter-recommended async chunked media/upload approach and tries to convey the correct mime type of the media. The implementation is based on https://github.com/geduldig/TwitterAPI/blob/master/examples/upload_video.py.