Skip to content

Commit cbafd75

Browse files
authored
Merge pull request #747 from fronzbot/dev
v0.22.0
2 parents 078405c + 735a582 commit cbafd75

29 files changed

+1987
-771
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ venv
1717
.session*
1818
Pipfile
1919
Pipfile.lock
20+
blink.json
21+
blinktest.py

CHANGES.rst

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ Changelog
44

55
A list of changes between each release
66

7+
0.22.0 (2023-08-16)
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
10+
**Bugfixes**
11+
12+
-None
13+
14+
**New Features**
15+
16+
- Asyncio conversion (`@mkmer #723 <https://github.com/fronzbot/blinkpy/pull/723>`__)
17+
18+
**Other Changes**
19+
20+
- Various fixes to codebase to support asyncio
21+
- Upgrade flake8 to 6.1.0
22+
- Upgrade pylint to 2.17.5
23+
- Upgrade pytest to 7.4.0
24+
- Upgrade black to 23.7.0
25+
- Upgrade pytest-cov to 4.1.0
26+
- Upgrade pygments to 2.16.1
27+
- Upgrade coverage to 7.3.0
28+
729
0.21.0 (2023-05-28)
830
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
931

README.rst

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
blinkpy |Build Status| |Coverage Status| |Docs| |PyPi Version| |Codestyle|
22
=============================================================================================
3-
A Python library for the Blink Camera system (Python 3.7+)
3+
A Python library for the Blink Camera system (Python 3.8+)
44

55
Like the library? Consider buying me a cup of coffee!
66

@@ -44,14 +44,14 @@ This library was built with the intention of allowing easy communication with Bl
4444

4545
Quick Start
4646
=============
47-
The simplest way to use this package from a terminal is to call ``Blink.start()`` which will prompt for your Blink username and password and then log you in. In addition, http requests are throttled internally via use of the ``Blink.refresh_rate`` variable, which can be set at initialization and defaults to 30 seconds.
47+
The simplest way to use this package from a terminal is to call ``await Blink.start()`` which will prompt for your Blink username and password and then log you in. In addition, http requests are throttled internally via use of the ``Blink.refresh_rate`` variable, which can be set at initialization and defaults to 30 seconds.
4848

4949
.. code:: python
5050
5151
from blinkpy.blinkpy import Blink
5252
5353
blink = Blink()
54-
blink.start()
54+
await blink.start()
5555
5656
5757
This flow will prompt you for your username and password. Once entered, if you likely will need to send a 2FA key to the blink servers (this pin is sent to your email address). When you receive this pin, enter at the prompt and the Blink library will proceed with setup.
@@ -69,15 +69,15 @@ In some cases, having an interactive command-line session is not desired. In th
6969
# Can set no_prompt when initializing auth handler
7070
auth = Auth({"username": <your username>, "password": <your password>}, no_prompt=True)
7171
blink.auth = auth
72-
blink.start()
72+
await blink.start()
7373
7474
7575
Since you will not be prompted for any 2FA pin, you must call the ``blink.auth.send_auth_key`` function. There are two required parameters: the ``blink`` object as well as the ``key`` you received from Blink for 2FA:
7676

7777
.. code:: python
7878
79-
auth.send_auth_key(blink, <your key>)
80-
blink.setup_post_verify()
79+
await auth.send_auth_key(blink, <your key>)
80+
await blink.setup_post_verify()
8181
8282
8383
Supplying credentials from file
@@ -91,9 +91,9 @@ Other use cases may involved loading credentials from a file. This file must be
9191
from blinkpy.helpers.util import json_load
9292
9393
blink = Blink()
94-
auth = Auth(json_load("<File Location>"))
94+
auth = Auth(await json_load("<File Location>"))
9595
blink.auth = auth
96-
blink.start()
96+
await blink.start()
9797
9898
9999
Saving credentials
@@ -102,7 +102,7 @@ This library also allows you to save your credentials to use in future sessions.
102102

103103
.. code:: python
104104
105-
blink.save("<File location>")
105+
await blink.save("<File location>")
106106
107107
108108
Getting cameras
@@ -123,19 +123,19 @@ The most recent images and videos can be accessed as a bytes-object via internal
123123
.. code:: python
124124
125125
camera = blink.cameras['SOME CAMERA NAME']
126-
blink.refresh(force=True) # force a cache update USE WITH CAUTION
127-
camera.image_from_cache.raw # bytes-like image object (jpg)
128-
camera.video_from_cache.raw # bytes-like video object (mp4)
126+
await blink.refresh(force=True) # force a cache update USE WITH CAUTION
127+
camera.image_from_cache # bytes-like image object (jpg)
128+
camera.video_from_cache # bytes-like video object (mp4)
129129
130130
The ``blinkpy`` api also allows for saving images and videos to a file and snapping a new picture from the camera remotely:
131131

132132
.. code:: python
133133
134134
camera = blink.cameras['SOME CAMERA NAME']
135-
camera.snap_picture() # Take a new picture with the camera
136-
blink.refresh() # Get new information from server
137-
camera.image_to_file('/local/path/for/image.jpg')
138-
camera.video_to_file('/local/path/for/video.mp4')
135+
await camera.snap_picture() # Take a new picture with the camera
136+
await blink.refresh() # Get new information from server
137+
await camera.image_to_file('/local/path/for/image.jpg')
138+
await camera.video_to_file('/local/path/for/video.mp4')
139139
140140
141141
Arming Blink
@@ -145,13 +145,13 @@ Methods exist to arm/disarm the sync module, as well as enable/disable motion de
145145
.. code:: python
146146
147147
# Arm a sync module
148-
blink.sync["SYNC MODULE NAME"].arm = True
148+
await blink.sync["SYNC MODULE NAME"].async_arm(True)
149149
150150
# Disarm a sync module
151-
blink.sync["SYNC MODULE NAME"].arm = False
151+
await blink.sync["SYNC MODULE NAME"].async_arm(False)
152152
153153
# Print arm status of a sync module - a system refresh should be performed first
154-
blink.refresh()
154+
await blink.refresh()
155155
sync = blink.sync["SYNC MODULE NAME"]
156156
print(f"{sync.name} status: {sync.arm}")
157157
@@ -162,13 +162,13 @@ Similar methods exist for individual cameras:
162162
camera = blink.cameras["SOME CAMERA NAME"]
163163
164164
# Enable motion detection on a camera
165-
camera.arm = True
165+
await camera.async_arm(True)
166166
167167
# Disable motion detection on a camera
168-
camera.arm = False
168+
await camera.async_arm( False)
169169
170170
# Print arm status of a sync module - a system refresh should be performed first
171-
blink.refresh()
171+
await blink.refresh()
172172
print(f"{camera.name} status: {camera.arm}")
173173
174174
@@ -180,7 +180,7 @@ Example usage, which downloads all videos recorded since July 4th, 2018 at 9:34a
180180

181181
.. code:: python
182182
183-
blink.download_videos('/home/blink', since='2018/07/04 09:34', delay=2)
183+
await blink.download_videos('/home/blink', since='2018/07/04 09:34', delay=2)
184184
185185
186186
Sync Module Local Storage

blinkapp/blinkapp.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Script to run blinkpy as an blinkapp."""
22
from os import environ
3+
import asyncio
34
from datetime import datetime, timedelta
5+
from aiohttp import ClientSession
46
from blinkpy.blinkpy import Blink
57
from blinkpy.auth import Auth
68
from blinkpy.helpers.util import json_load
79

8-
910
CREDFILE = environ.get("CREDFILE")
1011
TIMEDELTA = timedelta(environ.get("TIMEDELTA", 1))
1112

@@ -15,25 +16,28 @@ def get_date():
1516
return (datetime.now() - TIMEDELTA).isoformat()
1617

1718

18-
def download_videos(blink, save_dir="/media"):
19+
async def download_videos(blink, save_dir="/media"):
1920
"""Make request to download videos."""
20-
blink.download_videos(save_dir, since=get_date())
21+
await blink.download_videos(save_dir, since=get_date())
2122

2223

23-
def start():
24+
async def start(session: ClientSession):
2425
"""Startup blink app."""
25-
blink = Blink()
26-
blink.auth = Auth(json_load(CREDFILE))
27-
blink.start()
26+
blink = Blink(session=session)
27+
blink.auth = Auth(await json_load(CREDFILE))
28+
await blink.start()
2829
return blink
2930

3031

31-
def main():
32+
async def main():
3233
"""Run the blink app."""
33-
blink = start()
34-
download_videos(blink)
34+
session = ClientSession()
35+
blink = await start(session)
36+
await download_videos(blink)
3537
blink.save(CREDFILE)
38+
await session.close()
3639

3740

3841
if __name__ == "__main__":
39-
main()
42+
loop = asyncio.get_event_loop()
43+
loop.run_until_complete(main())

0 commit comments

Comments
 (0)