Skip to content

Commit 93472e3

Browse files
committed
Added in motion interval to allow for looking at historic motion events.
- Good debug utility - Helps iron out rapid motion events, or missed events due to quick calls to refresh method
1 parent 85c14ed commit 93472e3

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

blinkpy/blinkpy.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,10 @@
3030
create_session, merge_dicts, get_time, BlinkURLHandler,
3131
BlinkAuthenticationException, Throttle)
3232
from blinkpy.helpers.constants import (
33-
BLINK_URL, LOGIN_URL, OLD_LOGIN_URL, LOGIN_BACKUP_URL)
33+
BLINK_URL, LOGIN_URL, OLD_LOGIN_URL, LOGIN_BACKUP_URL,
34+
DEFAULT_MOTION_INTERVAL, DEFAULT_REFRESH, MIN_THROTTLE_TIME)
3435
from blinkpy.helpers.constants import __version__
3536

36-
REFRESH_RATE = 30
37-
38-
# Prevents rapid calls to blink.refresh()
39-
# with the force_cache flag set to True
40-
MIN_THROTTLE_TIME = 2
4137

4238
_LOGGER = logging.getLogger(__name__)
4339

@@ -46,14 +42,19 @@ class Blink():
4642
"""Class to initialize communication."""
4743

4844
def __init__(self, username=None, password=None,
49-
refresh_rate=REFRESH_RATE):
45+
refresh_rate=DEFAULT_REFRESH,
46+
motion_interval=DEFAULT_MOTION_INTERVAL):
5047
"""
5148
Initialize Blink system.
5249
5350
:param username: Blink username (usually email address)
5451
:param password: Blink password
5552
:param refresh_rate: Refresh rate of blink information.
5653
Defaults to 15 (seconds)
54+
:param motion_interval: How far back to register motion in minutes.
55+
Defaults to last refresh time.
56+
Useful for preventing motion_detected property
57+
from de-asserting too quickly.
5758
"""
5859
self._username = username
5960
self._password = password
@@ -73,6 +74,7 @@ def __init__(self, username=None, password=None,
7374
self.cameras = CaseInsensitiveDict({})
7475
self.video_list = CaseInsensitiveDict({})
7576
self._login_url = LOGIN_URL
77+
self.motion_interval = DEFAULT_MOTION_INTERVAL
7678
self.version = __version__
7779

7880
@property

blinkpy/sync_module.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, blink, network_name, network_id, camera_list):
3333
self.network_info = None
3434
self.events = []
3535
self.cameras = CaseInsensitiveDict({})
36+
self.motion_interval = blink.motion_interval
3637
self.motion = {}
3738
self.last_record = {}
3839
self.camera_list = camera_list
@@ -161,8 +162,15 @@ def refresh(self, force_cache=False):
161162

162163
def check_new_videos(self):
163164
"""Check if new videos since last refresh."""
165+
try:
166+
interval = self.blink.last_refresh - self.motion_interval*60
167+
except TypeError:
168+
# This is the first start, so refresh hasn't happened yet.
169+
# No need to check for motion.
170+
return False
171+
164172
resp = api.request_videos(self.blink,
165-
time=self.blink.last_refresh,
173+
time=interval,
166174
page=1)
167175

168176
for camera in self.cameras.keys():

0 commit comments

Comments
 (0)