Closed postlund closed 3 years ago
Or maybe, instead of creating a new repo, we could re-user chamberlain2007/apple_tv_mrp for that?
A pre-release, 0.4.0a1, is now available on pypi!
To get started with a config flow, run in Home Assistant dev env: python3 -m script.scaffold config_flow
👍
@balloob Cool, didn't know about that! I started with out-of-tree development at first (as custom component), but I think I will move in-tree instead and start from the beginning with the integration template instead. Thanks for the pointer!
I pushed a very, very rough start of the integration re-write here:
https://github.com/postlund/home-assistant/tree/atv_rewrite
I will do in-tree development only to not have to deal with limitations of custom components.
No authentication is built into the flow yet, but should work with MRP as-is (assuming zeroconf works as expected). Also, no re-connect logic, tests and other minor stuff are there. Seems like the remote component doesn't support config entries either, so it doesn't group well integration-wise either.
@postlund any beta build on the whole authenticationthing yet?
@postlund any beta build on the whole authenticationthing yet?
Not yet, working hard on that. I'm mostly done with #240 ("create a generic pairing API fo all protocols"), which is really what I need for that. It makes it easier to implement pairing in one way, dealing with any of the protocols. Can't promise anything time-wise, but I hope to be able to continue working here in the upcoming week or the week after that (depending on personal situation).
I have made a new pre-release, 0.4.0a3, that I will use as base to update the integration. Will likely start adjusting the code next week, but it is ok to start testing this release and report bugs. The documentation is partly updated with instructions for atvremote
:
After some fiddling, I think I have some messy code that works somewhat OK. Will have to clean it up a bit before publishing, but should be ready by tomorrow around this time or so. Found a couple of regressions that I had to fix (#265), so I will make a new release with these changes soon.
If you want to help me out and beta test, check back tomorrow.
Will TTS commands and Airplay etc, work with this beta version?
On 19 Nov 2019, at 23:13, Pierre Ståhl notifications@github.com wrote:
After some fiddling, I think I have some messy code that works somewhat OK. Will have to clean it up a bit before publishing, but should be ready by tomorrow around this time or so. Found a couple of regressions that I had to fix (#265 https://github.com/postlund/pyatv/pull/265), so I will make a new release with these changes soon.
If you want to help me out and beta test, check back tomorrow.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/postlund/pyatv/issues/209?email_source=notifications&email_token=AJJIEJQZY32YMKRFDFHRYK3QURQHFA5CNFSM4I6ND3Y2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEP62HY#issuecomment-555740447, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJJIEJQMCV7G6KN4HCJVFIDQURQHFANCNFSM4I6ND3YQ.
Will TTS commands and Airplay etc, work with this beta version?
I haven't had any intentions on looking into this, but I could probably make a quick work-around for it. It's more of an issue in aiohttp
that I can't do much about in a clean way at the moment, but a quickfix should work. I'll write an issue for it.
Issue: #266
So, I have now pushed an early version of the new components that should support all the different Apple TVs. I did not include the AirPlay "fix" mentioned above, just didn't have time for it. Will fix that later.
To get going it's more or less (you can remove the test_ha
directory when you are done testing):
mkdir test_ha
cd test_ha
git clone https://github.com/postlund/home-assistant.git
cd home-assistant
git checkout origin/new_atv
python3 -m venv venv
source venv/bin/activate
python setup.py develop
mkdir config
hass -c config
Wait for Home Assistant to start then shut it down (Ctrl+C), open config/configuration.yaml
and add:
logger:
default: info
logs:
pyatv: debug
Then just start it again:
hass -c config
Once Home Assistant is running, head over to Integrations and you should see your devices there. You can also add a device using an identifier (that you get with atvremote scan
for instance).
Would love to get some initial feedback on this! Remember, it's still early so some things doesn't work (like cover art) and you cannot configure via yaml (only config flows) for now. Remember to include debug logs if something breaks!
Hi, I will install and start testing tonight. Just a bit confused on the install instructions. Do you perhaps have a bit more detail?
Thank you for all your effort with this.
Hi, I will install and start testing tonight. Just a bit confused on the install instructions. Do you perhaps have a bit more detail?
Thank you for all your effort with this.
I updated the instructions in my previous post to include everything you need to do, hope it helps!
Thank you - I will be testing on my live HA instance which is installed in a venv. I will post feedback once it is up. Again, much appreciated!
I have started to follow the steps , but I get this error in the "git co" command
`git co origin/new_atv git: 'co' is not a git command. See 'git --help'.
The most similar commands are commit clone log` Am I missing something? Sorry for the stupid questions ;-)
UPDATE: Figured it out:
git config --global alias.co checkout
Thank you - I will be testing on my live HA instance which is installed in a venv. I will post feedback once it is up. Again, much appreciated!
I would highly recommend that you you use a separate venv (which you get with the commands above) and configuration and use it for testing this only.
I have started to follow the steps , but I get this error in the "git co" command
`git co origin/new_atv git: 'co' is not a git command. See 'git --help'.
The most similar commands are commit clone log` Am I missing something? Sorry for the stupid questions ;-)
UPDATE: Figured it out:
git config --global alias.co checkout
Yes, it's an alias 😄 I changed that in the comment.
Why write this?
core-ssh:~/home-assistant# python3 -m venv venv -bash: python3: command not found
Thank you for your work
I would highly recommend that you you use a separate venv (which you get with the commands above) and configuration and use it for testing this only.
If my deduction is correct I will have to install HA in that venv too?
Why write this?
core-ssh:~/home-assistant# python3 -m venv venv -bash: python3: command not found
Thank you for your work
I guess that you don't have a default version 3 for python. Try typing python and press TAB a few times, use the version you see (e.g. python3.6 or python3.7).
I would highly recommend that you you use a separate venv (which you get with the commands above) and configuration and use it for testing this only.
If my deduction is correct I will have to install HA in that venv too?
In my instructions you clone and install Home Assistant, so that is exactly what you are doing. You just use the version I am working on.
I have followed the steps above, but get these errors on initial startup of HA.
Just some additional info: I'm running python3.8
ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/data/dev/pyatv_test/home-assistant/venv/lib/python3.8/site-packages/aiohttp-3.6.1-py3.8-linux-armv7l.egg/aiohttp/web_protocol.py", line 275, in data_received messages, upgraded, tail = self._request_parser.feed_data(data) File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
I have checked if aiohttp is installed in the venv and it says "Requirement already satisfied"
Any suggestions?
UPDATE: Seems to to SSL related - It might be some webhooks from auxilary services trying to connect to this test HA instance.
I would also love to test it, but since i have hassio installed, i am not sure how to apply the instructions. Someone who could provide the procedure?
21 nov. 2019 kl. 13:33 skrev Horváth Károly notifications@github.com:
Why write this?
core-ssh:~/home-assistant# python3 -m venv venv -bash: python3: command not found
Thank you for your work
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
I have followed the steps above, but get these errors on initial startup of HA.
Just some additional info: I'm running python3.8
ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/data/dev/pyatv_test/home-assistant/venv/lib/python3.8/site-packages/aiohttp-3.6.1-py3.8-linux-armv7l.egg/aiohttp/web_protocol.py", line 275, in data_received messages, upgraded, tail = self._request_parser.feed_data(data) File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
I have checked if aiohttp is installed in the venv and it says "Requirement already satisfied"
Any suggestions?
UPDATE: Seems to to SSL related - It might be some webhooks from auxilary services trying to connect to this test HA instance.
Yeah, this seems unrelated and unless HA fails to start you should be able to ignore it.
I would also love to test it, but since i have hassio installed, i am not sure how to apply the instructions. Someone who could provide the procedure?
Do you run Hass.io on HassOS or do you run it on a generic Linux install? The first case is hard to do, you would probably have to create an add on to run it in. Would recommend using another machine with plain Linux instead.
If you already run on a plain Linux machine, you can just ssh and follow the instructions. You will have to use another port number though.
@postlund HassOS unfortunately... oh i see, do you have any plans on making it an addon later on?
-
Also, can you please delete my email signature that accidentally got embedded in your quote? :) Don’t want my contact details laying around. Thanks =)
I have followed the steps above, but get these errors on initial startup of HA. Just some additional info: I'm running python3.8
ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/data/dev/pyatv_test/home-assistant/venv/lib/python3.8/site-packages/aiohttp-3.6.1-py3.8-linux-armv7l.egg/aiohttp/web_protocol.py", line 275, in data_received messages, upgraded, tail = self._request_parser.feed_data(data) File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
I have checked if aiohttp is installed in the venv and it says "Requirement already satisfied" Any suggestions? UPDATE: Seems to to SSL related - It might be some webhooks from auxilary services trying to connect to this test HA instance.Yeah, this seems unrelated and unless HA fails to start you should be able to ignore it.
I got the system up - It shows the ATVs on my network, but will only be able to add them tonight, as I did the installation remotely. Anything specific you would like me to test?
@postlund HassOS unfortunately... oh i see, do you have any plans on making it an addon later on?
Also, can you please delete my email signature that accidentally got embedded in your quote? :) Don’t want my contact details laying around. Thanks =)
My intention is to replace the default component once it works as intended, so an addon won't be necessary. I would have implemented it as a custom component (during development phase) if I could, but there are some restrictions that doesn't allow me to do that.
Done!
I got the system up - It shows the ATVs on my network, but will only be able to add them tonight, as I did the installation remotely. Anything specific you would like me to test?
Great! Mainly verify that pairing and at least the some basic info works. It should show things like state, title, etc. It's just "general use" that I am interested in at this point 😄
Nice! Then i’ll just wait.
It’s possible through siri shortcuts to open specific apps on tvos.
do you think this will (in the future) be possible to do with your component?
21 nov. 2019 kl. 14:44 skrev Pierre Ståhl notifications@github.com:
@postlund HassOS unfortunately... oh i see, do you have any plans on making it an addon later on?
Also, can you please delete my email signature that accidentally got embedded in your quote? :) Don’t want my contact details laying around. Thanks =)
My intention is to replace the default component once it works as intended, so an addon won't be necessary. I would have implemented it as a custom component (during development phase) if I could, but there are some restrictions that doesn't allow me to do that.
Done!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Nice! Then i’ll just wait. It’s possible through siri shortcuts to open specific apps on tvos. do you think this will (in the future) be possible to do with your component? …
https://github.com/postlund/pyatv/issues/170#issuecomment-554372995
Okay - It worked beautifully. I added one ATV (Living Area) (On the newest tvOS) during the onboarding process of HA, and it asked for the PIN twice (Two different services, airplay and media player). After the two prompts I received the successful on HA(Onboarding.jpg), but the ATV was still displaying a new (3rd) PIN on the screen - It was dismissed by pressing menu on the remote.
The second ATV (Master Bedroom) I added via the integrations. On the integrations page it displayed three ATVs in the list (_ATVMB.jpg). I tried the first one, but I received an error - This was most likely due to taking too long to enter the PIN. Retrying it, did not generate a new PIN on the ATV. I then tried the other entry (without Homesharing enabled) and it went through the same process as the first also ending with a PIN on the screen.
After adding the Master Bedroom ATV there was still two listed under integrations (_ATV_MBAfterAdd.jpg).
On the Overview screen both ATV was added and two remotes (ATV Remotes.jpg). Both reported playing states from both Plex and Netflix and the controls to play/pause worked and the simulated off. Both also displayed the basic info about what is playing(ATV_LA_PlayingInfo).
Please let me know should you require any other testing.
This is great input, thanks! Comments are inlined below.
Okay - It worked beautifully. I added one ATV (Living Area) (On the newest tvOS) during the onboarding process of HA, and it asked for the PIN twice (Two different services, airplay and media player). After the two prompts I received the successful on HA(Onboarding.jpg), but the ATV was still displaying a new (3rd) PIN on the screen - It was dismissed by pressing menu on the remote.
I looked into this and found the root cause. The third PIN screen is actually still the first one. You begin by pairing with MRP, which succeeds. The PIN screen is still displayed but as soon as pairing of AirPlay starts, that is just rendered on top of the first one. When AirPlay pairing is done, its screen disappears and you are back at the first screen again. This happens because I don't close the connection used for pairing properly (which is handled OK for AirPlay it seems).
When using atvremote
you don't actually notice this since the applications exits once pairing is done, so the connection is closed. With Home Assistant the connection persists. I managed to sneak in a fix together with #274...
The second ATV (Master Bedroom) I added via the integrations. On the integrations page it displayed three ATVs in the list (_ATVMB.jpg). I tried the first one, but I received an error - This was most likely due to taking too long to enter the PIN. Retrying it, did not generate a new PIN on the ATV. I then tried the other entry (without Homesharing enabled) and it went through the same process as the first also ending with a PIN on the screen.
It is interesting that you get three different entries here. What does atvremote scan
say? Also, could you perhaps include some debug logs? It's easier to see what's going on.
I assume that this is an Apple TV 3? Using the service suffixed with "(Home sharing)" should only ask for PIN when pairing AirPlay. The other one should ask once for DMAP (or rather, you need to enter a PIN on the device) and a second one for AirPlay.
After adding the Master Bedroom ATV there was still two listed under integrations (_ATV_MBAfterAdd.jpg).
I believe this is a side-effect of the device being found several times (one for home sharing, once for when home sharing is not available and once for a reason I don't understand). Not sure if it's possible to signal to other config flows that they should disappear, but you should at least just get a message telling you that the device is already configured. Did you get that?
On the Overview screen both ATV was added and two remotes (ATV Remotes.jpg). Both reported playing states from both Plex and Netflix and the controls to play/pause worked and the simulated off. Both also displayed the basic info about what is playing(ATV_LA_PlayingInfo).
Sounds good! 👍
Please let me know should you require any other testing.
Absolutely! Would be good if you tried leaving it running for a while to see how it behaves over time. Exceptions and strange behavior is worth additional investigation.
I also tried this today. Right on the first start I see an Apple TV listed in the setup screen:
I added it from that screen, but also had the issue that the Apple TV PIN was still shown on screen when HA performs the Airplay pairing.
Using the "Apple TV Remove" switch to turn the Apple TV on/off didn't work (and I would find that very useful!). Using the media player on/off switch didn't work either. Play/pause/forward/rewind works fine. I see the video title in the HA media player.
My logs are here: home-assistant.log
Thanks a lot for working on this!
Can't install any tricks on Hass.io?
I also tried this today. Right on the first start I see an Apple TV listed in the setup screen:
I added it from that screen, but also had the issue that the Apple TV PIN was still shown on screen when HA performs the Airplay pairing.
Using the "Apple TV Remove" switch to turn the Apple TV on/off didn't work (and I would find that very useful!). Using the media player on/off switch didn't work either. Play/pause/forward/rewind works fine. I see the video title in the HA media player.
My logs are here: home-assistant.log
Thanks a lot for working on this!
Great, thanks you for testing! 😊 Turn on/off doesn't really work since I haven't implemented the disconnect routines in a decent way yet. Will probably focus on that soon. Turn on will work like it always has: if the device is off, it will turn on. Turn off will probably not work. For older devices (DMAP) there's no known way, so that's a no-go for now. I hope someone proves me wrong soon. Newer devices supports "suspend" (you can use it like so: atvremote ... suspend
). This will "turn off" the device but it doesn't coop with CEC, so if you rely on that it still won't work. In theory it's possible to navigate through menus to put the device to sleep, but I refrain from doing that as it's not reliable.
An interesting use case is to reboot the Apple TV a couple of times. It will probably change port at some point and stop working. Issue #273 deal with this and I hope to implement that soon as well.
Can't install any tricks on Hass.io?
I've modified the component bundled with Home Assistant, so you need this specific version of Home Assistant. I don't think it's supported by the Hass.io supervisor to install a user-provided version. So no, I at least think it's not possible in a simple way.
Turn on will work like it always has: if the device is off, it will turn on. Turn off will probably not work.
OK, I played with that. I manually put it to sleep (Settings -> Sleep now).
remote.turn_on
doesn't do anything.media_player.turn_on
shows the player as on in HA, but actually the device is off.media_player.media_play
turns it on.Having a way to turn it on (wake up from sleep) without playing some media would be nice! Until then, I can just disable sleep mode so it's always on.
OK, I played with that. I manually put it to sleep (Settings -> Sleep now).
- Starting HA will turn it on.
remote.turn_on
doesn't do anything.media_player.turn_on
shows the player as on in HA, but actually the device is off.media_player.media_play
turns it on.- Putting it back to sleep manually will not be detected by HA.
Having a way to turn it on (wake up from sleep) without playing some media would be nice! Until then, I can just disable sleep mode so it's always on.
I'm gonna try to explain how it works 😄 Warning, long post...
The Apple TV wakes up from sleep whenever something connects to it, be it MRP, AirPlay or something else. I don't believe it will go to sleep if it has a persistent connection to someone/something. In case of pyatv
we have two separate cases:
The way current Apple TV component in Home Assistant works, is that when you turn a device on or off, it basically disables push updates (via interface.PushUpdater.stop
). Again, we have two cases:
pyatv
has no connection to the device open whatsoever.The take from this is that when you "stop" a device that happens to be for instance an Apple TV 3, you will cease all communication with it (since it's a DMAP device) and not continue to wake it up. If you have start_off
set, you will not wake it up when restarting Home Assistant for the same reason.
Again, the same reasoning for lets say an Apple TV 4, will still keep it from going to sleep and/or wake it up since the connection is still active (because of MRP). Using start_off
will not work here either because that only deals with the "push updates" API and the connection is made before that API is available.
So... what needs to be done here is to not use the push updates API from turn on/off, but instead hook into connect
/close
and actually close the connection completely. The next time you turn on the device, pyatv
must perform a scan and try to find the device again (which it does under the hood) and then connect. This is also more or less the same case as when the device changes port, e.g. after a restart or so.
So to answer your question: yes, you will be able to wake up your device by just hitting turn on (and not having to send a particular command). It happens automatically when pyatv
establishes a connection.
I have decided to convert this into a custom component, with the limitation that auto-discovery will not work (since zeroconf is not supported for custom components). Hopefully I will finish this tonight. Progress will be posted in #278.
For people feeling brave, the beta component is here:
I've just installed it, and it works wonders with my ATV 4th gen using HA 0.102.2. At least I can read the playing state and media info again so I can dim my lights. Playing/pausing also seems to work. I also had no problems with the pin entering, both pins were correctly registered and they disappeared from the ATV after entering as they should. Thanks so much for all the effort you're putting into this! 😄 🏆
I also gave the beta component a shot, so far works brilliantly! I'm looking forward for this becoming a fixed part in HA.
@Qonstrukt @Kugelfang666 Thanks for giving it a spin and reporting back! 👍 Great to hear that it seems to work OK as well 😄
My upcoming focus will be on fixing a few bugs, #291 being one of them, but also implement re-connect if a device is not found (e.g. scan fails or Apple TV is turned off when starting Home Assistant) or if a connection error happens. I will merge #290 as well and would need some help to verify if AirPlay works as well.
Beta component is working flawlessly for me so far on my Apple TV 4th Gen. Really smooth setup and pairing experience, and I didn't even have to touch a YAML file. It feels so slick and polished even in this beta state. I'm impressed, great stuff!
The one minor issue I've found so far is that my device shows up "twice" on the integrations page (and the new "Devices" page). A blank/empty one and then the actual Apple TV.
I believe that it's the same exact issue as this: https://github.com/home-assistant/home-assistant/pull/29173 So perhaps you can see how balloob fixed it there and apply the same fix here.
I setup the beta component but I'm out of the country so can't actually pair it with any of my devices, I'll do some testing and provide feedback next week.
The one minor issue I've found so far is that my device shows up "twice" on the integrations page (and the new "Devices" page). A blank/empty one and then the actual Apple TV.
I believe that it's the same exact issue as this: home-assistant/home-assistant#29173 So perhaps you can see how balloob fixed it there and apply the same fix here.
Right, I think I messed up the device registry part here. I'm not enitrely sure how it's supposed to work, but I assume that the part added here https://github.com/postlund/hass-atv-beta/blob/master/custom_components/apple_tv/__init__.py#L57 should be removed. It seems to work via device_info
in media_player.py
and remote.py
anyway. Thanks for pointing out, I will add it to my TODO-list.
Really excited to try the beta but could not get it running, neither by putting it into custom_components
nor by overriding homeassistant/components/apple_tv
folder via Docker volumes.
It seems like it actually does replace the built-in applt_tv components as its services are no longer visible on Developer Tools -> Services screen, but no trace of Apple TV integration is to be found on Settings -> Integrations -> Add page 🤔
I'd appreciate any hints.
Really excited to try the beta but could not get it running, neither by putting it into
custom_components
nor by overridinghomeassistant/components/apple_tv
folder via Docker volumes.It seems like it actually does replace the built-in applt_tv components as its services are no longer visible on Developer Tools -> Services screen, but no trace of Apple TV integration is to be found on Settings -> Integrations -> Add page 🤔
I'd appreciate any hints.
This issue was reported earlier I think, but it seemed to work when installed via HACS. Could you try that? Otherwise try cleaning your cache and see if it appears.
Short feature/function description I will let this issue act as a scratch space when working on the Home Assistant integration of pyatv 0.4.0. Current integration (in HA) is not compatible with 0.4.0 at all, so some work needs to be done to adapt. We should also try do modernize the integration as well since it doesn't use modern features (lite config entries or flows). What is on
master
in writing moment should be enough to get going.I have not started working on this yet.
What needs to be done? Short list of tasks to do (based on modifying existing integration):
pyatv.get_device_id
)I think I have covered the necessary parts above, albeit they might need to be broken down a bit more. However it's a good start. One idea now is to setup a new repo for the component that can be installed via HACS (but require it to be manually added as a source repo), just to simplify testing for users. I will have to do a pre-release of pyatv as well I guess, need to figure out how that works.
Note: Finishing the above only means that the HA integration is done, there are still lots of work left in pyatv.
Is this a breaking change? Hopefully nothing for pyatv
Anything else worth knowing? Maybe @chamberlain2007 is interested in this issue.