Closed jasr1 closed 3 years ago
This sounds like the component ends up in a re-connect loop, which it shouldn't. It would help me a lot if you provide some logs, I don't see this behavior myself.
Sure, I can definitely get you the logs. Where do I find them?
Preferably like this:
logger:
default: warning
logs:
pyatv: debug
custom_components.apple_tv: debug
It will set default log level to warning to avoid getting swamped with debug data from other components.
Awesome, here are the logs:
Another issue seems to have arisen (I am not sure if this is related), but when I restarted my Home Assistant instance, upon start up the Apple TV showed it was in the "Paused" state, even though the Apple TV is completely turned off.
2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Disconnecting from device
2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
2020-04-17 00:08:50 DEBUG (MainThread) [pyatv.mrp.connection] Disconnected from device: None
2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=True
2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Not starting connect loop (True, False)
2020-04-17 00:08:55 DEBUG (MainThread) [custom_components.apple_tv] Starting connect loop
2020-04-17 00:08:55 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
2020-04-17 00:08:55 DEBUG (MainThread) [pyatv.support.udns] Sending DNS request to 192.168.8.184 (Data=35ff012000040000000000000b5f6170706c6574762d7632045f746370056c6f63616c0000ff80010b5f746f7563682d61626c65045f746370056c6f63616c0000ff80010e5f6d6564696172656d6f74657476045f746370056c6f63616c0000ff8001085f616972706c6179045f746370056c6f63616c0000ff8001)
2020-04-17 00:09:00 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E with address 192.168.8.184, trying to scan
2020-04-17 00:09:00 DEBUG (MainThread) [pyatv] Discovering devices for 5 seconds
2020-04-17 00:09:01 DEBUG (MainThread) [pyatv] Auto-discovered Bedroom at 192.168.8.65:7000 (Protocol.AirPlay)
2020-04-17 00:09:05 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
2020-04-17 00:09:05 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E, trying later
2020-04-17 00:09:05 DEBUG (MainThread) [custom_components.apple_tv] Reconnecting in 1 seconds
2020-04-17 00:09:06 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
2020-04-17 00:09:06 DEBUG (MainThread) [pyatv.support.udns] Sending DNS request to 192.168.8.184 (Data=35ff012000040000000000000b5f6170706c6574762d7632045f746370056c6f63616c0000ff80010b5f746f7563682d61626c65045f746370056c6f63616c0000ff80010e5f6d6564696172656d6f74657476045f746370056c6f63616c0000ff8001085f616972706c6179045f746370056c6f63616c0000ff8001)
2020-04-17 00:09:11 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E with address 192.168.8.184, trying to scan
2020-04-17 00:09:11 DEBUG (MainThread) [pyatv] Discovering devices for 5 seconds
2020-04-17 00:09:12 DEBUG (MainThread) [pyatv] Auto-discovered Bedroom at 192.168.8.65:7000 (Protocol.AirPlay)
2020-04-17 00:09:16 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
2020-04-17 00:09:16 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E, trying later
2020-04-17 00:09:16 DEBUG (MainThread) [custom_components.apple_tv] Reconnecting in 3 seconds
2020-04-17 00:09:19 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
2020-04-17 00:09:19 DEBUG (MainThread) [pyatv.support.udns] Sending DNS request to 192.168.8.184 (Data=35ff012000040000000000000b5f6170706c6574762d7632045f746370056c6f63616c0000ff80010b5f746f7563682d61626c65045f746370056c6f63616c0000ff80010e5f6d6564696172656d6f74657476045f746370056c6f63616c0000ff8001085f616972706c6179045f746370056c6f63616c0000ff8001)
2020-04-17 00:09:24 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E with address 192.168.8.184, trying to scan
2020-04-17 00:09:24 DEBUG (MainThread) [pyatv] Discovering devices for 5 seconds
2020-04-17 00:09:25 DEBUG (MainThread) [pyatv] Auto-discovered Bedroom at 192.168.8.65:7000 (Protocol.AirPlay)
2020-04-17 00:09:29 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
PS - the device the component ends up auto-discovering titled "Bedroom" is my airplay-enable Sonos speaker.
Another issue seems to have arisen (I am not sure if this is related), but when I restarted my Home Assistant instance, upon start up the Apple TV showed it was in the "Paused" state, even though the Apple TV is completely turned off.
Powered off is a fuzzy concept here because the device can appear to be turned off (no white light or image output), but still have power and an IP connection. In that case it can report what ever it feels like. My Apple TV sometimes reports that the music app is active and a song is paused, even though it is "off". Best would be if you check the Remote app on your phone and see what that is reporting.
2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Disconnecting from device 2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False 2020-04-17 00:08:50 DEBUG (MainThread) [pyatv.mrp.connection] Disconnected from device: None 2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=True 2020-04-17 00:08:50 DEBUG (MainThread) [custom_components.apple_tv] Not starting connect loop (True, False) 2020-04-17 00:08:55 DEBUG (MainThread) [custom_components.apple_tv] Starting connect loop 2020-04-17 00:08:55 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False 2020-04-17 00:08:55 DEBUG (MainThread) [pyatv.support.udns] Sending DNS request to 192.168.8.184 (Data=35ff012000040000000000000b5f6170706c6574762d7632045f746370056c6f63616c0000ff80010b5f746f7563682d61626c65045f746370056c6f63616c0000ff80010e5f6d6564696172656d6f74657476045f746370056c6f63616c0000ff8001085f616972706c6179045f746370056c6f63616c0000ff8001) 2020-04-17 00:09:00 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E with address 192.168.8.184, trying to scan 2020-04-17 00:09:00 DEBUG (MainThread) [pyatv] Discovering devices for 5 seconds 2020-04-17 00:09:01 DEBUG (MainThread) [pyatv] Auto-discovered Bedroom at 192.168.8.65:7000 (Protocol.AirPlay) 2020-04-17 00:09:05 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False 2020-04-17 00:09:05 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E, trying later 2020-04-17 00:09:05 DEBUG (MainThread) [custom_components.apple_tv] Reconnecting in 1 seconds 2020-04-17 00:09:06 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False 2020-04-17 00:09:06 DEBUG (MainThread) [pyatv.support.udns] Sending DNS request to 192.168.8.184 (Data=35ff012000040000000000000b5f6170706c6574762d7632045f746370056c6f63616c0000ff80010b5f746f7563682d61626c65045f746370056c6f63616c0000ff80010e5f6d6564696172656d6f74657476045f746370056c6f63616c0000ff8001085f616972706c6179045f746370056c6f63616c0000ff8001) 2020-04-17 00:09:11 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E with address 192.168.8.184, trying to scan 2020-04-17 00:09:11 DEBUG (MainThread) [pyatv] Discovering devices for 5 seconds 2020-04-17 00:09:12 DEBUG (MainThread) [pyatv] Auto-discovered Bedroom at 192.168.8.65:7000 (Protocol.AirPlay) 2020-04-17 00:09:16 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False 2020-04-17 00:09:16 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E, trying later 2020-04-17 00:09:16 DEBUG (MainThread) [custom_components.apple_tv] Reconnecting in 3 seconds 2020-04-17 00:09:19 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False 2020-04-17 00:09:19 DEBUG (MainThread) [pyatv.support.udns] Sending DNS request to 192.168.8.184 (Data=35ff012000040000000000000b5f6170706c6574762d7632045f746370056c6f63616c0000ff80010b5f746f7563682d61626c65045f746370056c6f63616c0000ff80010e5f6d6564696172656d6f74657476045f746370056c6f63616c0000ff8001085f616972706c6179045f746370056c6f63616c0000ff8001) 2020-04-17 00:09:24 DEBUG (MainThread) [custom_components.apple_tv] Failed to find device 93B23502-4B77-4795-ADC4-D0016032545E with address 192.168.8.184, trying to scan 2020-04-17 00:09:24 DEBUG (MainThread) [pyatv] Discovering devices for 5 seconds 2020-04-17 00:09:25 DEBUG (MainThread) [pyatv] Auto-discovered Bedroom at 192.168.8.65:7000 (Protocol.AirPlay) 2020-04-17 00:09:29 DEBUG (MainThread) [custom_components.apple_tv] Updating state: connected=False, disconnected=False
Yep, definitely a connect loop due to sleep here. I'm working on a "fix" for this, but it is again very tricky. I think I will have to do a proper write-up about power management and figure out a good approach to that. But lets leave it at "it's not as easy as it seems".
PS - the device the component ends up auto-discovering titled "Bedroom" is my airplay-enable Sonos speaker.
It will be visible in the debug logs but it should hopefully not appear in the dialog where you add devices I hope? That was something I fixed in 0.5.0.
I just pushed a new update that should hopefully make this better. Hopefully the device should end up in idle state.
Hey, just updated the integration but now I am getting an error that makes the state 'Unavailable'. Here are the logs:
2020-04-28 08:43:27 ERROR (MainThread) [homeassistant.setup] Setup failed for apple_tv: unknown error
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 137, in _async_setup_component component = integration.get_component()
File "/usr/src/homeassistant/homeassistant/loader.py", line 268, in get_component cache[self.domain] = importlib.import_module(self.pkg_path)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/apple_tv/__init__.py", line 8, in <module> from pyatv import connect, exceptions, scan
File "/usr/local/lib/python3.7/site-packages/pyatv/__init__.py", line 20, in <module> from pyatv.mrp import MrpAppleTV
File "/usr/local/lib/python3.7/site-packages/pyatv/mrp/__init__.py", line 25, in <module> from pyatv.mrp import messages, protobuf
File "/usr/local/lib/python3.7/site-packages/pyatv/mrp/messages.py", line 140, in <module> identifier, send_error=protobuf.SendCommandResultMessage.SendError.NoError
AttributeError: 'EnumTypeWrapper' object has no attribute 'NoError'
Same as in #623, just pushed a fix for it.
Thanks, just updated and the re-connect loop is not happening!
However, there is one issue that has arisen (I do not know if it is related to this issue or not). After a restart, the Apple TV state remains idle even if there is something playing or paused on the device. To get the proper state, I have to turn off the Apple TV (from HA), and then turn it back on. Unfortunately, nothing shows up in the logs about this. Any other way I can help you resolve this issue?
Yeah, this is an issue other people see as well. I don't really know what the problem is or how to solve it. But if you can provide some logs, that would be great. Log diversity might be a good thing here.
Can you possibly try with the latest update I just pushed to the component?
I have the same problem running the latest version. Apple tv is often unavailable and HA is stuck in a reconnect loop. No "key press" working from HA. From my iphone remote everything works fine.
@swenox Can you provide some logs from the re-connect loop? I suspect something "bad" happens which leads to a disconnect. But then scanning fails so the connection is never restored because of that.
@postlund I will try to get a log as soon as i have figured out how to. :)
@postlund Here is a log. Is this what youre looking for? 😊
2020-07-28 22:40:15 ERROR (MainThread) [custom_components.apple_tv] Failed to connect
Traceback (most recent call last):
File "/config/custom_components/apple_tv/__init__.py", line 227, in _connect_loop
await self._connect(conf)
File "/config/custom_components/apple_tv/__init__.py", line 317, in _connect
self.atv = await connect(conf, self.hass.loop, session=session)
File "/usr/local/lib/python3.8/site-packages/pyatv/__init__.py", line 76, in connect
await atv.connect()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 704, in connect
await self._protocol.start()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 66, in start
self.device_info = await self.send_and_receive(msg)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 138, in send_and_receive
return await self._receive(identifier, timeout)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 146, in _receive
await asyncio.wait_for(semaphore.acquire(), timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 490, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
2020-07-28 22:40:33 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for simpleicons which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-07-28 22:41:18 ERROR (MainThread) [custom_components.apple_tv] Failed to connect
Traceback (most recent call last):
File "/config/custom_components/apple_tv/__init__.py", line 227, in _connect_loop
await self._connect(conf)
File "/config/custom_components/apple_tv/__init__.py", line 317, in _connect
self.atv = await connect(conf, self.hass.loop, session=session)
File "/usr/local/lib/python3.8/site-packages/pyatv/__init__.py", line 76, in connect
await atv.connect()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 704, in connect
await self._protocol.start()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 66, in start
self.device_info = await self.send_and_receive(msg)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 138, in send_and_receive
return await self._receive(identifier, timeout)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 146, in _receive
await asyncio.wait_for(semaphore.acquire(), timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 490, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
2020-07-28 22:41:54 ERROR (MainThread) [custom_components.apple_tv] Failed to connect
Traceback (most recent call last):
File "/config/custom_components/apple_tv/__init__.py", line 227, in _connect_loop
await self._connect(conf)
File "/config/custom_components/apple_tv/__init__.py", line 317, in _connect
self.atv = await connect(conf, self.hass.loop, session=session)
File "/usr/local/lib/python3.8/site-packages/pyatv/__init__.py", line 76, in connect
await atv.connect()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 704, in connect
await self._protocol.start()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 66, in start
self.device_info = await self.send_and_receive(msg)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 138, in send_and_receive
return await self._receive(identifier, timeout)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 146, in _receive
await asyncio.wait_for(semaphore.acquire(), timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 490, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
2020-07-28 22:42:50 ERROR (MainThread) [custom_components.apple_tv] Failed to connect
Traceback (most recent call last):
File "/config/custom_components/apple_tv/__init__.py", line 227, in _connect_loop
await self._connect(conf)
File "/config/custom_components/apple_tv/__init__.py", line 317, in _connect
self.atv = await connect(conf, self.hass.loop, session=session)
File "/usr/local/lib/python3.8/site-packages/pyatv/__init__.py", line 76, in connect
await atv.connect()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 704, in connect
await self._protocol.start()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 66, in start
self.device_info = await self.send_and_receive(msg)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 138, in send_and_receive
return await self._receive(identifier, timeout)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 146, in _receive
await asyncio.wait_for(semaphore.acquire(), timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 490, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
2020-07-28 22:46:57 ERROR (MainThread) [custom_components.apple_tv] Failed to connect
Traceback (most recent call last):
File "/config/custom_components/apple_tv/__init__.py", line 227, in _connect_loop
await self._connect(conf)
File "/config/custom_components/apple_tv/__init__.py", line 317, in _connect
self.atv = await connect(conf, self.hass.loop, session=session)
File "/usr/local/lib/python3.8/site-packages/pyatv/__init__.py", line 76, in connect
await atv.connect()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/__init__.py", line 704, in connect
await self._protocol.start()
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 66, in start
self.device_info = await self.send_and_receive(msg)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 138, in send_and_receive
return await self._receive(identifier, timeout)
File "/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py", line 146, in _receive
await asyncio.wait_for(semaphore.acquire(), timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 490, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
@swenox Sorry about the delay. But yes, that's what I'm after. Very peculiar issue I must say. Can you start by testing with the latest updated component and see if the same re-connect loop happens?
@postlund I will try to update. I have been ignoring this issue for a while now and today i checked and HA havent seen my apple tv in 3 weeks. (It's on every day) I'll get back to you with results after the update.
@postlund Im now running the latest version of HA and appletv addon and it's still not working. Status is mostly unknown and HA cant find the apple tv even when it's on and playing something. This is really strange.
Just "dumping" my debug here. Maybe it's usefull. tvOS 14.3
Edit: make it smaller :)
It would be great if anyone of you in this issue could retry with latest version of Home Assistant and let me know what happens. No need for the custom component anymore.
@postlund
It would be great if anyone of you in this issue could retry with latest version of Home Assistant and let me know what happens. No need for the custom component anymore.
Still issues...
Generated html log for for comment #789274266 is here.
Still same with Home Assistant 2021.3.2
@MarcHagen Can you provide some logs as well?
Generated html log for for comment #792330994 is here.
@MarcHagen I don't quite get why the device decides to close the connection. Encryption is set up just fine and then, when the first message is sent after that: connection reset. Can you try running atvremote
from another host and see if that works?
@MarcHagen Also, what is the exact use case here? What are you doing?
@postlund oke, i have to admit, i feel pretty stupid. So apparently somewhere in updating of hass the pair keys where invalid/gone/not working. I had removed the integration/entity, rebooted hass, added paired it again and now it works. I had tried this before in the 2021.2 something version but that didn't work. So sorry if this caused you(of someone else) some inconvenience.
@MarcHagen Also, what is the exact use case here? What are you doing?
I use some automations within HA to control my apple tv. To a "netflix and chill" setting, turning on every media device. Also to do some "force" shutdowns when were going to bed, or away. And it sometimes get used just as a photoslider/videoslider/videowall. HA sends the remote command to the ATV to open a app and start a show.
@MarcHagen 👍
I feel that this issue has kinda moved away too far from the initial problem, making it hard to keep track. Gonna close this now. If any issues still persists, please search amongst already open issues and add a comment in one of those or create a new issue if none of the open matches. Thanks!
Describe the bug
When I turn off the Apple TV from the remote, the status ends up switching from playing/paused/idle etc to "Unknown", instead of "Off" or "idle".
To Reproduce
Turn off Apple TV from the remote.
Expected behavior
The status to be "Off" or "idle" when the Apple TV is off.
System Setup (please complete the following information):
Additional context
Apple TV is connected to the internet via ethernet cable. I have restarted Home Assistant and the issue still occurs.