hww3
(Bill Welliver)
August 20, 2025, 10:32pm
285
Hi All-
Sorry for not replying sooner, I’ve been away for a few weeks. I thought I’d included a reference to the problem, but I guess I never posted it. Here’s the bug report that I believe is the root of the problem some folks are seeing:
opened 04:29PM - 18 Mar 25 UTC
bug
### Describe the bug
I have 2 AppleTV boxes : one on tvOS 18.3 and another with… 18.4 beta.
The one with 18.4 beta raises a connection lost exception right after the connection (the other one works fine).
I paired the device with 2 protocols : companion and airplay. The disconnection is raised when using the companion protocol, (airplay is fine).
Edit : tested with python 3.12 and 3.13, on windows and a Ubuntu docker instance.
See the sample code below to reproduce it with the following steps
1. Pair the Apple TV device with companion protocol using tvOS 18.4
2. Connect to it with pyatv
3. Subscribe to connection lost/closed events by implementing the `DeviceListener` interface
4. The client will receive a lost connection event a few milliseconds later
```python
class AppleTvClient(DeviceListener):
async def start_client():
self._atv = AppleTv(device=config, loop=_LOOP)
await self._atv.connect()
self._atv.listener = self
def connection_lost(self, _exception) -> None:
_LOG.exception("[%s] Lost connection %s", self.log_id, _exception)
def connection_closed(self) -> None:
_LOG.debug("[%s] Connection closed!", self.log_id)
### Error log
Extraction of logs (full logs attached), see the `pyatv.protocols.companion.connection:Connection lost to remote device: None`
```log
DEBUG:__main__:[Salon Apple TV] Updating app list
DEBUG:pyatv.protocols.companion.protocol:Exchange OPACK: {'_i': 'FetchLaunchableApplicationsEvent', '_t': 2, '_c': {}, '_x': 20683}
DEBUG:pyatv.protocols.companion.protocol:Send OPACK: {'_i': 'FetchLaunchableApplicationsEvent', '_t': 2, '_c': {}, '_x': 20683}
DEBUG:pyatv.protocols.companion.connection:>> Send data (Data=e4425f696046657463684c61756e636861626c654170706c69636174696f6e734576656e74425f740a425f63e0425f7831cb50, FrameType=08)
DEBUG:pyatv.protocols.companion.connection:>> Send (Encrypted=9321a4c7e7672125d7db2a4e7e1e1085ad6c605d165f5368a476b89b75d326b14f4a7d4a3b2221343d9cbee4ef0d264de86dcda9f2b08497c63b6509afaf1fd60bc865, Header=08000043)
DEBUG:pyatv.protocols.companion.connection:Received data (Data=080003eb9c2012840d634416fce4079ce20dc26d7569db9e9507e25b7cd0def7b968dac4e67e28be8e99c408ce5937d44e5e0f9bede16d49f318b49b0e1f72fa1fe8d0c8ebd170533f8348e962ef89e87a79d620968457e2b7e60f28c0022ebceff90b2dbf400a69ae8294863e28f7c2b288cbbb8298d1797993dcd96fd5c0e033e3c8c904d8f2fa5f6b5410512d24fb23caee1a5aa9d814fe41e2131974255ce1f5a80601701fe4568d2009ca872ce2a120f67c49244b0310f2acd2010916a2011bf0cc24ea2da236bd4741e8119e9506a3379a7ac5022c44a81209bb12330c9acc8aee21ee636246874d332915730bef7598d82174f23934845dc1a9de6...)
DEBUG:pyatv.protocols.companion.protocol:Received frame FrameType.E_OPACK: b'\xe4B_x1\xcbPC_rT\nB_c\xefa!com.canalplusdistrib.mycanal.prodGmyCANALScom.firecore.infuseFInfuseQcom.apple.FitnessEFormeRcom.apple.podcastsHPodcastsRcom.cbs.canada.appJParamount+Rcom.apple.TVMoviesEFilmsUcom.apple.TVWatchListBTVRcom.apple.TVPhotosFPhotosTcom.apple.TVAppStoreJApp\xc2\xa0StoreUcom.amazon.aiv.AIVAppKPrime VideoQcom.apple.TVShowsKS\xc3\xa9ries\xc2\xa0TVPcom.apple.ArcadeFArcadeTorg.videolan.vlc-iosCVLCRcom.apple.TVSearchJRechercherNfr.kaze.kzplayCADNYtv.molotov.MolotovAppProdIMolotovTVWcom.apple.TVHomeSharingKOrdinateursRcom.apple.facetimeHFaceTimeVcom.google.ios.youtubeGYouTubeQtv.mrmc.mrmc.tvosDMrMCYcom.lvmh.RadioClassiqueTVORadio ClassiqueTcom.olimsoft.oplayerGOPlayer[com.dailymotion.dailymotionMdailymotionTV^com.ubisoft.raymanadventurestvQRayman AdventuresUcom.disney.disneyplusGDisney+Tcom.apple.TVSettingsIR\xc3\xa9glagesUcom.apple.appleeventsR\xc3\x89v\xc3\xa9nements AppleScom.netflix.NetflixGNetflixWcom.firecore.infuse.proLInfuse Pro 4Qcom.apple.TVMusicGMusiqueXcom.allocine.applifranceIAlloCin\xc3\xa9\x03B_t\x0b'
DEBUG:pyatv.protocols.companion.protocol:Process incoming OPACK frame (FrameType.E_OPACK): {'_x': 20683, '_rT': 2, '_c': {'com.canalplusdistrib.mycanal.prod': 'myCANAL', 'com.firecore.infuse': 'Infuse', 'com.apple.Fitness': 'Forme', 'com.apple.podcasts': 'Podcasts', 'com.cbs.canada.app': 'Paramount+', 'com.apple.TVMovies': 'Films', 'com.apple.TVWatchList': 'TV', 'com.apple.TVPhotos': 'Photos', 'com.apple.TVAppStore': 'App\xa0Store', 'com.amazon.aiv.AIVApp': 'Prime Video', 'com.apple.TVShows': 'Séries\xa0TV', 'com.apple.Arcade': 'Arcade', 'org.videolan.vlc-ios': 'VLC', 'com.apple.TVSearch': 'Rechercher', 'fr.kaze.kzplay': 'ADN', 'tv.molotov.MolotovAppProd': 'MolotovTV', 'com.apple.TVHomeSharing': 'Ordinateurs', 'com.apple.facetime': 'FaceTime', 'com.google.ios.youtube': 'YouTube', 'tv.mrmc.mrmc.tvos': 'MrMC', 'com.lvmh.RadioClassiqueTV': 'Radio Classique', 'com.olimsoft.oplayer': 'OPlayer', 'com.dailymotion.dailymotion': 'dailymotionTV', 'com.ubisoft.raymanadventurestv': 'Rayman Adventures', 'com.disney.disneyplus': 'Disney+', 'com.apple.TVSettings': 'Réglages', 'com.apple.appleevents': 'Événements Apple', 'com.netflix.Netflix': 'Netflix', 'com.firecore.infuse.pro': 'Infuse Pro 4', 'com.apple.TVMusic': 'Musique', 'com.allocine.applifrance': 'AlloCiné'}, '_t': 3}
DEBUG:pyatv.protocols.companion.connection:Connection lost to remote device: None
DEBUG:pyatv.protocols.airplay.mrp_connection:Closing connection
```
### How to reproduce the bug?
1. Pair the Apple TV device with companion protocol using tvOS 18.4
2. Connect to it with pyatv
3. Subscribe to connection lost/closed events by implementing the `DeviceListener` interface
4. The client will receive a lost connection event a few milliseconds later
### What is expected behavior?
The client should not disconnect (unless there is a network failure...)
### Operating System
Tested on Windows and Ubuntu
### Python
3.12
### pyatv
16.0.0
### Device
Apple TV 4K (gen 2), tvOS 18.4
### Additional context
[debug.log](https://github.com/user-attachments/files/19323349/debug.log)
I haven’t had a chance to see if any of the related changes solve the problem; I’ll try to get to that in the next week as I get back up to speed.
hww3
(Bill Welliver)
August 20, 2025, 10:40pm
286
I’m pretty happy with my AppleTV as a device, especially if you’ve got other Apple devices already. If you have HomeKit devices or use the OpenHAB HomeKit bridge, it can act as a HomeKit hub, which helps greatly with reliability vs just having an iPad or such. Some of the newer versions have Thread and Matter support, which I suspect will finally reach critical mass.
The big problem with AppleTV/HomePod integration is that Apple hasn’t publicly specified any of the protocols and so we’re at their mercy in terms of keeping the integration running. If you have automatic updates enabled, this can lead to things breaking while the changes are worked around.
I work on the binding in my spare time, so there are some things that I’d like to do, but haven’t found time for, yet. I do generally try to address problems when I hear about them. And of course, others are welcome to help out… I’m always glad to assist anyone wanting to get a bit more involved.
I’ve never used the google AV stuff, so I can’t really comment. Perhaps others can provide their thoughts about what works well and what doesn’t?
Hope this helps, feel free to let us know if there’s any other info we can provide.
Bill
1 Like
OMR
(Ole Morten Rønning)
August 24, 2025, 3:03pm
287
Thanks.
That issue seems to be fixed by : companion: Use static id for _i in _systemInfo by postlund · Pull Request #2680 · postlund/pyatv · GitHub now part of 0.16.1
I have done this test:
atvscript -s 192.168.1.107 push_updates --debug
and the log shows that the companion protocol remains connected.
So I’m a bit at a loss why it is not working:
2025-08-24 17:01:05.010 [INFO ] [nding.appletv.internal.PyATV$Scanner] - Started process 2919336
2025-08-24 17:01:05.010 [INFO ] [nding.appletv.internal.PyATV$Scanner] - Process 2919336 isRunning=true
2025-08-24 17:01:05.010 [INFO ] [nding.appletv.internal.PyATV$Scanner] - AppleTVCommandLoop: Running /var/lib/openhab/tmp/appletv-binding/bin/atvscript -i 86F37899E0E7 --raop-credentials 56211473591d5de6d426ae0a49cf76b0030b45c8b4bd8c7db97181219ce19302:9d7a02c59acc4302fb8cc439e61d1cbfd00175b308c83659dcb267ee59c4a522:38364633373839392d453045372d344541372d424339452d423337383635423344443546:65373333656336312d303530632d346335312d616239662d376232623263343163386537 --airplay-credentials 56211473591d5de6d426ae0a49cf76b0030b45c8b4bd8c7db97181219ce19302:d404ea7937ff459014cb8c47979b0ea61697d0fc08415530982bd2008b6296b0:38364633373839392d453045372d344541372d424339452d423337383635423344443546:38343736356264392d363566392d343636632d623564662d633333636237383933636232 --companion-credentials 56211473591d5de6d426ae0a49cf76b0030b45c8b4bd8c7db97181219ce19302:0b2928cdda3465ae4c75f425d0577859e687279d3621b819da19b6a3f8e6db01:38364633373839392d453045372d344541372d424339452d423337383635423344443546:66663361316465342d343462372d343363642d626665652d626466363032333662643530 command_loop
2025-08-24 17:01:06.349 [INFO ] [nding.appletv.internal.PyATV$Scanner] - queueing command: artwork
2025-08-24 17:01:06.594 [INFO ] [nding.appletv.internal.PyATV$Scanner] - AppleTVEventScanner: Command process=2919332 exited.
2025-08-24 17:01:06.594 [INFO ] [nding.appletv.internal.PyATV$Scanner] - Process 2919332 exists.
2025-08-24 17:01:06.598 [WARN ] [nding.appletv.internal.PyATV$Scanner] - PATH: /var/lib/openhab/tmp/appletv-binding/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/snap/bin
The last thing shown before thread exits is the sending of the artwork command. Unsure if it is related?
(appletv-binding) omr@shs3:~$ atvscript -s 192.168.1.107 artwork
{"result": "failure", "datetime": "2025-08-24T17:03:18.968240+02:00", "error": "unsupported_command"}
(appletv-binding) omr@shs3:~$
hww3
(Bill Welliver)
August 24, 2025, 6:25pm
288
If you’re using the stock pyatv with the binding it won’t work as there are a number of things added to it. You’ll need to use the version that I maintain that includes the additional features. I’ve included the fix there but ran into some additional problems with the changes that came along, so I need a few days to test those out before it’s safe to update your copy.
1 Like