pyatv: Can't Add Apple TV

Describe the bug I was previously successfully using this Beta but had to delete it to try and solve some other issues I was having, but now that I’ve reinstalled it I can’t get it to add my AppleTV.

After I’ve installed it and go to “Integrations” and then “AppleTV”, I get a message that it’s auto-discovered all of the AppleTV’s in my house, even though I have the following in my yaml:

discovery: ignore: - apple_tv

Then I’ll add in the IP address of the AppleTV I want to add, enter the code, and then it simply says “Aborted” and nothing happens. Furthermore, if I get a code starting in ‘0’ I can’t add it. It’s almost as if the Beta component just isn’t installing correctly, even though I tried both installing through HACS and manually. Debug logs are attached.

To Reproduce Try and add an AppleTV using the steps in the custom component. PYATV.log

Expected behavior Auto-discovery of my AppleTV’s shouldn’t occur, I should be able to enter codes starting in 0, and I should be able to successfully add my AppleTV.

System Setup (please complete the following information):

  • OS: Hass.IO 0.100.1
  • Python: not sure how to check this…
  • pyatv: 0.4.0a10

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

@Tangston311 Great, thanks for verifying! 😊 I will close the issue, feel free to write a new issue if you run into more problems!

No worries - appreciate the hard work!

Ok, so, this was one of those “it works for me”-kinda situations. It so happens that I already fixed this problem (at least for AirPlay):

https://github.com/postlund/pyatv/commit/d49837db28788dc98ae5facacfa84680cb7c4817

Since I have these changes locally I get the proper error message. I have not released pyatv with this change and updated the component yet though. So that is why you get the error above. I will hopefully make a new release tonight.

As I suspected:

020-01-28 06:23:59 ERROR (MainThread) [custom_components.apple_tv.config_flow] Auth exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 954, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 941, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 464, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 494, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.18', 7000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyatv/airplay/pairing.py", line 59, in begin
    return await self.auther.start_authentication()
  File "/usr/local/lib/python3.7/site-packages/pyatv/airplay/auth.py", line 32, in start_authentication
    'pair-pin-start', headers=_AIRPLAY_HEADERS)
  File "/usr/local/lib/python3.7/site-packages/pyatv/net.py", line 76, in post_data
    raise ex
  File "/usr/local/lib/python3.7/site-packages/pyatv/net.py", line 66, in post_data
    timeout=DEFAULT_TIMEOUT if timeout is None else timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 483, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 859, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.1.18:7000 ssl:None [Connect call failed ('192.168.1.18', 7000)]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/apple_tv/config_flow.py", line 225, in async_begin_pairing
    await self.pairing.begin()
  File "/usr/local/lib/python3.7/site-packages/pyatv/airplay/pairing.py", line 61, in begin
    raise exceptions.PairingError(str(ex)) from ex
pyatv.exceptions.PairingError: Cannot connect to host 192.168.1.18:7000 ssl:None [Connect call failed ('192.168.1.18', 7000)]

It is reasonable that this happen, I must handle this exception separately. This is all I need to fix this, thanks for all the help! 😄

Sure thing - I’ll add that in and post results tomorrow morning.