Skip to content

Commit

Permalink
Deprecate python 3.4
Browse files Browse the repository at this point in the history
From now on python 3.5.3 is needed. Documentation is not updated yet,
I will make a big overhaul later.
  • Loading branch information
postlund committed Feb 22, 2018
1 parent ad01ee5 commit 2e12f3b
Show file tree
Hide file tree
Showing 37 changed files with 403 additions and 543 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ htmlcov
artwork.png
.Python
.pytest_cache
.mypy_cache
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ sudo: false
matrix:
fast_finish: true
include:
- python: "3.4.2"
env: TOXENV=py34
- python: "3.4.2"
env: TOXENV=lint
- python: "3.5"
env: TOXENV=py35
- python: "3.5"
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Features
Requirements
------------

- python>=3.4.2
- python>=3.5.3
- See documentation for additional libraries

Getting started
Expand Down
6 changes: 2 additions & 4 deletions examples/auto_connect.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""Simple example that connects to a device with autodiscover."""

import asyncio
from pyatv import helpers


# Method that is dispatched by the asyncio event loop
@asyncio.coroutine
def print_what_is_playing(atv):
async def print_what_is_playing(atv):
"""Print what is playing for the discovered device."""
playing = yield from atv.metadata.playing()
playing = await atv.metadata.playing()
print('Currently playing:')
print(playing)

Expand Down
9 changes: 4 additions & 5 deletions examples/autodiscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@


# Method that is dispatched by the asyncio event loop
@asyncio.coroutine
def print_what_is_playing(loop):
async def print_what_is_playing(loop):
"""Find a device and print what is playing."""
print('Discovering devices on network...')
atvs = yield from pyatv.scan_for_apple_tvs(loop, timeout=5)
atvs = await pyatv.scan_for_apple_tvs(loop, timeout=5)

if not atvs:
print('no device found', file=sys.stderr)
Expand All @@ -22,12 +21,12 @@ def print_what_is_playing(loop):
atv = pyatv.connect_to_apple_tv(atvs[0], loop)

try:
playing = yield from atv.metadata.playing()
playing = await atv.metadata.playing()
print('Currently playing:')
print(playing)
finally:
# Do not forget to logout
yield from atv.logout()
await atv.logout()


if __name__ == '__main__':
Expand Down
12 changes: 5 additions & 7 deletions examples/device_auth.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
"""Example for device authentication."""

import sys
import asyncio
from pyatv import (exceptions, helpers)


@asyncio.coroutine
def authenticate_with_device(atv):
async def authenticate_with_device(atv):
"""Perform device authentication and print credentials."""
credentials = yield from atv.airplay.generate_credentials()
yield from atv.airplay.load_credentials(credentials)
credentials = await atv.airplay.generate_credentials()
await atv.airplay.load_credentials(credentials)

try:
yield from atv.airplay.start_authentication()
await atv.airplay.start_authentication()
pin = input('PIN Code: ')
yield from atv.airplay.finish_authentication(pin)
await atv.airplay.finish_authentication(pin)
print('Credentials: {0}'.format(credentials))

except exceptions.DeviceAuthenticationError:
Expand Down
7 changes: 3 additions & 4 deletions examples/manual_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@


# Method that is dispatched by the asyncio event loop
@asyncio.coroutine
def print_what_is_playing(loop):
async def print_what_is_playing(loop):
"""Connect to device and print what is playing."""
details = conf.AppleTV(ADDRESS, NAME)
details.add_service(conf.DmapService(HSGID))
Expand All @@ -23,10 +22,10 @@ def print_what_is_playing(loop):
atv = pyatv.connect_to_apple_tv(details, loop)

try:
print((yield from atv.metadata.playing()))
print((await atv.metadata.playing()))
finally:
# Do not forget to logout
yield from atv.logout()
await atv.logout()


if __name__ == '__main__':
Expand Down
11 changes: 5 additions & 6 deletions examples/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@


# Method that is dispatched by the asyncio event loop
@asyncio.coroutine
def pair_with_device(loop):
async def pair_with_device(loop):
"""Make it possible to pair with device."""
my_zeroconf = Zeroconf()
details = conf.AppleTV('127.0.0.1', 'Apple TV')
details.add_service(conf.DmapService('login_id'))
atv = pyatv.connect_to_apple_tv(details, loop)

yield from atv.pairing.start(
await atv.pairing.start(
zeroconf=my_zeroconf, name=REMOTE_NAME, pin=PIN_CODE)
print('You can now pair with pyatv')

# Wait for a minute to allow pairing
yield from asyncio.sleep(60, loop=loop)
await asyncio.sleep(60, loop=loop)

yield from atv.pairing.stop()
await atv.pairing.stop()

# Give some feedback about the process
if atv.pairing.has_paired:
pairing_guid = yield from atv.pairing.get('pairing_gui')
pairing_guid = await atv.pairing.get('pairing_gui')
print('Paired with device!')
print('Pairing guid: ' + pairing_guid)
else:
Expand Down
1 change: 1 addition & 0 deletions fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sed -r ':a;N;$!ba;s/ *asyncio.coroutine\n( *)def/\1async def/g;s/yield from/await/g'
8 changes: 4 additions & 4 deletions pyatv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def _should_abort(self, address):


# pylint: disable=too-many-arguments
@asyncio.coroutine
def scan_for_apple_tvs(loop, timeout=5, abort_on_found=False,
device_ip=None, only_usable=True, protocol=None):
async def scan_for_apple_tvs(loop, timeout=5, abort_on_found=False,
device_ip=None, only_usable=True,
protocol=None):
"""Scan for Apple TVs using zeroconf (bonjour) and returns them."""
semaphore = asyncio.Semaphore(value=0, loop=loop)
listener = _ServiceListener(
Expand All @@ -147,7 +147,7 @@ def scan_for_apple_tvs(loop, timeout=5, abort_on_found=False,
ServiceBrowser(zeroconf, MEDIAREMOTE_SERVICE, listener)
ServiceBrowser(zeroconf, AIRPLAY_SERVICE, listener)
_LOGGER.debug('Discovering devices for %d seconds', timeout)
yield from asyncio.wait_for(semaphore.acquire(), timeout, loop=loop)
await asyncio.wait_for(semaphore.acquire(), timeout, loop=loop)
except concurrent.futures.TimeoutError:
pass # Will happen when timeout occurs (totally normal)
finally:
Expand Down
Loading

0 comments on commit 2e12f3b

Please sign in to comment.