postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
839 stars 91 forks source link

Can't connect to Apple TV, is the app broken? #2208

Closed gravelfreeman closed 9 months ago

gravelfreeman commented 9 months ago

Describe the bug

When connecting ATV in HAOS integration with the code shown on ATV, I'm getting this error on HAOS; Authentication failed.

Error log

2023-09-22 16:18:30.647 ERROR (MainThread) [homeassistant.components.apple_tv.config_flow] Authentication problem
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/__init__.py", line 70, in error_handler
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/auth.py", line 53, in start_pairing
    resp = await self.protocol.exchange_auth(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 145, in exchange_auth
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 178, in _exchange_generic_opack
    raise exceptions.ProtocolError(f"Command failed: {unpacked_object['_em']}")
pyatv.exceptions.ProtocolError: Command failed: Pairing not allowed

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 422, in async_pair_next_protocol
    await self.pairing.begin()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/pairing.py", line 54, in begin
    await error_handler(
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/__init__.py", line 78, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: Command failed: Pairing not allowed

How to reproduce the bug?

  1. Discover ATV on HAOS
  2. Enter pin shown on Apple TV

What is expected behavior?

Successful pairing with ATV and HAOS.

Operating System

HAOS

Python

Other

pyatv

Unknown

Device

Latest ATV4K

Additional context

postlund commented 9 months ago

This is really weird, I haven't been able to reproduce it myself unfortunately. Can you check if "Everyone on the same network" is set in the Home app as well? I noticed my ATV reported pairing requirement as disabled when it was set to everyone in the same home.

gravelfreeman commented 9 months ago

I forgot to update this issue but I was able to resolve the issue deactivating the parental controls. I must say the Apple TV gui is terrible at showing logs, error codes, etc. It shouldn't permit the user that has parent controls setup to show a pair code on the screen.