Skip to content

Commit f5bf02f

Browse files
authored
v0.6.0 (#7)
* Remove timeout code Remove timeout code from pykuna and leave to be implemented by client code. * Replace camera dict after sucessful request * Bump version to 0.6.0
1 parent b2407de commit f5bf02f

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ python example.py USERNAME PASSWORD
6161

6262
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!
6363

64+
pykuna does not implement timeouts; use asyncio_timeout in your client code to wrap calls to the API as needed.
65+
6466
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.
6567

6668
pykuna will hit v1.0.0 when it's ready for Home Assistant. Until then, pykuna's API may change at any time!

pykuna/kuna.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ async def update(self):
4747
"""Refresh the dict of all cameras in the Kuna account."""
4848
result = await self._request("get", CAMERAS_ENDPOINT)
4949

50-
for item in result["results"]:
51-
self.cameras[item["serial_number"]] = KunaCamera(item, self._request)
50+
if result is not None:
51+
new_cameras = {}
52+
53+
for item in result["results"]:
54+
new_cameras[item["serial_number"]] = KunaCamera(item, self._request)
55+
56+
self.cameras = new_cameras
5257

5358
async def _request(
5459
self, method, path, params=None, json=None, image=False, allow_redirects=True
5560
):
5661
"""Make an async API request."""
5762
from aiohttp import ClientResponseError
58-
from async_timeout import timeout
59-
from asyncio import TimeoutError
6063

6164
url = "{}/{}/".format(API_URL, path)
6265
headers = {"User-Agent": USER_AGENT, "Content-Type": "application/json"}
@@ -68,29 +71,25 @@ async def _request(
6871
headers["User-Agent"] = USER_AGENT_THUMBNAIL
6972

7073
try:
71-
async with timeout(3):
72-
async with self._websession.request(
73-
method,
74-
url,
75-
params=params,
76-
json=json,
77-
headers=headers,
78-
allow_redirects=allow_redirects,
79-
) as result:
80-
81-
result.raise_for_status()
82-
if image:
83-
return await result.read()
84-
elif not allow_redirects:
85-
return result
86-
else:
87-
return await result.json()
74+
async with self._websession.request(
75+
method,
76+
url,
77+
params=params,
78+
json=json,
79+
headers=headers,
80+
allow_redirects=allow_redirects,
81+
) as result:
82+
83+
result.raise_for_status()
84+
if image:
85+
return await result.read()
86+
elif not allow_redirects:
87+
return result
88+
else:
89+
return await result.json()
8890

8991
except ClientResponseError as err:
9092
if result.status == 403:
9193
raise UnauthorizedError("Kuna token empty or expired")
9294
else:
9395
_LOGGER.error("Kuna API request error: {}".format(err))
94-
95-
except TimeoutError:
96-
_LOGGER.error("Request to Kuna API timed out")

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
setuptools.setup(
66
name="pykuna",
7-
version="0.5.1",
7+
version="0.6.0",
88
author="Mark Coombes",
99
author_email="mark@markcoombes.ca",
10-
description="Python3 library for interacting with the Kuna camera mobile API",
10+
description="Python3 async library for interacting with the Kuna camera mobile API",
1111
long_description=long_description,
1212
long_description_content_type="text/markdown",
1313
url="https://github.com/marthoc/pykuna",

0 commit comments

Comments
 (0)