maxileith / homebridge-appletv-enhanced

Homebridge plugin that exposes Apple TVs with features that should be native to Apple HomeKit.
MIT License
199 stars 3 forks source link

Cannot initiate Pairing on Apple TV on new install #290

Closed jsiegenthaler closed 8 months ago

jsiegenthaler commented 9 months ago

Preconditions

Current Situation

A new installation of Apple TV Enhanced cannot initiate pairing on the Apple TV. I have rebooted many times but no matter what, can never get the pin code display to appear on the Apple TV

Logs

[27/02/2024, 18:40:44] [Apple TV Enhanced] [I] Platform: Finished initializing platform: Apple TV Enhanced
[27/02/2024, 18:40:44] [Apple TV Enhanced] [D] Platform: Executed didFinishLaunching callback
[27/02/2024, 18:40:44] [Apple TV Enhanced] [I] Python check: Starting python check.
[27/02/2024, 18:40:44] [Apple TV Enhanced] [I] Python check: plugin dir exists.
[27/02/2024, 18:40:44] [Apple TV Enhanced] [I] Python check: Python 3.9.2 is installed and supported by the plugin.
[27/02/2024, 18:40:44] [Apple TV Enhanced] [I] Python check: Virtual environment already exists.
[27/02/2024, 18:40:45] [Apple TV Enhanced] [I] Python check: Venv is using current system python version (3.9.2).
[27/02/2024, 18:40:46] [Apple TV Enhanced] [I] Python check: Venv pip version: 24.0
[27/02/2024, 18:40:46] [Apple TV Enhanced] [I] Python check: Checking if there is an update for venv pip ...
[27/02/2024, 18:40:47] [Apple TV Enhanced] [I] Python check: Venv pip is up-to-date
[27/02/2024, 18:40:48] [Apple TV Enhanced] [W] Python check: WARNING: The directory '/home/homebridge/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
[27/02/2024, 18:40:48] [Apple TV Enhanced] [I] Python check: Python requirements are satisfied.
[27/02/2024, 18:40:48] [Apple TV Enhanced] [I] Python check: Finished
[27/02/2024, 18:40:48] [Apple TV Enhanced] [D] Platform: Setting the storage path of the PyATV instance to /var/lib/homebridge
[27/02/2024, 18:40:48] [Apple TV Enhanced] [D] CustomPyATVInstance: Set atvscript path to "/var/lib/homebridge/appletv-enhanced/.venv/bin/atvscript".
[27/02/2024, 18:40:48] [Apple TV Enhanced] [D] CustomPyATVInstance: Set atvremote path to "/var/lib/homebridge/appletv-enhanced/.venv/bin/atvremote".
[27/02/2024, 18:40:48] [Apple TV Enhanced] [I] Platform: Starting device discovery ...
[27/02/2024, 18:40:48] [Apple TV Enhanced] [D] Platform: Starting device discovery ...
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Platform: finished multicast device discovery
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Platform: Found Apple TV Lounge (90:DD:5D:C5:8C:6B / 192.168.0.153).
[27/02/2024, 18:40:55] [Apple TV Enhanced] [I] Platform: Adding Apple TV Lounge (90:DD:5D:C5:8C:6B)
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Platform: Waiting for Apple TV Lounge (90:DD:5D:C5:8C:6B) to boot ...
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): Accessory Config: {"name":"Apple TV Enhanced","mediaTypes":["music","tv"],"deviceStateDelay":0,"remoteKeysAsSwitch":["pause","play"],"avadaKedavraAppAmount":15,"disableVolumeControlRemote":false,"setTopBox":false,"discover":{"multicast":true},"forceVenvRecreate":false,"logLevel":4,"deviceSpecificOverrides":[{"overrideMediaTypes":false,"overrideDeviceStates":false,"overrideDeviceStateDelay":false,"deviceStateDelay":0,"overrideRemoteKeysAsSwitch":false,"overrideAvadaKedavraAppAmount":false,"avadaKedavraAppAmount":15,"overrideCustomInputURIs":false,"overrideDisableVolumeControlRemote":false,"disableVolumeControlRemote":false,"overrideSetTopBox":false,"setTopBox":false}],"platform":"AppleTVEnhanced"}
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): Loaded credentials: undefined
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): Loaded credentials: undefined
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Platform: Finished device discovery.
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): Got empty credentials, initiating pairing process.
[27/02/2024, 18:40:55] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): Wait for the atvremote process to terminate
[27/02/2024, 18:40:55] [Apple TV Enhanced] [W] Lounge (90:DD:5D:C5:8C:6B): Credentials are no longer valid. Need to repair ...
[27/02/2024, 18:40:55] [Apple TV Enhanced] [W] Lounge (90:DD:5D:C5:8C:6B): You need to pair your Apple TV before the plugin can connect to it. Enter the PIN that is currently displayed on the device here: http://192.168.0.100:42153/
[27/02/2024, 18:40:57] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): stdout: 2024-02-27 18:40:57 ERROR [pyatv.scripts.atvremote]: Pairing failed
Traceback (most recent call last):
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/support/__init__.py", line 71, in error_handler
    return await func(*args, **kwargs)
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/protocols/companion/auth.py", line 63, in start_pairing
    pairing_data = _get_pairing_data(resp)
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/protocols/companion/auth.py", line 33, in _get_pairing_data
    raise exceptions.AuthenticationError(stringify(tlv))
pyatv.exceptions.AuthenticationError: Error=BackOff, BackOff=9383s, SeqNo=M2
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 196, in pair
    await self._perform_pairing(pairing)
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 206, in _perform_pairing
    await pairing.begin()
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/protocols/companion/pairing.py", line 47, in begin
    await error_handler(
  File "/var/lib/homebridge/appletv-enhanced/.venv/lib/python3.9/site-packages/pyatv/support/__init__.py", line 77, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: Error=BackOff, BackOff=9383s, SeqNo=M2

[27/02/2024, 18:40:57] [Apple TV Enhanced] [W] Lounge (90:DD:5D:C5:8C:6B): Apple TV Lounge: Too many attempts. Waiting for 9388 seconds before retrying.
[27/02/2024, 18:40:57] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): 9388 seconds remaining.
[27/02/2024, 18:40:58] [Apple TV Enhanced] [D] Lounge (90:DD:5D:C5:8C:6B): 9387 seconds remaining.

Configuration

{
    "name": "Apple TV Enhanced",
    "mediaTypes": [
        "music",
        "tv"
    ],
    "deviceStateDelay": 0,
    "remoteKeysAsSwitch": [
        "pause",
        "play"
    ],
    "avadaKedavraAppAmount": 15,
    "disableVolumeControlRemote": false,
    "setTopBox": false,
    "discover": {
        "multicast": true
    },
    "forceVenvRecreate": false,
    "logLevel": 3,
    "deviceSpecificOverrides": [
        {
            "overrideMediaTypes": false,
            "overrideDeviceStates": false,
            "overrideDeviceStateDelay": false,
            "deviceStateDelay": 0,
            "overrideRemoteKeysAsSwitch": false,
            "overrideAvadaKedavraAppAmount": false,
            "avadaKedavraAppAmount": 15,
            "overrideCustomInputURIs": false,
            "overrideDisableVolumeControlRemote": false,
            "disableVolumeControlRemote": false,
            "overrideSetTopBox": false,
            "setTopBox": false
        }
    ],
    "_bridge": {
        "username": "0E:17:50:E5:71:23",
        "port": 57763
    },
    "platform": "AppleTVEnhanced"
}

Operating System

Linux

Operating System: Bits

64-bit

Operating System: Distribution

NAME="Raspbian GNU/Linux"

Operating System: Distribution Version

VERSION="11 (bullseye)"

Docker

no

Docker Image

None

Docker Image Version

No response

Homebridge Version

1.7.0

Homebridge Config UI Version

4.55.1

Homebridge Storage Path

/var/lib/homebridge

Homebridge Apple TV Enhanced Version

1.2.4

Node Version

v20.11.1

NPM Version

10.2.4

Python Version

3.9.2

PIP Version

20.3.4

HDMI Hops

AV Receiver

Audio Output

no

Same Subnet

yes

Additional Context

I have tried many times but have never gotten the pairing display to appear on the Apple TV. The URL in the logs (Enter the PIN that is currently displayed on the device here: http://192.168.0.100:42153/) always results in ERR_CONNECTION_REFUSED

github-actions[bot] commented 9 months ago

✔️ Take a coffee ☕

Your opened issue fulfills all requirements validated in the pre-checks 🎉

My master will take a look at the problem as soon as he has the time for it 🤖

Time to get a coffee ☕

maxileith commented 9 months ago

Yeah, the log might be a bit misleading.

So it is as follows:

So the Webserver is only available when there is an active pairing request.

If you entered the back off loop and do not want to set a timer on when you need to come back to pair the Apple TV, I would suggest to shutdown the plugin. Wait until you are certain that the back off time has passed and then enable the plugin again. Be ready to enter the code fast.

I might have to refactor the pairing process ...

jsiegenthaler commented 9 months ago

OK, 9388 seconds = 156m = 2.6 hours. I guess I'll shut down the plugin until tomorrow.

jsiegenthaler commented 9 months ago

My issue is that my Apple TV is in a different room from my PC, so if I reboot homebridge from my PC, and then walk to the TV room, the 30s can easily elapse before I get there.

I think you should update the pairing instructions to some something like:

  1. Install the plugin.
  2. (optional) Enable the plugin to run as a child bridge. The benefit here is that the plugin is more isolated from other plugins, e.g. in case of a plugin crash, only the plugin will crash and not the whole homebridge. 3. Important: Make sure you are in front of your Apple TV and ready to read the pairing code which will be displayed for a maximum of around XX seconds.
  3. Restart the homebridge.
maxileith commented 9 months ago

@jsiegenthaler have you successfully paired your Apple TV? Or do you need further assistance?

jsiegenthaler commented 9 months ago

HI. I just paired it now. You really have to be infront of the TV with an iPad and ready to quickly change the portnumber of Homebridge to type in the pin code.... easy to miss that step within the allotted time.

Nolabob commented 9 months ago

I'm having the same issue. I will keep the plugin disabled for 5+ hours before I try again. I do have a few questions to get mine paired. . What do mean by changing the port number to the pin code. Which pin code? The pin from the Apple TV, or the pin listed in the log? Also, why an iPAD? Can't i just use a PC with the correct port?

Write commented 8 months ago

Same issue here. New fresh install, already tried two codes and got the same error both times.

EDIT : Finally succeeded, the pairing process is waaaaaay to fast. Very weird. I can confirm you really have to be in front of the TV to type the code as fast as possible.

maxileith commented 7 months ago

Hello everyone,

its been some time. However, I would like to let you know that I have opened an enhancement request regarding the stressful paring: #359. I cannot garantuee say when I will be implementing a solution to that problem, just wanted to let you know that I haven´t forgotten the issue.

I will take a look at it when I am motivated to do it. Currently, I am not coding that much in my free time.

However, PRs are welcome if you are motivated ;)