unfoldedcircle / feature-and-bug-tracker

Feature and bug tracker repository for Unfolded Circle products
22 stars 0 forks source link

[bug] pyatv.exceptions.BlockedStateError: remote_control is blocked #300

Open kennymc-c opened 5 months ago

kennymc-c commented 5 months ago

Is there an existing issue for this?

Description

I recently added my Apple TV to Home Assistant. As a result, operation via Remote Two no longer worked. The log showed the following message:

2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO    pyatv.exceptions.BlockedStateError: remote_control is blocked
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "pyatv/support/shield.py", line 71, in _guard_method
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "tv.py", line 441, in cursorLeft
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "driver.py", line 369, in event_handler
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "pyee/base.py", line 139, in _emit_handle_potential_error
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "pyee/base.py", line 179, in emit
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "pyee/asyncio.py", line 71, in callback
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO      File "asyncio/events.py", line 81, in _run
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO    Traceback (most recent call last):
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO    handle: <Handle AsyncIOEventEmitter._emit_run.<locals>.callback(<Task finishe... is blocked')>) at pyee/asyncio.py:65>
2024-01-29 17:19:27.183139 +00:00   intg-appletv    INFO    ERROR:asyncio:Exception in callback AsyncIOEventEmitter._emit_run.<locals>.callback(<Task finishe... is blocked')>) at pyee/asyncio.py:65
2024-01-29 17:19:27.177180 +00:00   intg-appletv    INFO    DEBUG:ucapi.api:<-: {"kind":"req","id":21,"msg":"entity_command","msg_data":{"cmd_id":"cursor_left","entity_id":"40FC6C78-E08D-4A6B-9CBC-37078152133E","entity_type":"media_player"}}

Only after I removed the ATV from HA again, removed all corresponding remote apps in the ATV settings, removed the entity in the integration menu and then restarted the setup I was able to operate the device via the remote again. Before that, I only got messages like service not available or a timeout.

How to Reproduce

  1. Add Apple TV to Remote Two
  2. Add the same Apple TV to Home Assistant
  3. Try to control the Apple TV via Remote Two

Expected behavior

The Apple TV can be fully controlled via Remote Two

System version

1.6.7

What part of the system affected by the problem?

Integration

Additional context

No response

martonborzak commented 4 months ago

Might be related to #315

kennymc-c commented 4 months ago

I found out that the problem can be reproduced very easily by restarting the Apple TV. Beforehand, everything still works and after the restart, these error messages appear with every Apple TV command, which then result in a command timeout a short time later. Restarting the Remote Two solves the problem.

martonborzak commented 4 months ago

I found out that the problem can be reproduced very easily by restarting the Apple TV. Beforehand, everything still works and after the restart, these error messages appear with every Apple TV command, which then result in a command timeout a short time later. Restarting the Remote Two solves the problem.

Thanks. So both the remote and HA can control the Apple TV before a restart?

kennymc-c commented 4 months ago

I haven't used HA to control the Apple TV since I created this issue. Right now I only control it via the internal integration. I think HA could be unrelated to this issue. I can't remember exactly but maybe I also restarted the Apple TV when set up the integration in HA which caused the same issue.

martonborzak commented 4 months ago

I haven't used HA to control the Apple TV since I created this issue. Right now I only control it via the internal integration. I think HA could be unrelated to this issue. I can't remember exactly but maybe I also restarted the Apple TV when set up the integration in HA which caused the same issue.

Just want to make sure because the original description says it only worked after removing from HA.

zehnm commented 3 months ago

Fixed in the next release. I've found one cause for the BlockedStateError and also added a reconnect trigger in case it still occurs. This error is usually thrown if the connection has been dropped by the Apple TV, but the integration didn't create a new connection.

zehnm commented 3 months ago

New Apple TV integration is released in beta group. If we don't find a showstopper it will be released this week.

kennymc-c commented 3 months ago

With 1.7.4 the BlockedStateError seems to be fixed but it still takes 5-10 seconds after a restart to control the Apple TV again. I noticed a KeyError in the integration logs: UCR2_logs_2024-03-09.txt

zehnm commented 3 months ago

Restart of what, the ATV device or remote?

The error is a TimeoutError: ATV didn't respond

kennymc-c commented 3 months ago

A restart of the Apple TV