Skip to content

Commit 5319714

Browse files
authored
Merge pull request #79 from fronzbot/v0.8.2
V0.8.2
2 parents 9335a37 + 5d91056 commit 5319714

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

blinkpy/blinkpy.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ def update(self, values):
194194
"""Update camera information."""
195195
self.name = values['name']
196196
self._status = values['active']
197-
self.thumbnail = "{}{}.jpg".format(
198-
self.urls.base_url, values['thumbnail'])
199197
self.clip = "{}{}".format(
200198
self.urls.base_url, values['video'])
199+
thumb_from_clip = self.clip[0:-4]
200+
self.thumbnail = "{}.jpg".format(thumb_from_clip)
201201
self._battery_string = values['battery']
202202
self.notifications = values['notifications']
203203

@@ -221,7 +221,8 @@ def update(self, values):
221221
# Check if the most recent clip is included in the last_record list
222222
# and that the last_record list is populated
223223
try:
224-
new_clip = self.blink.videos[self.name][0]['clip']
224+
records = sorted(self.blink.record_dates[self.name])
225+
new_clip = records.pop()
225226
if new_clip not in self.last_record and self.last_record:
226227
self.motion_detected = True
227228
self.last_record.insert(0, new_clip)
@@ -244,9 +245,10 @@ def image_refresh(self):
244245
for element in response:
245246
try:
246247
if str(element['device_id']) == self.id:
248+
clip = element['video']
247249
self.thumbnail = (
248250
"{}{}.jpg".format(
249-
self.urls.base_url, element['thumbnail'])
251+
self.urls.base_url, clip[0:-4])
250252
)
251253
return self.thumbnail
252254
except KeyError:
@@ -293,6 +295,7 @@ def __init__(self, username=None, password=None):
293295
self._video_count = 0
294296
self._all_videos = {}
295297
self._summary = None
298+
self.record_dates = dict()
296299

297300
@property
298301
def camera_thumbs(self):
@@ -376,6 +379,7 @@ def refresh(self):
376379
def get_videos(self, start_page=0, end_page=1):
377380
"""Retrieve last recorded videos per camera."""
378381
videos = list()
382+
all_dates = dict()
379383
for page_num in range(start_page, end_page + 1):
380384
this_page = self._video_request(page_num)
381385
if not this_page:
@@ -388,6 +392,12 @@ def get_videos(self, start_page=0, end_page=1):
388392
camera_name = entry['camera_name']
389393
clip_addr = entry['address']
390394
thumb_addr = entry['thumbnail']
395+
clip_date = clip_addr.split('_')[-6:]
396+
clip_date = '_'.join(clip_date)
397+
clip_date = clip_date.split('.')[0]
398+
if camera_name not in all_dates:
399+
all_dates[camera_name] = list()
400+
all_dates[camera_name].append(clip_date)
391401
try:
392402
self._all_videos[camera_name].append(
393403
{
@@ -402,6 +412,7 @@ def get_videos(self, start_page=0, end_page=1):
402412
'thumb': thumb_addr,
403413
}
404414
]
415+
self.record_dates = all_dates
405416

406417
def get_cameras(self):
407418
"""Find and creates cameras."""

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

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

tests/test_blink_cameras.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def setUp(self):
3939
'name': 'foobar',
4040
'armed': False,
4141
'active': 'disarmed',
42-
'thumbnail': '/test/image',
42+
'thumbnail': '/test/clip/clip.jpg',
4343
'video': '/test/clip/clip.mp4',
4444
'temp': 70,
4545
'battery': 3,
@@ -76,7 +76,7 @@ def test_camera_properties(self, mock_get, mock_post, mock_cfg):
7676
self.assertEqual(camera.armed, False)
7777
self.assertEqual(
7878
camera.thumbnail,
79-
"https://rest.test.{}/test/image.jpg".format(BLINK_URL)
79+
"https://rest.test.{}/test/clip/clip.jpg".format(BLINK_URL)
8080
)
8181
self.assertEqual(
8282
camera.clip,
@@ -93,7 +93,7 @@ def test_camera_properties(self, mock_get, mock_post, mock_cfg):
9393

9494
camera_config = self.camera_config
9595
camera_config['active'] = 'armed'
96-
camera_config['thumbnail'] = '/test2/image'
96+
camera_config['thumbnail'] = '/test2/clip.jpg'
9797
camera_config['video'] = '/test2/clip.mp4'
9898
camera_config['temp'] = 60
9999
camera_config['battery'] = 0
@@ -104,7 +104,7 @@ def test_camera_properties(self, mock_get, mock_post, mock_cfg):
104104
self.assertEqual(camera.armed, True)
105105
self.assertEqual(
106106
camera.thumbnail,
107-
"https://rest.test.{}/test2/image.jpg".format(BLINK_URL)
107+
"https://rest.test.{}/test2/clip.jpg".format(BLINK_URL)
108108
)
109109
self.assertEqual(
110110
camera.clip,
@@ -143,7 +143,7 @@ def test_camera_attributes(self, mock_cfg):
143143
self.assertEqual(camera_attr['armed'], False)
144144
self.assertEqual(
145145
camera_attr['thumbnail'],
146-
"https://rest.test.{}/test/image.jpg".format(BLINK_URL)
146+
"https://rest.test.{}/test/clip/clip.jpg".format(BLINK_URL)
147147
)
148148
self.assertEqual(
149149
camera_attr['video'],

0 commit comments

Comments
 (0)