Skip to content

Commit

Permalink
v0.2.0 (#1)
Browse files Browse the repository at this point in the history
* Add request timeout and catch Timeout exception

* Update README.md
  • Loading branch information
marthoc authored Dec 11, 2018
1 parent 3235c59 commit 81ebbbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pykuna's main class is KunaAPI. Create an API object, and authenticate it, like
import pykuna

kuna = pykuna.KunaAPI(USERNAME, PASSWORD)
kuna.authenticate()
```

Where:
Expand All @@ -29,9 +30,9 @@ kuna.update()

## Methods

The following methods are available on a camera device object returned by `get_cameras()`:
The following methods are available on a camera device object in the KunaAPI.cameras list:

- `update()` - refresh device properties from the API.
- `update()` - refresh only that camera's properties from the API.
- `get_thumbnail()` - returns a camera snapshot as a jpeg image.
- `set_property(property=state)` - sets a property of the device. Properties currently settable via pykuna are:
- `bulb_on` (boolean) - set the lightbulb on (true) or off (false)
Expand All @@ -57,8 +58,6 @@ pykuna is synchronous.

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 implements no request timeouts.

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

## Contributing
Expand Down
6 changes: 4 additions & 2 deletions pykuna/kuna.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def update(self):
def _request(self, method, path, json=None, thumbnail=False):
"""Make an API request"""
import requests
from requests.exceptions import HTTPError
from requests.exceptions import HTTPError, Timeout

url = '{}/{}/'.format(API_URL, path)
headers = {
Expand All @@ -74,7 +74,7 @@ def _request(self, method, path, json=None, thumbnail=False):
headers['User-Agent'] = USER_AGENT_THUMBNAIL

try:
result = req(url, headers=headers, json=json)
result = req(url, headers=headers, json=json, timeout=3)
result.raise_for_status()

if thumbnail:
Expand All @@ -85,3 +85,5 @@ def _request(self, method, path, json=None, thumbnail=False):
except HTTPError as err:
if err.response.status_code == 401:
raise UnauthorizedError('Kuna Auth Token invalid or stale?')
except Timeout:
_LOGGER.error('Request to Kuna API timed out.')

0 comments on commit 81ebbbb

Please sign in to comment.