home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.12k stars 31.11k forks source link

Apple TV integration reporting "invalid authentication" #113374

Open nashnix opened 8 months ago

nashnix commented 8 months ago

The problem

Expected Behaviour:

Home Assistant will ask the Apple TV to provide a PIN, this is provided and entered, and Home Assistant connects to Apple TV

Actual Behaviour:

Home Assistant asks the Apple TV to provide a PIN; this is provided and entered, then Home Assistant integration fails, declaring "invalid authentication", even though the AppleTV connection PIN is correct.

Supplementary:

What version of Home Assistant Core has the issue?

core-2024.3.0

What was the last working version of Home Assistant Core?

N/A - has never worked

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Apple TV

Link to integration documentation on our website

https://www.home-assistant.io/integrations/apple_tv

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.apple_tv.config_flow
Source: components/apple_tv/config_flow.py:460
integration: apple_tv (documentation, issues)
First occurred: 13:49:36 (1 occurrences)
Last logged: 13:49:36

Authentication problem
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pyatv/support/__init__.py", line 71, in error_handler
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/auth.py", line 53, in start_pairing
    resp = await self.protocol.exchange_auth(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/protocol.py", line 142, in exchange_auth
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/protocol.py", line 175, 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 460, in async_pair_next_protocol
    await self.pairing.begin()
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/pairing.py", line 47, in begin
    await error_handler(
  File "/usr/local/lib/python3.12/site-packages/pyatv/support/__init__.py", line 77, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: Command failed: Pairing not allowed

Additional information

The following are definitely not the cause:

home-assistant[bot] commented 8 months ago

Hey there @postlund, mind taking a look at this issue as it has been labeled with an integration (apple_tv) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `apple_tv` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign apple_tv` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


apple_tv documentation apple_tv source (message by IssueLinks)

nashnix commented 8 months ago

I can report that the exact same behaviour noted above persists under the most current version of Home Assistant (i.e, under version 2024.3.1):

Home Assistant details:

Log:

Logger: homeassistant.components.apple_tv.config_flow
Source: components/apple_tv/config_flow.py:460
integration: apple_tv (documentation, issues)
First occurred: 18:38:55 (1 occurrences)
Last logged: 18:38:55

Authentication problem
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pyatv/support/__init__.py", line 71, in error_handler
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/auth.py", line 53, in start_pairing
    resp = await self.protocol.exchange_auth(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/protocol.py", line 142, in exchange_auth
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/protocol.py", line 175, 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 460, in async_pair_next_protocol
    await self.pairing.begin()
  File "/usr/local/lib/python3.12/site-packages/pyatv/protocols/companion/pairing.py", line 47, in begin
    await error_handler(
  File "/usr/local/lib/python3.12/site-packages/pyatv/support/__init__.py", line 77, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: Command failed: Pairing not allowed

As before:

galmeida commented 8 months ago

facing same issue with newer Apple TV 4 and Apple TV 4K (gen 3). AppleTV (gen 2) works fine

jonatansmedsgard commented 7 months ago

I am having the same issue as well.

I have also tested with pyatv stand alone from pip and it gives the same exception.

jonatansmedsgard commented 7 months ago

I was able to make the authentication work and the Home Assistant Apple TV integration setup to succeed. The issue for me was that the settings "Air Play Settings" and "Remote App Pairing" under Restrictions in Settings App was set to "Restrict". Once those were changed to "Allow" the pairing process worked.

Apple TV Restrictions Settings

nashnix commented 7 months ago

Thanks @jonatansmedsgard, but as I noted in both my reports above; AirPlay is on, access is set to "everyone", and there are no PIN codes or like barriers (that includes the remote stuff too).

Whatever issue this is, that doesn't fix it.

The issue appears to be on the HomeAssistant side; as far as the AppleTV is concerned, everything is set up and working just fine.

EjobHA commented 6 months ago

Just installed HomeAssistant and has the same issue with Apple TV integration ..

nashnix commented 6 months ago

It appears that a complete factory reset of your AppleTV will result in Home Assistant being able to see and integrate the AppleTV. See https://support.apple.com/en-us/108897 for directions as to how.

Note that this will wipe everything from your AppleTV, including any streaming services and downloads you have.

I would not call that real solution though; it is, at best, a stopgap workaround. Most people will be loathe to wipe their AppleTV just to enable this integration - especially as you will need to re-download everything you had on it manually, which means having to log back into every one of the fifty streaming services everyone has to have now, all at once. As such, I have left the issue open, as it is still in need of a reasonable solution.

cinghialino commented 5 months ago

I was able to make the authentication work and the Home Assistant Apple TV integration setup to succeed. The issue for me was that the settings "Air Play Settings" and "Remote App Pairing" under Restrictions in Settings App was set to "Restrict". Once those were changed to "Allow" the pairing process worked.

Apple TV Restrictions Settings

This worked for me. A difference I have from the others is that I am running the current beta version of the new tvOS, 18.0

galmeida commented 4 months ago

I was able to make the authentication work and the Home Assistant Apple TV integration setup to succeed. The issue for me was that the settings "Air Play Settings" and "Remote App Pairing" under Restrictions in Settings App was set to "Restrict". Once those were changed to "Allow" the pairing process worked.

This worked for me as well, thanks @jonatansmedsgard

astubbs commented 2 months ago

I was able to make the authentication work and the Home Assistant Apple TV integration setup to succeed. The issue for me was that the settings "Air Play Settings" and "Remote App Pairing" under Restrictions in Settings App was set to "Restrict". Once those were changed to "Allow" the pairing process worked.

Thank you! I've been banging my head against this for a while! :)

https://github.com/postlund/pyatv/issues/2495 https://github.com/maxileith/homebridge-appletv-enhanced/issues/459