Initial support for Apple TV#5698
Conversation
|
Hello @postlund, When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es). The commits that are missing a linked GitHub account are the following:
Unfortunately, we are unable to accept this pull request until this situation is corrected. Here are your options:
We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community. Thanks, I look forward to checking this PR again soon! ❤️ |
|
I confirmed this works for me on an aTV 4 (and commented on the linked pyatv issue as such) |
|
Wow I didn't think this protocol worked for the old apple tvs. I thought it was new for the atv4 and the new remote app. Nice work. |
There was a problem hiding this comment.
Please use the newer access_token implementation. There's an example here.
There was a problem hiding this comment.
You shouldn't have to implement this yourself - it is implemented in the base class.
There was a problem hiding this comment.
Great, I will remove it! 👍
There was a problem hiding this comment.
If there is a problem connection does an error get generated here? If so, we should catch it.
Also, normally we set up the device in the setup_platform call and then pass it into the MediaPlayerDevice class.
There was a problem hiding this comment.
It's currently not handled, it's part of the "rough version". I will add some error handling as soon as possible. And also fix the setup as you describe.
|
@postlund Pressing Pause in Home Assistant pauses my aTV 4 for a split second then it plays again... |
There was a problem hiding this comment.
This is implemented inside the main class, you don't have to do to copy paste it. Please remove it.
Instead, implement the property media_image_url and all will work magically 🌟
There was a problem hiding this comment.
Ah, I see. I think I misunderstood have that worked but now I get it. I will fix that as well 👍
There was a problem hiding this comment.
Just thought one more time about this. I do not expose the image URL from pyatv, just a method that fetches the binary image (as part of my abstraction). I guess this doesn't work with that solution?
There was a problem hiding this comment.
It doesn't. Would it be possible to expose the url ?
There was a problem hiding this comment.
@balloob It's possible but would be ugly, because Apple TV requires a somewhat rapidly changing session ID on every request, so now the pyATV library will need to expose that ID to HA for consumption on just this one call...
There was a problem hiding this comment.
As @robbiet480 says, it would technically be possible but more of a hack. Maybe we could extend the cache somehow so that it would be possible to manually add images to it? I would prefer to remove that part of the code from this integration.
There was a problem hiding this comment.
Let's remove all art work from this PR and open a new PR that:
- The web view will implement the following logic:
if hasattr(player, 'async_get_media_image'):
image = yield from player.async_media_image()
if image is None and hasattr(player, 'get_media_image'):
image = yield from self.app['hass''].loop.run_in_executor(None, player.media_image)
if image is None and player.media_image_url:
image = … # fetch image using player.media_image_urlThere was a problem hiding this comment.
After that, implementing the coroutine async_get_media_image, or if your lib is not async, implement get_media_image
There was a problem hiding this comment.
Yes, I like this approach. I will make a new PR for that later tonight or tomorrow 👍
There was a problem hiding this comment.
An issue here, from what I have understood, is that the frontend uses media_entity_image to figure out if there is an image at all. Since that method returns None now, no image is shown. If I just return anything in that method, I can of course intercept the request in view and that works. Any input on how to handle this in a good way?
|
@maddox, I think the API is actually from the older devices. Nowadays there's some "kit" for doing this that probably only works on gen 4 (and later, when that happens). But the old protocol sort-of still works with newer devices as well :) @robbiet480 is testing the library like crazy, so there might be some things to fix in order to be equally compatible with gen 4 devices. |
|
Made some updates based on comments and some other fixes. Artwork does currently not work until #5754 is done, but it is prepared for that. |
|
Since pairing is now functional and netdisco support is forthcoming it may be a good idea to use the configurator to allow interactive pairing through the HASS UI. |
|
I agree and it is on my TODO-list. But it might be better to make a new PR for that once I have released the next version of pyatv. My goal is to finish the "play_url" support so that TTS can be used out-of-the-box (it's not that far away now). So if we could get this on dev that would be great! |
|
I just realized that I need to write some doc for this before merge. Will do that later tonight. |
|
I would love to test out TTS support. I have it working now as a "custom_components". Thanks to @robbiet480 help on the gitter.im |
|
I would love some feedback on that. Just pushed necessary updates to this PR, so it should work with Home Assistant. But it's not in pyatv yet. So you will have to clone that repo, switch to branch play_media and install it (or use python setup.py develop). Also, you need to update the version for this component to 0.0.2dev1 as well. Feel free to try it out :) https://github.com/postlund/pyatv/tree/play_media |
|
Awesome work! 🐬 |
|
@postlund I will test this out tonight hopefully (play_media) that is.. not sure I followed the update steps for payatv, will try to setup with develop option. Also, please update the original post, where the example configuration.yaml still says: "hsgid", it looks like now it's "login_id". Another issues I just noticed. I have two Apple TV Gen 4, similar to @robbiet480. But my atvremote scan shows the two separate Apple TVs, with their correct static IPs, but the HSGID is the exact same. ... which my guess is not correct? |
|
@rosahas, great! I'm going try to release the next version of pyatv ASAP so that I hopefully can get that included in the next release of Home Assistant. But if you have any problems, just let me know. I have updated the instructions, they were indeed incorrect. Since I don't have more than one Apple TV myself, I'm not sure how HSGID works. But I wouldn't be surprised if they are they same, it is probably associated with your account. Since you are talking with devices on two different IP-address, this shouldn't be a problem. Have you had any issues with this? |
|
@postlund just tried to get the dev environment setup. Created an issue on your github: If I can get at least the virtual_env built with the dev code and the new play_media branch, which I assume this will help me create locally, then I can at least test playing media using atvremote from "bin/activate"? Not sure how I would bind that to Home Assistant's configuration.yaml. I haven't tried setting up the second apple tv, was not sure about the same hsgid, will try it out tonight. |
|
@postlund yes, I was able to play the sample video on my Apple TV! I can "turn_on" the media, but i can't "turn_off". I don't think that's implemented, perhaps the Standby is implemented, but not sure what the command is for that? If everything is off, just turning on the Apple TV gets the rest of my components to start. But, it's failing on "turn_off" command at the moment. I will also have to increase the delay to accommodate for my receiver and TV to turn on properly. I was able to test playing the Goggle_TTS built MP3 just with atvremote command, but not via the Home Assistant script yet. |
|
I can also confirm that the HSGID is the same, must be by my userid or something.. I was able to add my other Apple TV using the same HSGID and the other IP address, no problem. |
|
@postlund Is there anyway to stop both my Apple TVs from turning on, when Home Assistant restarts? |
|
And as ju you noticed, it is not possible to turn off the device as that is not implemented. I don't think it's possible to implement I'm afraid. |
|
@postlund It's probably possible for Gen4 since you can long press the TV button to sleep but yeah not possible for anything other than that. |
|
@robbiet480 but I guess it would be hard to know when to trigger sleep in that case. |
|
@robbiet480 interesting.. I didn't know that. Anyway to try it out? I would love to have a way to put Apple TV on standby. Perhaps through a shell script that long presses the TV button? |
|
@rosahas Just press and hold the TV button and it will ask if you want to sleep. It will then turn itself and all connected CEC devices. |
|
@robbiet480 I turned on CEC so that when the Apple TV turns off after the 15 min timer, it turns off my TV and other CEC devices (like my Onkyo receiver). It seems that somehow this is causing my Apple TV to come on when I restart HA now! Will investigate further. |
|
@rosahas This is a known issue |
|
@robbiet480 thanks .. yes, I am on that thread too.. and I finally have the same random issue as well! |
|
@robbiet480 any way to do this "standby" programmatically by duplicating the long press for TV button? |
|
@robbiet480 Would it be possible to get top_menu functionality implemented (accessible through HASS) since its already available in pyatv? |
|
@SShah2601 Yes, that would be possible and it's on my TODO-list. My goal is to add a service that can simulate all kinds of key presses. Once I can get pyatv 0.3.0 out the door, even arrow keys can be supported. But I'm currently blocked by a dependency issue. I'll see if I can get some time tonight to at least support the keys that are supported by the user pyatv version. |
Description:
I've been working on a python library for the Apple TV for a while now and finally released the first version. So here is the first rough version of an Apple TV platform. Currently, it has only been tested with an Apple TV 3 as that is all I have. If someone owns a gen 4 device and has some time over, I would appreciate some help :) Feel free to use this issue: postlund/pyatv#3
Once I get some more time, I will add support to netdisco and fix automatic discovery. For now you have to configure it manually. As I said, it's in early development and there are some issues. So hit me with some bug reports!
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#1996
Example entry for
configuration.yaml(if applicable):Just specify IP and a name for the device. You also need an identifier called HSGID, you can find it with the
atvremotewhich you can read about here: https://github.com/postlund/pyatv/blob/master/docs/atvremote.rstChecklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.