GithubHelp home page GithubHelp logo

postlund / pyatv Goto Github PK

View Code? Open in Web Editor NEW
824.0 26.0 87.0 6.46 MB

A client library for Apple TV and AirPlay devices

Home Page: https://pyatv.dev

License: MIT License

Python 99.85% Shell 0.12% Dockerfile 0.03%
home-automation apple-tv python3 asyncio pypi hacktoberfest airplay raop

pyatv's Introduction

A client library for Apple TV and AirPlay devices

Tests pyatv Actions codecov Code style: black PyPi Package Gitpod Ready-to-Code Downloads PyPI pyversions License: MIT

This is an asyncio python library for interacting with Apple TV and AirPlay devices. It mainly targets Apple TVs (all generations, including tvOS 15 and later), but also supports audio streaming via AirPlay to receivers like the HomePod, AirPort Express and third-party speakers. It can act as remote control to the Music app/iTunes in macOS.

All the documentation you need is available at pyatv.dev.

What can it do?

Some examples include:

  • Remote control commands
  • Metadata retrieval with push updates
  • Stream files via AirPlay
  • List and launch installed apps
  • List and switch user accounts
  • Add, remove or set audio output devices (e.g. HomePods)
  • Keyboard support
  • Persistent storage of credentials and settings

...and lots more! A complete list is available here.

Great, but how do I use it?

All documentation (especially for developers) are available at pyatv.dev. It is however possible to install with pip and set up a new device atvremote:

$ pip install pyatv
$ atvremote wizard
Looking for devices...
Found the following devices:
    Name                      Model                    Address
--  ------------------------  -----------------------  -----------
 1  Receiver+                 airupnp                  10.0.10.200
 2  Receiver                  RX-V773                  10.0.10.82
 3  Pierre's AirPort Express  AirPort Express (gen 2)  10.0.10.168
 4  FakeATV                   Unknown                  10.0.10.254
 5  Vardagsrum                Apple TV 4K              10.0.10.81
 6  Apple TV                  Apple TV 3               10.0.10.83
Enter index of device to set up (q to quit): 4
Starting to set up FakeATV
Starting to pair Protocol.MRP
Enter PIN on screen: 1111
Successfully paired Protocol.MRP, moving on...
Pairing finished, trying to connect and get some metadata...
Currently playing:
  Media type: Music
Device state: Playing
       Title: Never Gonna Give You Up
      Artist: Rick Astley
    Position: 1/213s (0.0%)
      Repeat: Off
     Shuffle: Off
Device is now set up!

After setting up a new device, other commands can be run directly:

$ atvremote -s 10.0.10.254 playing
  Media type: Music
Device state: Playing
       Title: Never Gonna Give You Up
      Artist: Rick Astley
    Position: 1/213s (0.0%)
      Repeat: Off
     Shuffle: Off
$ atvremote -s 10.0.10.254 pause
$ atvremote -n FakeATV play

You can also run it inside a container (x86_64, aarch64, armv7):

docker run -it --rm --network=host ghcr.io/postlund/pyatv:0.14.0 atvremote scan

The master tag points to latest commit on the master branch and can latest points to the latest release.

I need to change something?

Want to help out with pyatv? Press the button below to get a fully prepared development environment and get started right away!

Open in Gitpod

Shortcuts to the good stuff

To save you some time, here are some shortcuts:

pyatv's People

Contributors

acheronfail avatar bdraco avatar ckeehan avatar crxporter avatar dependabot-preview[bot] avatar dependabot[bot] avatar ehendrix23 avatar jakobjjw avatar jdsnape avatar jlian avatar kibosj avatar lucasec avatar maxileith avatar michalmo avatar nebzhb avatar onkelbeh avatar paxswill avatar pierrickrouxel avatar postlund avatar pranav767 avatar robbiet480 avatar robnee avatar schlaubischlump avatar sebbo2002 avatar shraymonks avatar stackia avatar stickpin avatar sy6sy2 avatar systemcrash avatar xpnewmedia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyatv's Issues

Timeouts during login

I've seen a lot of these errors when when connecting to my Apple TV (with OS 7.2.2):

atvremote --debug -a playing
DEBUG: Discovering devices for 3 seconds
DEBUG: Auto-discovered service Apple TV at 10.0.10.22 (hsgid: XXXX)
INFO: Auto-discovered Apple TV at 10.0.10.22
DEBUG: GET URL: http://10.0.10.22:3689/login?hsgid=XXXX&hasFP=1
Traceback (most recent call last):
  File "/Users/postlund/tmp/pyatv/pyatv/__main__.py", line 223, in _run_application
    asyncio.wait_for((yield from cli_handler(loop)), timeout=15)
  File "/Users/postlund/tmp/pyatv/pyatv/__main__.py", line 72, in cli_handler
    return (yield from _handle_autodiscover(args, loop))
  File "/Users/postlund/tmp/pyatv/pyatv/__main__.py", line 116, in _handle_autodiscover
    yield from _handle_command(args, loop)
  File "/Users/postlund/tmp/pyatv/pyatv/__main__.py", line 151, in _handle_command
    playing_resp = yield from atv.metadata.playing()
  File "/Users/postlund/tmp/pyatv/pyatv/internal/apple_tv.py", line 225, in playing
    playstatus = yield from self.apple_tv.playstatus()
  File "/Users/postlund/tmp/pyatv/pyatv/daap.py", line 126, in get
    yield from self._assure_logged_in()
  File "/Users/postlund/tmp/pyatv/pyatv/daap.py", line 177, in _assure_logged_in
    yield from self.login()
  File "/Users/postlund/tmp/pyatv/pyatv/daap.py", line 115, in login
    resp = yield from self._do(self.session.get_data, url)
  File "/Users/postlund/tmp/pyatv/pyatv/daap.py", line 144, in _do
    resp, status = yield from action(url)
  File "/Users/postlund/tmp/pyatv/pyatv/daap.py", line 50, in get_data
    url, headers=_DMAP_HEADERS, timeout=self._timeout)
  File "/Users/postlund/tmp/pyatv/lib/python3.5/site-packages/aiohttp/client.py", line 530, in __iter__
    resp = yield from self._coro
  File "/Users/postlund/tmp/pyatv/lib/python3.5/site-packages/aiohttp/client.py", line 176, in _request
    conn = yield from self._connector.connect(req)
  File "/Users/postlund/tmp/pyatv/lib/python3.5/site-packages/async_timeout/__init__.py", line 44, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError

>>> An error occurred, full stack trace above

By looking at the traffic with wireshark, it looks like the Apple TV for some reason starts responding with ICMP Redirects. After a bunch of retries (five in my case) it fails. Not sure why it would do that. If anyone has any idea, I would appreciate some help. I can add that it usually (but not always) happens when the device is in standby. When I wake it up, it works again.

@robbiet480, have you seen this?

failed to login: 503, Unknown data: b'103'

(My apologies if this is not the correct repo to post to, I wasn't sure whether to post this on the HA repo or here so I chose here.)

I'm running Home Assistant 0.54 and I'm consistently receiving this error when my Apple TV seems to be asleep. I usually have to restart my Apple TV and home assistant while playing something on my Apple TV before restarting HA to show the proper state of my Apple TV. After doing so it works well, but when it goes idle for a while this error will start to occur. I have a Apple TV 4K running the latest tvOS.

Errors I'm receiving:

2017-10-05 01:19:00 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503
2017-10-05 01:19:10 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-10-05 01:19:10 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'

pyatv no longer installs on Raspbian

pyatv will no longer on a Raspberry Pi (Raspbian) ARM-7

distutils.errors.DistutilsError: Setup script exited with error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------
Cleaning up... Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-gzvblv_a/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-27mwr394-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-gzvblv_a/cryptography Storing debug log for failure in /root/.pip/pip.log

regards,
Makz

Latest TVOS "playing" issue

Here is output :

atvremote --address ..... --login_id ..... playing
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyatv/main.py", line 420, in _run_application
return (yield from cli_handler(loop))
File "/usr/local/lib/python3.5/dist-packages/pyatv/main.py", line 257, in cli_handler
return (yield from _handle_commands(args, loop))
File "/usr/local/lib/python3.5/dist-packages/pyatv/main.py", line 331, in _handle_commands
ret = yield from _handle_device_command(args, cmd, atv, loop)
File "/usr/local/lib/python3.5/dist-packages/pyatv/main.py", line 362, in _handle_device_command
atv.metadata, cmd, True, *cmd_args))
File "/usr/local/lib/python3.5/dist-packages/pyatv/main.py", line 392, in _exec_command
_pretty_print(value)
File "/usr/local/lib/python3.5/dist-packages/pyatv/main.py", line 410, in _pretty_print
print(data)
File "/usr/local/lib/python3.5/dist-packages/pyatv/interface.py", line 135, in str
convert.playstate_str(self.play_state)))
File "/usr/local/lib/python3.5/dist-packages/pyatv/internal/apple_tv.py", line 245, in play_state
return convert.playstate(state)
File "/usr/local/lib/python3.5/dist-packages/pyatv/convert.py", line 48, in playstate
raise exceptions.UnknownPlayState('Unknown playstate: ' + str(state))
pyatv.exceptions.UnknownPlayState: Unknown playstate: 0

An error occurred, full stack trace above

Launching tvOS apps

Does this support launching application on an AppleTV? I'm guessing it does not currently, but didn't see this said one way or the other in the README and figured I'd ask.

The use case I am thinking of is to update homeassistant's AppleTV support to expose selecting different apps as 'input', so you can do automation around launching apps. For example, make a switch "HBO" that you can control from Alexa, and it handles launching the HBO Go app.

Upgrade to aiohttp 1.3.0

Once it is released, upgrade to aiohttp 1.3.0. Currently, when running the tests some warnings like these are printed:

...
test_button_menu (tests.test_functional.FunctionalTest) ... /Users/postlund/git/pyatv/lib/python3.5/site-packages/aiohttp-1.2.0-py3.5-macosx-10.11-x86_64.egg/aiohttp/test_utils.py:212: ResourceWarning: Creating a client session outside of coroutine is a very dangerous idea
  **kwargs)
Creating a client session outside of coroutine
client_session: <aiohttp.client.ClientSession object at 0x102781080>
/Users/postlund/git/pyatv/pyatv/daap.py:37: ResourceWarning: Creating a client session outside of coroutine is a very dangerous idea
  self._session = ClientSession(loop=loop)
Creating a client session outside of coroutine
client_session: <aiohttp.client.ClientSession object at 0x102781320>
ok
...

This is fixed by using get_application instead of get_app in the test suite, according to
aio-libs/aiohttp#1499

Can't figure out the push api

I've tried your example, but I'm no experienced with python enough to know if it's missing any thing.

I've got the following:
import pyatv
import asyncio

class PushListener:

    def playstatus_update(self, updater, playstatus):
        # Currently playing in playstatus
        print(playstatus)

    @staticmethod
    def playstatus_error(updater, exception):
        # Error in exception
        updater.start(initial_delay=10)

@asyncio.coroutine
def listen_to_updates(self):
    listener = PushListener()
    self.atv.push_updater.listener = listener
    self.atv.push_updater.start()

if __name__ == "__main__":
    listen_to_updates()

which now seems to run, as without the if main it'd get a syntax error. But then it just drops out. I assume I can just put in a loop. Would I be correct in that there's not loop/timer in the push_updater, or listener code?

Incorrect Pincode

Pairing using default or customized PIN code does not seem to be possible anymore, Apple tv is claiming incorrect pincode.

tvOS 10.2.1 is used. Tested on two Apple TV devices.

Play media by specifying a URL

From what I have gathered, it should be possible to use the play command and pass a URL to the device to play it. Some inspiration can be found in these projects:

https://github.com/hellozimi/AirPlayer/blob/master/airplayer.py
https://github.com/Tomohiro/airplayer

Also the Unoffical AirPlay Protocol Specification:

https://nto.github.io/AirPlay.html#video-httprequests

I would like to add the same functionality to pyatv. Suggested API is pyatv.interface.RemoteControl.play(url).

Scan return no devices

Hey

I can ping appletv without problems but scan return no devices, what's wrong?

image

#
# ping 10.0.1.9
PING 10.0.1.9 (10.0.1.9) 56(84) bytes of data.
64 bytes from 10.0.1.9: icmp_seq=1 ttl=64 time=5.67 ms
64 bytes from 10.0.1.9: icmp_seq=2 ttl=64 time=4.44 ms
^C
--- 10.0.1.9 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 4.449/5.063/5.677/0.614 ms
# atvremote scan
Found Apple TVs:
# atvremote -t 9 scan
Found Apple TVs:
#

Realtime

So what are your thoughts on implementing playstatusupdate?

tvOS pairing/authetication protocol?

Hi - I saw you implemented the tvOS authentication protocol. I need to develop my own version for updating one of my app and I need to do that in Perl and C. Do you know if the protocol is described somewhere? I can take it from your Python implementation, but I'm really not good at reading Python.

Thanks in advance

Verify support with Apple TV 4

As I only have a gen 3 device, I have not yet verified pyatv with a gen 4 device. If you have one, please try the library out and report any issues. The atvremote is probably easiest to use, look under docs/ for some help.

Home Assistant is sending ATV commands when accessing Home Assistant UI

When accessing HA UI through web or app, HA apple_tv component is sending a http get call to all available ATV's, causing them to boot up (the bootup is known feature of atv as you've mentioned earlier). This new behaviour started after latest HA update.

debug:

2017-08-13 08:13:45 INFO (MainThread) [homeassistant.components.http] Serving /api/media_player_proxy/media_player.apple_tv_vardagsrum to 192.168.1.2 (auth: False)
2017-08-13 08:13:45 DEBUG (MainThread) [pyatv.daap] Already logged in, re-using seasion id 5
2017-08-13 08:13:45 DEBUG (MainThread) [pyatv.net] GET URL: http://192.168.1.3:3689/ctrl-int/1/nowplayingartwork?mw=1024&mh=576&session-id=5
2017-08-13 08:13:45 INFO (MainThread) [homeassistant.components.http] Serving /api/media_player_proxy/media_player.apple_tv_vardagsrum to 192.168.1.2 (auth: False)
2017-08-13 08:13:45 INFO (MainThread) [homeassistant.components.http] Serving /api/media_player_proxy/media_player.apple_tv_sovrum to 192.168.1.2 (auth: False)
2017-08-13 08:13:45 INFO (MainThread) [homeassistant.components.http] Serving /api/media_player_proxy/media_player.apple_tv_sovrum to 192.168.1.2 (auth: False)
2017-08-13 08:13:45 DEBUG (MainThread) [pyatv.daap] Already logged in, re-using seasion id 13
2017-08-13 08:13:45 DEBUG (MainThread) [pyatv.net] GET URL: http://192.168.1.7:3689/ctrl-int/1/nowplayingartwork?mw=1024&mh=576&session-id=13
2017-08-13 08:13:45 DEBUG (MainThread) [pyatv.daap] _get_request: b''
2017-08-13 08:13:45 DEBUG (MainThread) [pyatv.daap] _get_request: b''

I would guess that this could be consider more a feature than a bug. But from a user perspective having the HDMI-CEC enabled (and want to keep it that way) this is essentially making the component quite frustrating to have active, since my tv's will turn on when I don't intend to use them.

Homebridge connection [Help needed]

Hi

I have successfully installed the app on a pi and it works with two atv4. However I do not really like home assistant (slow, web interface), but I have a fully working homebridge setup. Did you tried to connect pyatv to homebridge?

Flag --debug in atvremote is ignored if -v is specified after

Example with --debug:

$ atvremote --debug scan
DEBUG: Discovering devices for 3 seconds
DEBUG: Auto-discovered service Apple TV at 10.0.10.26 (hsgid: 123)
Found Apple TVs:
 - Apple TV at 10.0.10.26 (login id: 123)

If -v is added after:

$ atvremote --debug -v scan
Found Apple TVs:
 - Apple TV at 10.0.10.26 (login id: 00000000-1125-ff3b-7f12-8518bf3e4c0e)

Before works fine:

$ atvremote -v --debug scan
DEBUG: Discovering devices for 3 seconds
DEBUG: Auto-discovered service Apple TV at 10.0.10.26 (hsgid: 123)
Found Apple TVs:
 - Apple TV at 10.0.10.26 (login id: 123)

Add basic implementation of MediaRemoteTV protocol

This is a place holder for adding protocol support for MediaRemoteTV. I have not done any work on this at all and I can give no information at this stage if or when it will be supported.

There are some documentation about it here:
https://github.com/jeanregisser/mediaremotetv-protocol
But I assume that it is no longer complete. As it uses SRP, hopefully most of the work done for device authentication can be re-used.

Some things to consider:

  • How to select which protocol to use?
  • Which additional APIs are available?
  • Testing

Trigger Sleep mode?

I don't see a way to hold keys down to trigger the Apple TV's Sleep mode — that's one thing I've been unable to get to work via IR either. Would it be possible to reverse-engineer the corresponding command for when you hold down the TV button on the Siri remote (or play/pause on older remotes)?

aTV 4 compatibility problems

Working:

  • play
  • select (when playing this will play/pause)
  • topmenu
  • menu
  • next
  • Artwork
  • Metadata

Not working:

  • pause pauses for about 10 ms and then plays again
  • previtem just goes to the next item in the playlist
  • left, right, up, down throw pyatv.exceptions.NotSupportedError

Feature request: the "TV" and "Mic" buttons.

On the 4th Gen Apple TV remotes (also called the "Siri" remote, can be seen here, there are two new buttons: the TV button which is kinda like the home button on iOS devices, and the Mic button which activates Siri. The Siri button isn't as important, as you'd need the microphone in the remote in order to do anything with it anyway. Double clicking the TV button will basically bring up a home screen where you can close or switch apps like you can in iOS; single clicking it will bring you back to the home screen (kinda like top_menu; and holding it down will bring up a little menu that allows you to put the Apple TV to sleep.

Crash when scanning for devices

(venv)pi@hassbian:~/venv $ atvremote scan
Found Apple TVs:
Traceback (most recent call last):
File "/home/pi/venv/lib/python3.4/site-packages/pyatv/main.py", line 245, in _run_application
asyncio.wait_for((yield from cli_handler(loop)), timeout=15)
File "/home/pi/venv/lib/python3.4/site-packages/pyatv/main.py", line 81, in cli_handler
yield from _handle_scan(args, loop)
File "/home/pi/venv/lib/python3.4/site-packages/pyatv/main.py", line 108, in _handle_scan
_print_found_apple_tvs(atvs)
File "/home/pi/venv/lib/python3.4/site-packages/pyatv/main.py", line 116, in _print_found_apple_tvs
outstream.writelines(msg)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe5' in position 0: ordinal not in range(128)

        An error occurred, full stack trace above

Support for python 3.6

There seems to be a bug in pylint/asteriod that causes a circle dependency:

...
  File "/home/travis/build/postlund/pyatv/.tox/lint/lib/python3.6/site-packages/astroid/rebuilder.py", line 167, in visit
    return visit_method(node, parent, assign_ctx)
  File "/home/travis/build/postlund/pyatv/.tox/lint/lib/python3.6/site-packages/astroid/rebuilder.py", line 447, in visit_expr
    newnode.value = self.visit(node.value, newnode, assign_ctx)
  File "/home/travis/build/postlund/pyatv/.tox/lint/lib/python3.6/site-packages/astroid/rebuilder.py", line 167, in visit
    return visit_method(node, parent, assign_ctx)
  File "/home/travis/build/postlund/pyatv/.tox/lint/lib/python3.6/site-packages/astroid/rebuilder.py", line 315, in visit_call
    for child in node.args]
  File "/home/travis/build/postlund/pyatv/.tox/lint/lib/python3.6/site-packages/astroid/rebuilder.py", line 315, in <listcomp>
    for child in node.args]
  File "/home/travis/build/postlund/pyatv/.tox/lint/lib/python3.6/site-packages/astroid/rebuilder.py", line 165, in visit
    visit_method = getattr(self, visit_name)
AttributeError: 'TreeRebuilder3k' object has no attribute 'visit_joinedstr'
ERROR: InvocationError: '/home/travis/build/postlund/pyatv/.tox/lint/bin/pylint pyatv'
lint runtests: commands[2] | pydocstyle pyatv tests

From what I can see in pylint-dev/pylint#1113, this will be fixed when PyLint 2.0 and asteroid 1.5 is released. So I will let PR #15 wait until that it fixed.

Option to stop scanning when a device is found

Most people only have one device so it would speed up auto discovery (atvremote -a <command>) if scanning could be canceled when a device has been found.

API suggestion: pyatv.scan_for_apple_tvs(loop, timeout=5, stop_on_found=False)

This should also be updated in pyatv.helpers.auto_connect. Also, add a test for this.

play_url start and stop any video

I tried both avi and mp4 and still get the same

DEBUG: media playback ended

bash-3.2$ atvremote --debug -a --airplay_credentials EE109CBFE1CFE549:1E88A3CC55584CFF2DE7DB4463A2C8E34F81B0FBC843275B65329FB413CA2F11  play_url=http://171.25.232.20:8080/api/v1/stream/20_FvZ3oYGWmY7HiwsJAPygB8SFOT5kxa/hls/index.m3u8,0
DEBUG: Discovering devices for 3 seconds
DEBUG: Auto-discovered service Apple TV at 192.168.1.130 (hsgid: 00000000-7552-80fc-81b6-e38bf8864aec)
DEBUG: Aborting since a device was found
INFO: Auto-discovered Apple TV at 192.168.1.130
DEBUG: Authentication keys (Private=1e88a3cc55584cff2de7db4463a2c8e34f81b0fbc843275b65329fb413ca2f11, Public=b419c8c05a7ebc6e0abffa3f6afa010fcce036a39a63d1e8efd0cdd180be9816)
DEBUG: Loaded AirPlay credentials: EE109CBFE1CFE549:1E88A3CC55584CFF2DE7DB4463A2C8E34F81B0FBC843275B65329FB413CA2F11
DEBUG: Verification keys (Private=1888a3cc55584cff2de7db4463a2c8e34f81b0fbc843275b65329fb413ca2f51, Public=3250d94ea71ac3641ec6fd919a986d318bb35e9d1e9e4d2648530ea5af8d2f57)
DEBUG: POST URL: http://192.168.1.130:7000/pair-verify
DEBUG: -> Data[68]: b'010000003250d94ea71ac3641ec6fd919a986d318bb35e9d1e9e4d2648530ea5af8d2f57b419c8c05a7ebc6e0abffa3f6afa010fcce036a39a63d1e8efd0cdd180be9816'
DEBUG: <- Data[96]: b'9721f07891310b4d4310ed4ef8f88b420a590eba278ce833870ec1ec19a9df2a70b7d2e34fc6203ae5a8a37d2ff6a29afc00e4274f5abeb0a25d9d48a3a447a066371ba896727aad3fe57714b741ac7fad67264c24ff33b6ca81bde363a7f38b'
DEBUG: Verify (PublicSecret=9721f07891310b4d4310ed4ef8f88b420a590eba278ce833870ec1ec19a9df2a, Data=70b7d2e34fc6203ae5a8a37d2ff6a29afc00e4274f5abeb0a25d9d48a3a447a066371ba896727aad3fe57714b741ac7fad67264c24ff33b6ca81bde363a7f38b)
DEBUG: Shared secret (Secret=3aa309a7fb8552e4c7b5deab015141381b22e07733148328c495e9caa0fd1d5c)
DEBUG: Pair-Verify-AES (Key=fb79c523e23e05e316a9f1a611893bd3, IV=f4e9767c31d47da1a608565ce446a0dc)
DEBUG: Signature (Signature=6a37b4847491cc309cb5165879fe058e84f3301541938c1f768cd35415a1559e804f96ef75d3280d3d8128edc1b3b0843c7d5e7e4571c33967a8d75e1fa1fd23)
DEBUG: POST URL: http://192.168.1.130:7000/pair-verify
DEBUG: -> Data[68]: b'000000006a37b4847491cc309cb5165879fe058e84f3301541938c1f768cd35415a1559e804f96ef75d3280d3d8128edc1b3b0843c7d5e7e4571c33967a8d75e1fa1fd23'
DEBUG: AirPlay 0 to http://192.168.1.130:7000/play
DEBUG: media playback ended
bash-3.2$ 

I see how the player appears on the download screen and then interrupts.

Remote control commands design

Is it voluntary to use topmenu rather than top_menu to name the remote control command? It does not match the design of set_position.

This is not really important but as it is a fresh project, there is still time to change :)

`tag_definition` `cang` for genre of currently playing media

Raspberry Pi 3b
Hassbian 1.23
HA 0.52.1

I'm seeing warnings in the HA logs like this:

WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'cang\x00\x00\x00\nSoundtrackcanl\x00\x00\x001'

A little research shows that cang clearly ties to the genre of the currently playing song. E.G. the above is from tracks on the "Tron:Legacy" album. "Tron:Legacy Reconfigured" then changes this to Unknown data: b'cang\x00\x00\x00\nElectroniccanl\x00\x00\x00\x19' which follows the album genre. Etc, etc...

I can submit a PR to add this to tag_definitions.py if someone can point me to where I can find the correct corresponding mapping value.

setup_dev_env.sh fails

I ran this command to get the new "play_media" option. Although, even when it works, not sure how I would use this vir_env to run it with Home-Assistant.io yet?

In any case, I ran the setup command with both user "pi" as well as with "sudo" up front.. same error:

-> Using python: python3.4
-> Creating python virtual environment...
Running virtualenv with interpreter /usr/bin/python3.4
Using base prefix '/usr'
New python executable in /home/pi/programming/ha_custom_comp_media_player_atv/pyatv/bin/python3.4
Not overwriting existing python script /home/pi/programming/ha_custom_comp_media_player_atv/pyatv/bin/python (you must use /home/pi/programming/ha_custom_comp_media_player_atv/pyatv/bin/python3.4)
Installing setuptools, pip, wheel...done.
-> Activating virtual environment...
-> Upgrading pip...
Requirement already up-to-date: pip in ./lib/python3.4/site-packages
-> Installing library as develop...
running develop
running egg_info
writing top-level names to pyatv.egg-info/top_level.txt
writing pyatv.egg-info/PKG-INFO
writing entry points to pyatv.egg-info/entry_points.txt
writing dependency_links to pyatv.egg-info/dependency_links.txt
reading manifest file 'pyatv.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: manifest_maker: MANIFEST.in, line 11: unknown action 'prunt'

writing manifest file 'pyatv.egg-info/SOURCES.txt'
running build_ext
Creating /home/pi/programming/ha_custom_comp_media_player_atv/pyatv/lib/python3.4/site-packages/pyatv.egg-link (link to .)
pyatv 0.0.2.dev1 is already the active version in easy-install.pth
Installing atvremote script to /home/pi/programming/ha_custom_comp_media_player_atv/pyatv/bin

Installed /home/pi/programming/ha_custom_comp_media_player_atv/pyatv
Processing dependencies for pyatv==0.0.2.dev1
Finished processing dependencies for pyatv==0.0.2.dev1
-> Installing test dependencies...
Requirement already satisfied: asynctest==0.9.0 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 1))
Requirement already satisfied: flake8>=3.0.4 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 2))
Requirement already satisfied: pylint>=1.5.6 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 3))
Requirement already satisfied: coveralls>=1.1 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 4))
Requirement already satisfied: pytest>=2.9.2 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 5))
Requirement already satisfied: pytest-cov>=2.3.1 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 6))
Requirement already satisfied: pytest-timeout>=1.0.0 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 7))
Requirement already satisfied: pytest-aiohttp==0.1.3 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 8))
Requirement already satisfied: pydocstyle>=1.0.0 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 9))
Requirement already satisfied: mypy-lang>=0.4 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 10))
Requirement already satisfied: Sphinx==1.5.1 in ./lib/python3.4/site-packages (from -r requirements_test.txt (line 11))
Requirement already satisfied: pycodestyle<2.4.0,>=2.0.0 in ./lib/python3.4/site-packages (from flake8>=3.0.4->-r requirements_test.txt (line 2))
Requirement already satisfied: pyflakes<1.6.0,>=1.5.0 in ./lib/python3.4/site-packages (from flake8>=3.0.4->-r requirements_test.txt (line 2))
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in ./lib/python3.4/site-packages (from flake8>=3.0.4->-r requirements_test.txt (line 2))
Requirement already satisfied: six in ./lib/python3.4/site-packages (from pylint>=1.5.6->-r requirements_test.txt (line 3))
Requirement already satisfied: astroid<1.5.0,>=1.4.5 in ./lib/python3.4/site-packages (from pylint>=1.5.6->-r requirements_test.txt (line 3))
Requirement already satisfied: isort>=4.2.5 in ./lib/python3.4/site-packages (from pylint>=1.5.6->-r requirements_test.txt (line 3))
Requirement already satisfied: requests>=1.0.0 in ./lib/python3.4/site-packages (from coveralls>=1.1->-r requirements_test.txt (line 4))
Requirement already satisfied: docopt>=0.6.1 in ./lib/python3.4/site-packages (from coveralls>=1.1->-r requirements_test.txt (line 4))
Requirement already satisfied: coverage>=3.6 in ./lib/python3.4/site-packages (from coveralls>=1.1->-r requirements_test.txt (line 4))
Requirement already satisfied: setuptools in ./lib/python3.4/site-packages (from pytest>=2.9.2->-r requirements_test.txt (line 5))
Requirement already satisfied: py>=1.4.29 in ./lib/python3.4/site-packages (from pytest>=2.9.2->-r requirements_test.txt (line 5))
Requirement already satisfied: aiohttp>=0.22.0 in ./lib/python3.4/site-packages (from pytest-aiohttp==0.1.3->-r requirements_test.txt (line 8))
Requirement already satisfied: docutils>=0.11 in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: Jinja2>=2.3 in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: babel!=2.0,>=1.3 in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: imagesize in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: Pygments>=2.0 in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: alabaster<0.8,>=0.7 in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: snowballstemmer>=1.1 in ./lib/python3.4/site-packages (from Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: lazy-object-proxy in ./lib/python3.4/site-packages (from astroid<1.5.0,>=1.4.5->pylint>=1.5.6->-r requirements_test.txt (line 3))
Requirement already satisfied: wrapt in ./lib/python3.4/site-packages (from astroid<1.5.0,>=1.4.5->pylint>=1.5.6->-r requirements_test.txt (line 3))
Requirement already satisfied: packaging>=16.8 in ./lib/python3.4/site-packages (from setuptools->pytest>=2.9.2->-r requirements_test.txt (line 5))
Requirement already satisfied: appdirs>=1.4.0 in ./lib/python3.4/site-packages (from setuptools->pytest>=2.9.2->-r requirements_test.txt (line 5))
Requirement already satisfied: multidict>=2.1.4 in ./lib/python3.4/site-packages (from aiohttp>=0.22.0->pytest-aiohttp==0.1.3->-r requirements_test.txt (line 8))
Requirement already satisfied: yarl>=0.8.1 in ./lib/python3.4/site-packages (from aiohttp>=0.22.0->pytest-aiohttp==0.1.3->-r requirements_test.txt (line 8))
Requirement already satisfied: async-timeout>=1.1.0 in ./lib/python3.4/site-packages (from aiohttp>=0.22.0->pytest-aiohttp==0.1.3->-r requirements_test.txt (line 8))
Requirement already satisfied: chardet in ./lib/python3.4/site-packages (from aiohttp>=0.22.0->pytest-aiohttp==0.1.3->-r requirements_test.txt (line 8))
Requirement already satisfied: MarkupSafe>=0.23 in ./lib/python3.4/site-packages (from Jinja2>=2.3->Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: pytz>=0a in ./lib/python3.4/site-packages (from babel!=2.0,>=1.3->Sphinx==1.5.1->-r requirements_test.txt (line 11))
Requirement already satisfied: pyparsing in ./lib/python3.4/site-packages (from packaging>=16.8->setuptools->pytest>=2.9.2->-r requirements_test.txt (line 5))
Requirement already satisfied: tox in ./lib/python3.4/site-packages
Requirement already satisfied: virtualenv>=1.11.2; python_version != "3.2" in ./lib/python3.4/site-packages (from tox)
Requirement already satisfied: pluggy<1.0,>=0.3.0 in ./lib/python3.4/site-packages (from tox)
Requirement already satisfied: py>=1.4.17 in ./lib/python3.4/site-packages (from tox)
-> Running tests as verification...
running test
running egg_info
writing top-level names to pyatv.egg-info/top_level.txt
writing pyatv.egg-info/PKG-INFO
writing dependency_links to pyatv.egg-info/dependency_links.txt
writing entry points to pyatv.egg-info/entry_points.txt
reading manifest file 'pyatv.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: manifest_maker: MANIFEST.in, line 11: unknown action 'prunt'

writing manifest file 'pyatv.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 34, in
'Topic :: Home Automation',
File "/usr/lib/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/pi/programming/ha_custom_comp_media_player_atv/pyatv/lib/python3.4/site-packages/setuptools/command/test.py", line 211, in run
self.run_tests()
File "/home/pi/programming/ha_custom_comp_media_player_atv/pyatv/lib/python3.4/site-packages/setuptools/command/test.py", line 234, in run_tests
**exit_kwarg
File "/usr/lib/python3.4/unittest/main.py", line 92, in init
self.parseArgs(argv)
File "/usr/lib/python3.4/unittest/main.py", line 139, in parseArgs
self.createTests()
File "/usr/lib/python3.4/unittest/main.py", line 146, in createTests
self.module)
File "/usr/lib/python3.4/unittest/loader.py", line 146, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python3.4/unittest/loader.py", line 146, in
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python3.4/unittest/loader.py", line 117, in loadTestsFromName
return self.loadTestsFromModule(obj)
File "/home/pi/programming/ha_custom_comp_media_player_atv/pyatv/lib/python3.4/site-packages/setuptools/command/test.py", line 43, in loadTestsFromModule
tests.append(self.loadTestsFromName(submodule))
File "/usr/lib/python3.4/unittest/loader.py", line 114, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_interface'

concurrent.futures._base.TimeoutError after 2 push_updates

% atvremote --login_id 0x0000000000000001 --address bedroom.local push_updates
Press ENTER to stop
Media type: Music
Play state: Playing
     Title: Aaron Severson of AteUpWithMotor.com
    Artist: Petersen Automotive Museum
     Album: CarStories
  Position: 378/3003s (12.6%)
    Repeat: Off
   Shuffle: False
--------------------
Media type: Music
Play state: Playing
     Title: Aaron Severson of AteUpWithMotor.com
    Artist: Petersen Automotive Museum
     Album: CarStories
  Position: 382/3004s (12.7%)
    Repeat: Off
   Shuffle: False
--------------------
Traceback (most recent call last):
  File "/Users/nicholas/Documents/Development/pyatv/src/pyatv/pyatv/__main__.py", line 306, in _run_application
    return (yield from asyncio.wait_for(cli_handler(loop), timeout=15))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 356, in wait_for
    raise futures.TimeoutError()
concurrent.futures._base.TimeoutError

This happened after the 1st update on Python 3.5; I upgraded to Python 3.6 and it now gets 2 updates before no longer working. This is a 3rd gen Apple TV to which I am sending AirPlay audio (there's actually nothing plugged into the HDMI port) if that is of any importance.

Upgrade and pin test requirements

Latest version of pypi discovers new issues. I want to pin important test packages and fix new issues, this issue will act as a task for that.

Arrow keys for Apple TV 4

Based on my testing, the protocol differs for how arrow keys are handled. From the looks of it, the reverse engineered keys are based on the touch interface of ATV4. We can see that here:

  'up': [
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1DtouchDown&time=0&point=20,275",
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1DtouchMove&time=1&point=20,270",
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1DtouchMove&time=2&point=20,265",
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1DtouchMove&time=3&point=20,260",
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1DtouchMove&time=4&point=20,255",
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1DtouchMove&time=5&point=20,250",
    "cmcc\x00\x00\x00\x01\x30cmbe\x00\x00\x00\x1BtouchUp&time=6&point=20,250"
  ],

It's basically a bunch of new DAAP/DMAP data (cmcc, cmbe). Should be easy enough to implement but this means that the implementation will differ for ATV4 and pre-ATV4 devices. Since I don't want to mix code between them, two implementations will have to be made (some subclassing and re-use in pyatv.internal). Tests will also have to be split, e.g, rename test_functional.py to base_function.py and create two subclasses: one for ATV4 and one for ATV3. Tests for arrow keys shall be added in the ATV4 suite. Have to think about naming.

Finding Apple TVs without Home Sharing enabled

Thanks to a bit of panic from me and @dale3h we determined that an Apple TV without Home Sharing enabled will broadcast the touch-able._tcp.local. service but NOT the _appletv-v2._tcp.local. service. We should check to see if we don't have a corresponding _appletv-v2._tcp.local. service and if so alert the user that they need to enable Home Sharing.

support for long key press

Would it be possible to code in support for long key presses? eg long press "top_menu" would bring up the shutdown options on ATV4. Thank you, project is awesome!

Add missing playstate "0"

With tvOS 11, it seems like playstate "0" is used. Not sure what it represents, but it needs to be added because it causes exceptions:

2017-09-20 14:10:29 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.6/asyncio/tasks.py”, line 179, in _step
result = coro.send(None)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 239, in async_update_ha_state
state = self.state
File “/usr/lib/python3.6/site-packages/homeassistant/components/media_player/apple_tv.py”, line 98, in state
state = self._playing.play_state
File “/usr/lib/python3.6/site-packages/pyatv/internal/apple_tv.py”, line 245, in play_state
return convert.playstate(state)
File “/usr/lib/python3.6/site-packages/pyatv/convert.py”, line 48, in playstate
raise exceptions.UnknownPlayState('Unknown playstate: ’ + str(state))
pyatv.exceptions.UnknownPlayState: Unknown playstate: 0

Better output for "playing" command in atvremote

Output currently looks like this:

atvremote -a playing
album: None
artist: None
media_type: 3
play_state: 4
position: -4291240
title: Some program
total_time: 0

Empty fields should be ignore. Fields media_type and play_state should also have an explanatory string.

play_url airplay crash

Hi Postlund,

when atvremote --debug -a play_url=MP3LSTREAMURL,0 it crashed after approximately one minute and prints out the following.

Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/pyatv/main.py", line 290, in _run_application
asyncio.wait_for((yield from cli_handler(loop)), timeout=15)
File "/usr/local/lib/python3.4/dist-packages/pyatv/main.py", line 105, in cli_handler
return (yield from _handle_autodiscover(args, loop))
File "/usr/local/lib/python3.4/dist-packages/pyatv/main.py", line 171, in _handle_autodiscover
yield from _handle_command(args, loop)
File "/usr/local/lib/python3.4/dist-packages/pyatv/main.py", line 238, in _handle_command
yield from _exec_command(atv.remote_control, cmd, *cmd_args)
File "/usr/local/lib/python3.4/dist-packages/pyatv/main.py", line 261, in _exec_command
value = yield from tmp(*args)
File "/usr/local/lib/python3.4/dist-packages/pyatv/airplay.py", line 42, in play_url
yield from self._wait_for_media_to_end(port)
File "/usr/local/lib/python3.4/dist-packages/pyatv/airplay.py", line 62, in _wait_for_media_to_end
parsed = plistlib.loads(data)
File "/usr/lib/python3.4/plistlib.py", line 1006, in loads
fp, fmt=fmt, use_builtin_types=use_builtin_types, dict_type=dict_type)
File "/usr/lib/python3.4/plistlib.py", line 991, in load
raise InvalidFileException()
plistlib.InvalidFileException: Invalid file

Any idéas what might be the issue? Running on a rp3 with hassbian.

Thanks!

D

Support for tvOS?

Anyone using this with tvos? I can't get it to pair or do anything. Pairing shows the remote in the ATV interface but when I try to pair it just says incorrect password. I rebooted it. Same thing.

# atvremote --address x.x.x.x --login_id 00000000-1043-09d4-1407-fe8d613a4bf3 pause
... This yields a blank line result.

Command of up yields CRITICAL: Command 'up' is not supported by device

I made sure home sharing is enabled as well.

The only thing that did work for me was # atvremote scan

Also the docs say something about an option --hsgid but that doesn't seem to exist.

Unknown media kind TV show

The media kind "TV Show" is not recognized correctly.
pyatv.exceptions.UnknownMediaKind: Unknown media kind: 64

Support for streaming local files via AirPlay

I started this work a while back and I think I have a branch for it somewhere. Basically setup a local web server serving the file and pass URL to the Apple TV. Should be simple enough.

Devices not showing up during a scan

This library relies on Bonjour/zeroconf for service discovery. If that doesn't work, a scan will not show anything. From my past endeavours when troubleshooting this on Linux, I know that lots of things can go wrong and some users see this issue. So, we need to work systematically to figure out why it works for some and not for others.

An initial test is to just scan for all services and see if anything shows up. If it's empty, then something is really broken. A simple test is to install python-zeroconf in a venv and run this from a python interpreter (python3):

from zeroconf import ZeroconfServiceTypes
ZeroconfServiceTypes.find(timeout=10)

It will scan for ten seconds and show available services, like in my case:

('_acp-sync._tcp.local.', '_airplay._tcp.local.', '_airport._tcp.local.', '_apple-mobdev2._tcp.local.', '_appletv-v2._tcp.local.', '_canon-bjnp1._tcp.local.', '_hap._tcp.local.', '_home-assistant._tcp.local.', '_homekit._tcp.local.', '_http._tcp.local.', '_ipp._tcp.local.', '_ipps._tcp.local.', '_printer._tcp.local.', '_privet._tcp.local.', '_raop._tcp.local.', '_scanner._tcp.local.', '_sleep-proxy._udp.local.', '_smb._tcp.local.', '_sub._apple-mobdev2._tcp.local.', '_touch-able._tcp.local.', '_udisks-ssh._tcp.local.', '_uscan._tcp.local.', '_workstation._tcp.local.')

So if someone with scanning issues could try this, it would help a lot.

Pairing

I tried to throw together a pairing functionality tonight but still haven't figured my way out around asyncio. The guide at the top of this page worked perfectly for me to pair my Apple TV gen 4 though, so shouldn't be too hard to implement!

Used this on my Mac to get a ZeroConf service registered: dns-sd -R pyATV _touch-remote._tcp local 3689 DvNm=pyATV RemV=10000 DvTy=computer RemN=Remote txtvers=1 Pair=0000000000000001

Automatic re-login if logged out from device

How to reproduct:

  • Login with one client and keep the session alive
  • Login with another client and perform a command (or login)
  • Issue a new command in the first client

Actual:
In my case I kept Home Assistant running with the Apple TV while issuing atvremote -a --developer dev_playstatus:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/Users/postlund/git/home-assistant/homeassistant/helpers/entity.py", line 200, in async_update_ha_state
    yield from self.async_update()
  File "/Users/postlund/git/home-assistant/homeassistant/components/media_player/apple_tv.py", line 100, in async_update
    playing = yield from self._atv.metadata.playing()
  File "/Users/postlund/git/home-assistant/virtualenv/lib/python3.5/site-packages/pyatv/internal/apple_tv.py", line 225, in playing
    playstatus = yield from self.apple_tv.playstatus()
  File "/Users/postlund/git/home-assistant/virtualenv/lib/python3.5/site-packages/pyatv/daap.py", line 128, in get
    is_daap=daap_data))
  File "/Users/postlund/git/home-assistant/virtualenv/lib/python3.5/site-packages/pyatv/daap.py", line 151, in _do
    action, url, False, is_login=is_login, is_daap=is_daap))
  File "/Users/postlund/git/home-assistant/virtualenv/lib/python3.5/site-packages/pyatv/daap.py", line 154, in _do
    'failed to login: ' + str(status))
pyatv.exceptions.AuthenticationError: failed to login: 403

Expected:
A re-login should be triggered and command should succeed without user noticing.

Idle state on Apple TV 4

Hey there,

I did some more digging regarding home-assistant/core#6293 (card flickering because image cannot be found). I saw that you utilize pyatv.const.PLAY_STATE_NO_MEDIA to tell HASS that the Apple TV is idle - however on my Apple TV 4 it actually never goes to this state. This is the state when nothing is playing (home menu):

state: paused
media_title: No title
media_duration: 0
entity_picture: /api/media_player_proxy/media_player.apple_tv?token=token&cache=cache
supported_features: 21427
media_position: 0
media_content_type: movie
media_position_updated_at: 2017-03-26T12:39:33.996764+00:00
hidden: true
friendly_name: Apple TV

This state causes HASS to think that there is artwork available (the artwork of the 'paused movie No Title'), causing the card to flicker while it tries to update and fails.

I think that this is something that can be fixed from this underlying library, however I am not quite sure where to start here. I haven't quite understood all of the inner workings of this library, so please correct me if I'm wrong!

Unpin requirements

It can cause issues downstream if libraries pin their requirements. It means that for users of your library (in this case Home Assistant) to upgrade to a new version of pyatv, we also need to match the aiohttp requirement to avoid conflicts.

If you don't depend on specific features in libs, may I suggest that you try to match your requirements as low as possible.

Connecting triggers devices to turn on

First, thanks for this and the home-assistant integration, it's awesome.

The issue I have is on restart of home-assistant it triggers the TV (in my case a projector) to come on. In case it was just a home-assistant issue I tested with the auto_connect.py example which causes the same thing.

This is a pretty big caveat since at least in my case turning on the ATV triggers some other automation and I don't want to sacrifice being able to having everything come on by just hitting the ATV remote.

Is there a way in the protocol to detect if the ATV is in sleep?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.