Closed Veldkornet closed 4 years ago
I'm not sure to be honest, it just happens at seemingless random times. Usually zeroconf stops working at all, at least for
atvremote
. I have seen this behavior several times when I have Home Assistant running with my component connected to ATV. When runningatvremote
on the same machine usually return zero result. My best guess is that it has to do with port re-using (since you have to specify that a UDP can be re-used when binding to it), but I haven't investigated that further. It's also hard to tell if it's the same issue.
hmm hmm... how often the port usage check is made? I mean, when the port is being re-used, atvremote isn't aware of that change and everything stop working at that point?
Also, I've been running your component for a few hours only and so far, it is working flawlessly. After how much time you end up having issues? a few days? weeks?
With mDNS/Zeroconf, the request is multicasted out on the network to a specific address (224.0.0.251). All clients must listen on port 5353 UDP on this address. When a request is received a response is sent back to the requester at the same port, 5353. If an application already listens on this port you can't bind to it, that wouldn't normally make sense. Since UDP is datagram based and has no retransmissions, segmentation or other complex mechanisms, it works two have several listeners anyways and that they receive the same data. But you have to say that you want to reuse a port when binding to it. So you only do it initially.
Last time I saw it it happened instantly, more or less. I started Home Assistant and shortly thereafter I tried atvremote
in another shell and it didn't find any hosts.
So chances are the solution might reside somewhere else in mDNS/Zeronconf? I mean, you won't be able to take care of that issue from within pyatv or atvremote ?
Yes, I see that as an inherent risk. But that doesn't mean it's not solvable, we just have to make a PR somewhere else or point to some issue stating where it's potentially fixed. If it's a bug in python for instance, then it's not much more we can do then require a specific version of python in case it's fixed.
I'm trying to create a workaround for the scanning issues, please have a look at #343.
I have managed to complete #343 and integrate it with the component, but I need to do some clean up and additional testing of it. To summarize how it works:
pyatv
will scan for that device only by sending a request directly to the device. This should work even when normal scans doesn't work. Entering an identifier or name will trigger a scan just like before in order to find the device.This should work good for all users. My assumption is that scanning works sometimes, even for users that have problems. This approach hopefully makes the connection recover at some point in time. If it doesn't, then the integration must be removed and added again for now. I will have to look at an approach to edit IP-address manually in the future.
My intention is to release an update to the component today/tonight. I would be extremely happy to get some testers on this, especially if you have said problems.
This will be a breaking change: you must remove and re-add your integration when updating!
Updated version of the component is out now!
Do you have an updated version of the beta add-on? If so, could you post a link?
Latest commit in https://github.com/postlund/hass-atv-beta is always latest "version".
Thank you!
@postlund seems to be working great, thank you!
@nikolaykasyanov Great, thanks for trying! 👍 Did you by any chance test unicast scanning, I.e. adding device by specifying IP-address?
@postlund yes, I'm adding the device via IP and it survives HASS restarts.
@nikolaykasyanov Perfect, thanks again! 👍 Seems to be a problem lurking somewhere, as seen in #363, so it is good so see that it works for at least someone else.
Problem is partially solve via unicast scanning (entering IP-address). A foolproof solution is something we probably won's see near time. But I hope this is good enough.
Describe the bug After initially setting up the AppleTV in HomeAssistant 0.102.2 in Hass.io, you restart HomeAssistant, and the AppleTV no longer works.
2019-11-27 22:57:08 ERROR (MainThread) [custom_components.apple_tv] Failed to find device with identifier xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
The only way to make it work again is to remove the AppleTv and re-add it again.To Reproduce
Expected behavior
System Setup (please complete the following information):
Additional context