pyatv: Version 2.2.0 of hass-atv-beta fails to communicate with Apple TV 4K

Describe the bug

Upon upgrading from v1.8.1 of hass-atv-beta to v2.2.0, I’m unable to communicate with my Apple TV. Downgrading to v2.1.0 solves the problem. The Apple TV is on a separate VLAN, but mDNS relay is enabled, and this has never been a problem before. Additionally, v2.1.0 works fine!

Error log

n/a

How to reproduce the bug?

  1. Install v2.2.0 of hass-atv-beta
  2. Successfully complete pairing
  3. Note in the Home Assistant UI that OS version, model number, etc isn’t populated.
  4. Also note that in the Home Assistant UI, no play status information is conveyed, and turn on/turn off no longer works

What is expected behavior?

After pairing, communication with the Apple TV should proceed as normal.

Operating System

Linux (Debian)

Python

3.9

pyatv

Unknown (whatever hass-atv-beta v2.2.0 uses)

Device

Apple TV 4K First Gen tvOS 15.1.1

Additional context

Downgrading to v2.1.0 solves the problem.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (12 by maintainers)

Most upvoted comments

Send them by email to me, you have the address in my profile. I’ll have a look as soon as I can!

I’ve done some more cleanup and testing. I’ll open a PR shortly

Still early, but I took @bdraco’s changes and have them running locally and seem to have reliable discovery & status detection of Apple TVs and HomePods. Prior to this (similar network setup), I too couldn’t get discovery functional on 2.2.0 and reverted to 2.1.0 where I had intermittent discovery and random disconnects. Both seem to be resolved, text to speech works, etc.

I am in the same boat. I’ll generate some logs tonight.

Running this for a few hours, everything seems to be working well in my production setup. Surprisingly its actually using less cpu even though its multicast because most (all if everything is up) of the query answers are in the cache so they don’t actually send anything.

Here is a proof of concept branch that uses zeroconf for scanning (code temporarily in hass, can be moved to pyatv and pass in AsyncZeroconf instance). Its probably a bit bigger than it needs to be but scan didn’t allow passing in a scanner instance.

Note that its required to have a ServiceBrowser running for all the types we care about (except device info – we could add a check like we do in aiohomekit https://github.com/Jc2k/aiohomekit/blob/main/aiohomekit/zeroconf/__init__.py#L300 but probably ok to assume if they pass in zeroconf its running). I added services to the manifest to ensure they are being ServiceBrowsered and end up in cache https://github.com/bdraco/home-assistant/blob/scanner_use_zc/homeassistant/components/apple_tv/manifest.json#L9. I used a property that will never match for now. We can probably come up with a more elegant way of doing that.

https://github.com/bdraco/home-assistant/tree/scanner_use_zc

https://github.com/bdraco/home-assistant/blob/scanner_use_zc/homeassistant/components/apple_tv/scanner.py

Also _decode_properties should probably be used to decode the properties https://github.com/postlund/pyatv/blob/master/pyatv/core/mdns.py#L59

Ok, so, I think I understand now. In the latest change, @bdraco made a bunch of awesome optimizations since my scanning code generated a lot of duplicate traffic and high CPU usage. One relevant change is that instead if performing a multicast scan and look for identifiers belonging to the discovered device, a unicast scan toward the device address is performed instead. This is the most logical way of doing things, the problem is however that unicast scanning does not work across VLANs.

So, @bdraco, this became an unintended issue with the change. What would be your recommendation here? I guess it hits both config flow and connect loop.

Prior setup that worked was ATV’s in the user VLAN. Home Assistant in server VLAN. mDNS on USG 4 Pro turned on. ATV Airplay and HomeKit setting = Everyone

After update. With Airplay and HomeKit setting at everyone I cannot connect. If I change that settings to “Anyone on the same network” I can pair but have no actual control.

I pulled some longs and it appears like the devices are polled successfully by pyatv scan.

What is the best way to get you those logs? Thank you!

Hmm, are you sure there’s nothing in the log? Otherwise, please enable additional logging. Hopefully it can help out troubleshooting this.

https://github.com/postlund/hass-atv-beta#debug-logs