pyatv: Scan is broken after update?

import asyncio
import time

import pyatv #for controlling apple tv
from pyatv import conf, connect, scan #for controlling apple tv
from pyatv.const import Protocol #for getting port

async def test():
    loop = asyncio.get_event_loop()
    atvs = await pyatv.scan(loop, timeout=5)
    print(atvs)

asyncio.run(test())

the above was working fine prior to the last update? Any idea what would have changed to break it?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (6 by maintainers)

Commits related to this issue

Most upvoted comments

If I get time for it, I will revert the port change tonight. I will have to look through a few issues first, but I will try to make a release soon and bump in Home Assistant for the 1.0 release.

Did not hardcode ports. Simply did the below. On my router I setup the below addresses to be static in DHCP, so even after reboot or arp reset these devices will pick up the same addresses. Its fast, works, and runs inside its own thread updating a global if the device settings were ever to change for some reason, or the ports to shift, it would automatically update the global and the rest of the code would be aware.


async def FindAppleTV():
    global AppleTVInfo
    while(1):
        try:
            loop = asyncio.get_event_loop()
            atvs = await pyatv.scan(loop, hosts=['10.1.1.72', '10.1.1.184'],timeout=5) #can no longer scan by just protocol.
            #Get TVs update ports
            for tv in atvs:
                tvName = tv.name
                tvPort = tv.get_service(Protocol.MRP).port
                AppleTVInfo[tvName]= tvPort
            print(Fore.BLUE + "\nApple TV Info: " + str(AppleTVInfo))
        except Exception as E:
            print("Error Apple TV Thread: " + str(E))
        time.sleep(60)

I suspect this is because I changed the port I bind to from random to 5353, which I would expect should work (that what python-zeroconf seems to do). But I might have to revert that.