With help from Claude, I think I was able to insert the necessary code and it appears to be working. It seems to have been fairly straightforward. Before starting, I made a backup copy of the /tmp/appletv-binding folder as suggested by Bill.
Below are the instructions as provided by Claude
Firstly, the code needs to be inserted into the _init_.py fileā¦
sudo nano /var/lib/openhab/tmp/appletv-binding/lib/python3.11/site-packages/pyatv/protocols/companion/__init__.py
At the end of this file, the following code was added, which is a slightly modified version of what on GitHub.
async def patched_pyatv_companion_connect(self):
"""Patch connect method for pyatv Companion protocol."""
if self._protocol:
return
from pyatv.protocols.companion import connection as _conn_mod
from pyatv.protocols.companion import protocol as _proto_mod
from pyatv.auth import hap_srp as _hap_srp
self._connection = _conn_mod.CompanionConnection(
self.core.loop,
str(self.core.config.address),
self.core.service.port,
self.core.device_listener,
)
self._protocol = _proto_mod.CompanionProtocol(
self._connection, _hap_srp.SRPAuthHandler(), self.core.service
)
self._protocol.listener = self
await self._protocol.start()
await self.system_info()
await self._touch_start()
await self._session_start()
await self._send_command("TVRCSessionStart", {"ProtocolVersionKey": "1.2"})
await self._text_input_start()
await self.subscribe_event("_iMC")
# TODO patch for tvOS 26.5 : to be removed when fixed
from pyatv.protocols.companion import api as _companion_api
_companion_api.CompanionAPI.connect = patched_pyatv_companion_connect
The changes from the GitHub version is the use of relative imports⦠per Claudeā¦
The patch code looks correct. The issue is that lines 698-699 still reference pyatv.protocols.companion.protocol and pyatv.auth.hap_srp using the full pyatv. prefix, which arenāt available that way inside the package itself.
Letās fix the function to use relative imports instead.
Once OpenHAB was restarted, the Apple TV Thing started to appear online and the existing automation I had created working correctly.
Claude did also mention the below so clearly a more robust fix is needed.
Important caveat: This edit will be wiped every time OpenHAB restarts because that folder gets re-extracted from the binding JAR. If it works, weāll need to figure out a way to make it persistent ā but letās confirm it fixes the issue first.
Hope this helps!