diff --git a/.travis.yml b/.travis.yml index 3963549..cf58dad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,13 @@ sudo: false matrix: fast_finish: true include: - - python: "3.4" - env: TOXENV=lint - python: "3.5" env: TOXENV=lint + - python: "3.6" + env: TOXENV=lint + - python: "3.7" + env: TOXENV=lint + dist: xenial install: pip install -U tox language: python script: tox diff --git a/pydroid_ipcam.py b/pydroid_ipcam.py index 04ad691..3fbd3ca 100644 --- a/pydroid_ipcam.py +++ b/pydroid_ipcam.py @@ -3,8 +3,7 @@ import logging import aiohttp -import async_timeout -import yarl +from yarl import URL _LOGGER = logging.getLogger(__name__) @@ -13,7 +12,7 @@ ] -class PyDroidIPCam(object): +class PyDroidIPCam: """The Android device running IP Webcam.""" def __init__(self, loop, websession, host, port, username=None, @@ -52,21 +51,18 @@ def available(self): """Return True if is available.""" return self._available - @asyncio.coroutine - def _request(self, path): + async def _request(self, path): """Make the actual request and return the parsed response.""" url = '{}{}'.format(self.base_url, path) data = None try: - with async_timeout.timeout(self._timeout, loop=self.loop): - response = yield from self.websession.get(url, auth=self._auth) - + async with self.websession.get(url, auth=self._auth, timeout=self._timeout) as response: if response.status == 200: if response.headers['content-type'] == 'application/json': - data = yield from response.json() + data = await response.json() else: - data = yield from response.text() + data = await response.text() except (asyncio.TimeoutError, aiohttp.ClientError) as error: _LOGGER.error('Failed to communicate with IP Webcam: %s', error) @@ -76,18 +72,16 @@ def _request(self, path): self._available = True if isinstance(data, str): return data.find("Ok") != -1 - else: - return data + return data - @asyncio.coroutine - def update(self): + async def update(self): """Fetch the latest data from IP Webcam.""" - status_data = yield from self._request('/status.json?show_avail=1') + status_data = await self._request('/status.json?show_avail=1') if status_data: self.status_data = status_data - sensor_data = yield from self._request('/sensors.json') + sensor_data = await self._request('/sensors.json') if sensor_data: self.sensor_data = sensor_data @@ -104,7 +98,7 @@ def current_settings(self): except ValueError: val = val - if val == 'on' or val == 'off': + if val in ('on', 'off'): val = (val == 'on') settings[key] = val @@ -140,7 +134,7 @@ def available_settings(self): except ValueError: subval = subval - if subval == 'on' or subval == 'off': + if val in ('on', 'off'): subval = (subval == 'on') available[key].append(subval) @@ -196,7 +190,7 @@ def record(self, record=True, tag=None): """ path = '/startvideo?force=1' if record else '/stopvideo?force=1' if record and tag is not None: - path = '/startvideo?force=1&tag={}'.format(yarl.quote(tag)) + path = '/startvideo?force=1&tag={}'.format(URL(tag).raw_path) return self._request(path) @@ -234,7 +228,7 @@ def set_quality(self, quality=100): Return a coroutine. """ return self.change_setting('quality', quality) - + def set_motion_detect(self, activate=True): """Set motion detection on/off. Return a coroutine. diff --git a/setup.py b/setup.py index c9fe4be..370a16c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ with open('README.rst') as f: long_description = f.read() -VERSION = "0.8" +VERSION = "0.9" setup( name='pydroid-ipcam', @@ -23,16 +23,15 @@ 'Operating System :: OS Independent', 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ], keywords=['android', 'ipcam', 'api', 'asyncio'], zip_safe=False, platforms='any', py_modules=['pydroid_ipcam'], install_requires=[ - 'async_timeout', 'aiohttp', 'yarl', ], diff --git a/tox.ini b/tox.ini index ead82c8..c782d89 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,5 @@ basepython = python3 ignore_errors = True deps = pylint - flake8 commands = - flake8 pydroid_ipcam.py pylint pydroid_ipcam.py