Skip to content

Commit 9335a37

Browse files
authored
Merge pull request #77 from fronzbot/v0.8.1
v0.8.1
2 parents 0d83a7f + 3713485 commit 9335a37

File tree

9 files changed

+48
-18
lines changed

9 files changed

+48
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.pytest_cache/*
12
.cache/*
23
.tox/*
34
__pycache__/*

CHANGES.rst

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

44
A list of changes between each release
55

6+
0.9.0.dev (Development Version)
7+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
69
0.8.0 (2018-05-21)
710
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
811
- Added support for battery voltage level (fixes `#64 <https://github.com/fronzbot/blinkpy/issues/64>`_)

blinkpy/blinkpy.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
_LOGGER = logging.getLogger('blinkpy')
2828

29+
MAX_CLIPS = 5
30+
2931

3032
def _attempt_reauthorization(blink):
3133
"""Attempt to refresh auth token and links."""
@@ -79,7 +81,7 @@ class BlinkAuthenticationException(BlinkException):
7981
pass
8082

8183

82-
class BlinkURLHandler(object):
84+
class BlinkURLHandler():
8385
"""Class that handles Blink URLS."""
8486

8587
def __init__(self, region_id):
@@ -93,7 +95,7 @@ def __init__(self, region_id):
9395
_LOGGER.debug("Setting base url to %s.", self.base_url)
9496

9597

96-
class BlinkCamera(object):
98+
class BlinkCamera():
9799
"""Class to initialize individual camera."""
98100

99101
def __init__(self, config, blink):
@@ -118,6 +120,8 @@ def __init__(self, config, blink):
118120
self.motion_detected = None
119121
self.wifi_strength = None
120122
self.camera_config = dict()
123+
self.motion_enabled = None
124+
self.last_record = list()
121125

122126
@property
123127
def attributes(self):
@@ -132,10 +136,12 @@ def attributes(self):
132136
'battery': self.battery,
133137
'thumbnail': self.thumbnail,
134138
'video': self.clip,
139+
'motion_enabled': self.motion_enabled,
135140
'notifications': self.notifications,
136141
'motion_detected': self.motion_detected,
137142
'wifi_strength': self.wifi_strength,
138-
'network_id': self.blink.network_id
143+
'network_id': self.blink.network_id,
144+
'last_record': self.last_record
139145
}
140146
return attributes
141147

@@ -205,13 +211,31 @@ def update(self, values):
205211

206212
try:
207213
self.battery_voltage = cfg['camera'][0]['battery_voltage']
208-
self.motion_detected = cfg['camera'][0]['motion_alert']
214+
self.motion_enabled = cfg['camera'][0]['motion_alert']
209215
self.wifi_strength = cfg['camera'][0]['wifi_strength']
210216
self.temperature = cfg['camera'][0]['temperature']
211217
except KeyError:
212218
_LOGGER.warning("Problem extracting config for camera %s",
213219
self.name)
214220

221+
# Check if the most recent clip is included in the last_record list
222+
# and that the last_record list is populated
223+
try:
224+
new_clip = self.blink.videos[self.name][0]['clip']
225+
if new_clip not in self.last_record and self.last_record:
226+
self.motion_detected = True
227+
self.last_record.insert(0, new_clip)
228+
if len(self.last_record) > MAX_CLIPS:
229+
self.last_record.pop()
230+
elif not self.last_record:
231+
self.last_record.insert(0, new_clip)
232+
self.motion_detected = False
233+
else:
234+
self.motion_detected = False
235+
except KeyError:
236+
_LOGGER.warning("Could not extract clip info from camera %s",
237+
self.name)
238+
215239
def image_refresh(self):
216240
"""Refresh current thumbnail."""
217241
url = self.urls.home_url
@@ -248,7 +272,7 @@ def video_to_file(self, path):
248272
copyfileobj(response.raw, vidfile)
249273

250274

251-
class Blink(object):
275+
class Blink():
252276
"""Class to initialize communication and sync module."""
253277

254278
def __init__(self, username=None, password=None):
@@ -348,7 +372,6 @@ def refresh(self):
348372
camera.update(element)
349373
except KeyError:
350374
pass
351-
return None
352375

353376
def get_videos(self, start_page=0, end_page=1):
354377
"""Retrieve last recorded videos per camera."""

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 = 8
7-
PATCH_VERSION = 0
7+
PATCH_VERSION = 1
88

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

pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ reports=no
77
# unused-argument - generic callbacks and setup methods create a lot of warnings
88
# too-many-* - are not enforced for the sake of readability
99
# too-few-* - same as too-many-*
10+
# no-else-return - I don't see any reason to enforce this. both forms are readable
1011

1112
disable=
1213
locally-disabled,
@@ -20,4 +21,5 @@ disable=
2021
too-many-return-statements,
2122
too-many-statements,
2223
too-many-lines,
23-
too-few-public-methods,
24+
too-few-public-methods,
25+
no-else-return,

requirements_test.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
flake8==3.3
2-
flake8-docstrings==1.1.0
3-
pylint==1.8.1
4-
pydocstyle==2.0.0
5-
pytest==3.3.1
1+
flake8==3.5.0
2+
flake8-docstrings==1.3.0
3+
pylint==2.1.1
4+
pydocstyle==2.1.1
5+
pytest==3.7.1
66
pytest-cov>=2.3.1
77
pytest-sugar>=0.9.0
88
pytest-timeout>=1.0.0
99
restructuredtext-lint>=1.0.1
10-
pygments>=2.2.0
10+
pygments>=2.2.0

tests/mock_responses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def json(self):
3939
response_to_return = {'message': 'Error', 'code': 404}
4040
code_to_return = 404
4141

42-
if url_arg == const.LOGIN_URL or url_arg == const.LOGIN_BACKUP_URL:
42+
if url_arg in (const.LOGIN_URL, const.LOGIN_BACKUP_URL):
4343
response_to_return = LOGIN_RESPONSE
4444
code_to_return = 200
4545
elif url_arg is not None:
@@ -77,6 +77,7 @@ def raw(self):
7777

7878
url_arg = args[0]
7979

80+
# pylint: disable=R1711
8081
if url_arg == 'use_bad_response':
8182
return MockGetResponse({'foo': 'bar'}, 200)
8283
elif url_arg == 'reauth':

tests/test_blink_cameras.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_camera_properties(self, mock_get, mock_post, mock_cfg):
8888
self.assertEqual(camera.battery_string, "OK")
8989
self.assertEqual(camera.notifications, 2)
9090
self.assertEqual(camera.region_id, 'test')
91-
self.assertEqual(camera.motion_detected, True)
91+
self.assertEqual(camera.motion_enabled, True)
9292
self.assertEqual(camera.wifi_strength, -30)
9393

9494
camera_config = self.camera_config
@@ -154,5 +154,5 @@ def test_camera_attributes(self, mock_cfg):
154154
self.assertEqual(camera_attr['battery'], 50)
155155
self.assertEqual(camera_attr['notifications'], 2)
156156
self.assertEqual(camera_attr['network_id'], '0000')
157-
self.assertEqual(camera_attr['motion_detected'], True)
157+
self.assertEqual(camera_attr['motion_enabled'], True)
158158
self.assertEqual(camera_attr['wifi_strength'], -30)

tests/test_blink_setup.py

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

99
import unittest
1010
from unittest import mock
11-
from blinkpy import blinkpy as blinkpy
11+
from blinkpy import blinkpy
1212
import tests.mock_responses as mresp
1313

1414
USERNAME = 'foobar'

0 commit comments

Comments
 (0)