Skip to content

Commit e872fc9

Browse files
authored
Merge pull request #105 from fronzbot/dev
0.10.1
2 parents 4e6957a + 5196147 commit e872fc9

File tree

11 files changed

+95
-25
lines changed

11 files changed

+95
-25
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
5+
---
6+
7+
**Describe the bug**
8+
A clear and concise description of what the bug is.
9+
10+
**To Reproduce**
11+
Steps to reproduce the behavior:
12+
13+
1.
14+
2.
15+
3.
16+
17+
**Expected behavior**
18+
A clear and concise description of what you expected to happen.
19+
20+
**Home Assistant version (if applicable):** <HA Version Number>
21+
22+
**`blinkpy` version (not needed if filling out Home Assistant version):**
23+
24+
**Log Output/Additional Information**
25+
If using home-assistant, please paste the output of the log showing your error below. If not, please include any additional useful information.
26+
27+
```
28+
PASTE LOG OUTPUT HERE
29+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
**Is your feature request related to a problem? Please describe.**
8+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9+
10+
**Describe the solution you'd like**
11+
A clear and concise description of what you want to happen.
12+
13+
**Additional context**
14+
Add any other context about the feature request (such as API endpoint responses, etc).

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
## Checklist:
77
- [ ] Local tests with `tox` run successfully **PR cannot be meged unless tests pass**
8-
- [ ] If user-facing functionality changed, README.rst updated
9-
- [ ] Tests added to verify new code works
8+
- [ ] Changes tested locally to ensure platform still works as intended
9+
- [ ] Tests added to verify new code works

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ dist/*
1010
.sh
1111
build/*
1212
docs/_build
13+
*.log

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Changelog
33

44
A list of changes between each release
55

6+
0.10.1 (2018-10-18)
7+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
- Fix re-authorization bug (fixes `#101 <https://github.com/fronzbot/blinkpy/issues/#101>`_)
9+
- Log an error if saving video that doesn't exist
10+
611
0.10.0 (2018-10-16)
712
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
813
- Moved all API calls to own module for easier maintainability

blinkpy/blinkpy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
create_session, BlinkURLHandler,
2222
BlinkAuthenticationException)
2323
from blinkpy.helpers.constants import (
24-
BLINK_URL, LOGIN_URL, LOGIN_BACKUP_URL)
24+
BLINK_URL, LOGIN_URL, LOGIN_BACKUP_URL, PROJECT_URL)
2525

2626
REFRESH_RATE = 30
2727

@@ -146,8 +146,7 @@ def get_ids(self):
146146
if all_networks:
147147
_LOGGER.error(("More than one unboarded network. "
148148
"Platform may not work as intended. "
149-
"Please open an issue on "
150-
"https://github.com/fronzbot/blinkpy."))
149+
"Please open an issue on %s"), PROJECT_URL)
151150

152151
def refresh(self, force_cache=False):
153152
"""

blinkpy/camera.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def check_for_motion(self):
162162
else:
163163
self.motion_detected = False
164164
except KeyError:
165-
_LOGGER.warning("Could not extract clip info from camera %s",
166-
self.name)
165+
_LOGGER.info("Could not extract clip info from camera %s",
166+
self.name)
167167

168168
def image_to_file(self, path):
169169
"""
@@ -187,6 +187,9 @@ def video_to_file(self, path):
187187
"""
188188
_LOGGER.debug("Writing video from %s to %s", self.name, path)
189189
response = self._cached_video
190+
if response is None:
191+
_LOGGER.error("No saved video exist for %s.", self.name)
192+
return
190193
with open(path, 'wb') as vidfile:
191194
copyfileobj(response.raw, vidfile)
192195

blinkpy/helpers/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
MAJOR_VERSION = 0
66
MINOR_VERSION = 10
7-
PATCH_VERSION = 0
7+
PATCH_VERSION = 1
88

99
__version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
1010

blinkpy/helpers/util.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
from requests import Request, Session, exceptions
5-
from blinkpy.helpers.constants import BLINK_URL
5+
from blinkpy.helpers.constants import BLINK_URL, PROJECT_URL
66
import blinkpy.helpers.errors as ERROR
77

88

@@ -17,7 +17,7 @@ def create_session():
1717

1818
def attempt_reauthorization(blink):
1919
"""Attempt to refresh auth token and links."""
20-
_LOGGER.debug("Auth token expired, attempting reauthorization.")
20+
_LOGGER.info("Auth token expired, attempting reauthorization.")
2121
headers = blink.get_auth_token()
2222
return headers
2323

@@ -48,20 +48,25 @@ def http_req(blink, url='http://example.com', data=None, headers=None,
4848

4949
try:
5050
response = blink.session.send(prepped, stream=stream)
51+
if json_resp and 'code' in response.json():
52+
if is_retry:
53+
_LOGGER.error(("Cannot obtain new token for server auth. "
54+
"Please report this issue on %s"), PROJECT_URL)
55+
return None
56+
else:
57+
headers = attempt_reauthorization(blink)
58+
return http_req(blink, url=url, data=data, headers=headers,
59+
reqtype=reqtype, stream=stream,
60+
json_resp=json_resp, is_retry=True)
5161
except (exceptions.ConnectionError, exceptions.Timeout):
52-
_LOGGER.error("Cannot connect to server. Possible outage.")
53-
return None
54-
55-
if json_resp and 'code' in response.json():
56-
if is_retry:
57-
_LOGGER.error("Cannot authenticate with server.")
58-
raise BlinkAuthenticationException(
59-
(response.json()['code'], response.json()['message']))
60-
else:
62+
_LOGGER.error("Cannot connect to server with url %s.", url)
63+
if not is_retry:
6164
headers = attempt_reauthorization(blink)
6265
return http_req(blink, url=url, data=data, headers=headers,
6366
reqtype=reqtype, stream=stream,
6467
json_resp=json_resp, is_retry=True)
68+
_LOGGER.error("Possible issue with Blink servers.")
69+
return None
6570

6671
if json_resp:
6772
return response.json()

tests/test_api.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test various api functions."""
22

33
import unittest
4+
from unittest import mock
45
from blinkpy import api
56
from blinkpy.blinkpy import Blink
67
from blinkpy.helpers.util import create_session
@@ -20,13 +21,21 @@ def tearDown(self):
2021
"""Tear down blink module."""
2122
self.blink = None
2223

23-
def test_http_req_connect_error(self):
24+
@mock.patch('blinkpy.blinkpy.Blink.get_auth_token')
25+
def test_http_req_connect_error(self, mock_auth):
2426
"""Test http_get error condition."""
25-
expected = ("ERROR:blinkpy.helpers.util:"
26-
"Cannot connect to server. Possible outage.")
27+
mock_auth.return_value = {'foo': 'bar'}
28+
firstlog = ("ERROR:blinkpy.helpers.util:"
29+
"Cannot connect to server with url {}").format(
30+
'http://notreal.fake.')
31+
nextlog = ("INFO:blinkpy.helpers.util:"
32+
"Auth token expired, attempting reauthorization.")
33+
lastlog = ("ERROR:blinkpy.helpers.util:"
34+
"Possible issue with Blink servers.")
35+
expected = [firstlog, nextlog, firstlog, lastlog]
2736
with self.assertLogs() as getlog:
2837
api.http_get(self.blink, 'http://notreal.fake')
2938
with self.assertLogs() as postlog:
3039
api.http_post(self.blink, 'http://notreal.fake')
31-
self.assertEqual(getlog.output, [expected])
32-
self.assertEqual(postlog.output, [expected])
40+
self.assertEqual(getlog.output, expected)
41+
self.assertEqual(postlog.output, expected)

tests/test_blinkpy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from blinkpy.helpers.util import (
1515
http_req, create_session, BlinkAuthenticationException,
1616
BlinkException, BlinkURLHandler)
17+
from blinkpy.helpers.constants import PROJECT_URL
1718
import tests.mock_responses as mresp
1819

1920
USERNAME = 'foobar'
@@ -77,11 +78,15 @@ def test_manual_login(self, getpwd, mock_sess):
7778
def test_bad_request(self, mock_sess):
7879
"""Check that we raise an Exception with a bad request."""
7980
self.blink.session = create_session()
81+
explog = ("ERROR:blinkpy.helpers.util:"
82+
"Cannot obtain new token for server auth. "
83+
"Please report this issue on {}").format(PROJECT_URL)
8084
with self.assertRaises(BlinkException):
8185
http_req(self.blink, reqtype='bad')
8286

83-
with self.assertRaises(BlinkAuthenticationException):
87+
with self.assertLogs() as logrecord:
8488
http_req(self.blink, reqtype='post', is_retry=True)
89+
self.assertEqual(logrecord.output, [explog])
8590

8691
def test_authentication(self, mock_sess):
8792
"""Check that we can authenticate Blink up properly."""

0 commit comments

Comments
 (0)