diff --git a/README.md b/README.md index c3d88ec..aa9bea5 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ python example.py USERNAME PASSWORD pykuna interacts with Kuna's (private) mobile device API, which could change at any time. And, without official documentation or terms of service, there's no way to know what type or rate of usage may result in your account being banned by Kuna. Use carefully! +pykuna does not implement timeouts; use asyncio_timeout in your client code to wrap calls to the API as needed. + pykuna was inspired by the investigative work of @loghound: https://github.com/loghound/kuna-camera-api, but does not yet implement all known endpoints; this project is primarily intended to interface Home Assistant with the Kuna API, and will be further developed with that goal in mind. pykuna will hit v1.0.0 when it's ready for Home Assistant. Until then, pykuna's API may change at any time! diff --git a/pykuna/kuna.py b/pykuna/kuna.py index b6f4ed5..e804a4e 100644 --- a/pykuna/kuna.py +++ b/pykuna/kuna.py @@ -47,16 +47,19 @@ async def update(self): """Refresh the dict of all cameras in the Kuna account.""" result = await self._request("get", CAMERAS_ENDPOINT) - for item in result["results"]: - self.cameras[item["serial_number"]] = KunaCamera(item, self._request) + if result is not None: + new_cameras = {} + + for item in result["results"]: + new_cameras[item["serial_number"]] = KunaCamera(item, self._request) + + self.cameras = new_cameras async def _request( self, method, path, params=None, json=None, image=False, allow_redirects=True ): """Make an async API request.""" from aiohttp import ClientResponseError - from async_timeout import timeout - from asyncio import TimeoutError url = "{}/{}/".format(API_URL, path) headers = {"User-Agent": USER_AGENT, "Content-Type": "application/json"} @@ -68,29 +71,25 @@ async def _request( headers["User-Agent"] = USER_AGENT_THUMBNAIL try: - async with timeout(3): - async with self._websession.request( - method, - url, - params=params, - json=json, - headers=headers, - allow_redirects=allow_redirects, - ) as result: - - result.raise_for_status() - if image: - return await result.read() - elif not allow_redirects: - return result - else: - return await result.json() + async with self._websession.request( + method, + url, + params=params, + json=json, + headers=headers, + allow_redirects=allow_redirects, + ) as result: + + result.raise_for_status() + if image: + return await result.read() + elif not allow_redirects: + return result + else: + return await result.json() except ClientResponseError as err: if result.status == 403: raise UnauthorizedError("Kuna token empty or expired") else: _LOGGER.error("Kuna API request error: {}".format(err)) - - except TimeoutError: - _LOGGER.error("Request to Kuna API timed out") diff --git a/setup.py b/setup.py index 4818572..a50f1e5 100644 --- a/setup.py +++ b/setup.py @@ -4,10 +4,10 @@ setuptools.setup( name="pykuna", - version="0.5.1", + version="0.6.0", author="Mark Coombes", author_email="mark@markcoombes.ca", - description="Python3 library for interacting with the Kuna camera mobile API", + description="Python3 async library for interacting with the Kuna camera mobile API", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/marthoc/pykuna",