Pyatv: Since tvOS 14 turn_off SOMETIMES only open the lateral menu, maybe just timing issue...

Created on 10 Jan 2021  路  12Comments  路  Source: postlund/pyatv

Since tvOS 14 (I cannot easily know if it was already the case with 14.0.1, or even 14.0.0, but with tvOS 13 this issue never came into light), the turn_off command I send using atvremote sometimes only open the lateral menu, and don't validate the sleep command.

A simple select command works or a second turn_off does the job every time though.

System Setup:

  • OS: Mac OS X Mojave 10.14.6
  • Python: 3.8.3
  • pyatv: 0.7.5 (using atvremote)

    • Apple TV: Apple TV 4 tvOS 14.0.2 build 18J411

bug

All 12 comments

I think this might be a timing issue, yes. Before we used ack'ed requests, which allowed us to wait until a command finished. This seemed to break with tvOS 14, so I had to remove it. As a workaround, we should probably add a small delay (let's say a second to be sure) before pressing select. That should solve the problem.

I can prepare a PR if you are willing to test? It's easier to do by installing pyatv and running atvremote manually, as bumping versions for dependencies in Home Assistant without making a release is more or less impossible.

Hello, thank you!
As a matter of fact, I only use atvremote (inside ON/OFF/Status scripts for the Script2 home bridge accessory). I use only the on/off feature, so any beta version you provide can be easily tested.
Maybe a suggestion: make the delay configurable (like a value in millisecond given in argument, at least for the beta version) so I can test several values easily (I think that 1 second could be a lot, as the issue occurs only sometimes; 300 ms could be largely enough).

I use this the exact same way via script in Homebridge. I can confirm just a few ms will be fine. 1 second will be massively overkill. I'd even say as low as 100ms would likely be OK.

I hear you and I have created #923 which introduces a 100ms delay between the commands. Please give it a try!

OK, thank you a lot for your reactivity !!, will try it. Just to be sure (as it is the first time I update from a pull request), do I use the command "pip3 install git+https://github.com/postlund/pyatv.git@refs/pull/923/head" to update ?

No worries 馃憤 I believe that command should work, but make sure to scan output from pip for any potential errors.

In fact, that command should work (as I found in both your documentation and the internet locations, but it seems that the files changed by your pull request are not updated (__init__.py for instance).

Here is the output of the pip3 command:

MacMini2:mrp mrabozee$ sudo pip3 install  git+https://github.com/postlund/pyatv.git@refs/pull/923/head
WARNING: The directory '/Users/mrabozee/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting git+https://github.com/postlund/pyatv.git@refs/pull/923/head
  Cloning https://github.com/postlund/pyatv.git (to revision refs/pull/923/head) to /private/tmp/pip-req-build-1b52u52x
  WARNING: Did not find branch or tag 'refs/pull/923/head', assuming revision or ref.
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Requirement already satisfied: protobuf<4,>=3.6.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pyatv==0.7.5) (3.12.2)
Requirement already satisfied: srptools>=0.2.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pyatv==0.7.5) (1.0.0)
Requirement already satisfied: aiohttp<5,>=3.1.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pyatv==0.7.5) (3.6.2)
Requirement already satisfied: zeroconf>=0.28.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pyatv==0.7.5) (0.28.7)
Requirement already satisfied: cryptography>=2.6 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pyatv==0.7.5) (2.9.2)
Requirement already satisfied: netifaces>=0.10.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pyatv==0.7.5) (0.10.9)
Requirement already satisfied: async-timeout<4.0,>=3.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp<5,>=3.1.0->pyatv==0.7.5) (3.0.1)
Requirement already satisfied: chardet<4.0,>=2.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp<5,>=3.1.0->pyatv==0.7.5) (3.0.4)
Requirement already satisfied: yarl<2.0,>=1.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp<5,>=3.1.0->pyatv==0.7.5) (1.4.2)
Requirement already satisfied: attrs>=17.3.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp<5,>=3.1.0->pyatv==0.7.5) (19.3.0)
Requirement already satisfied: multidict<5.0,>=4.5 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp<5,>=3.1.0->pyatv==0.7.5) (4.7.6)
Requirement already satisfied: six>=1.4.1 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from cryptography>=2.6->pyatv==0.7.5) (1.15.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from cryptography>=2.6->pyatv==0.7.5) (1.14.0)
Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.6->pyatv==0.7.5) (2.20)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from protobuf<4,>=3.6.0->pyatv==0.7.5) (41.2.0)
Requirement already satisfied: idna>=2.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from yarl<2.0,>=1.0->aiohttp<5,>=3.1.0->pyatv==0.7.5) (2.10)
Requirement already satisfied: ifaddr>=0.1.7 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from zeroconf>=0.28.0->pyatv==0.7.5) (0.1.7)
MacMini2:mrp mrabozee$ 

Might be because you have pyatv installed with the same version already, so pip probably skips installing it. Try pip install -U ... or pip install --force-reinstall, might work better. Would also recommend that you install in a venv instead of globally on the system.

I modified the file manually (just 2 lines :-) )

The thing is that it waits 100 seconds between the 2 commands with DELAY_BETWEEN_COMMANDS = 100.0

I have instead written DELAY_BETWEEN_COMMANDS = 0.100 and so far so good (I checked 10 ON / OFF cycles)

Haha, yes, you are right. Waiting 100s might be a bit overkill 馃槈

Pushed an update with correct time now!

I went ahead and merged the fix, it will be included in the next release which I will make shortly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rephlex00 picture rephlex00  路  8Comments

jjlawren picture jjlawren  路  4Comments

cpohli picture cpohli  路  4Comments

postlund picture postlund  路  13Comments

poudenes picture poudenes  路  3Comments