41
blinkpy Documentation Release 0.16.0-rc11 Kevin Fronczak Jul 02, 2020

blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy DocumentationRelease 0.16.0-rc11

Kevin Fronczak

Jul 02, 2020

Page 2: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method
Page 3: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

Contents:

1 Quick Start 3

2 Advanced Library Usage 7

3 Contributing to blinkpy 9

4 Blinkpy Library Reference 13

5 Changelog 23

6 Indices and tables 31

Python Module Index 33

Index 35

i

Page 4: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

ii

Page 5: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

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

Buy me a Coffee!

Disclaimer: Published under the MIT license - See LICENSE file for more details.

“Blink Wire-Free HS Home Monitoring & Alert Systems” is a trademark owned by Immedia Inc., seewww.blinkforhome.com for more information. I am in no way affiliated with Blink, nor Immedia Inc.

Original protocol hacking by MattTW : https://github.com/MattTW/BlinkMonitorProtocol

API calls faster than 60 seconds is not recommended as it can overwhelm Blink’s servers. Please use this moduleresponsibly.

0.1 Installation

pip install blinkpy

0.1.1 Installing Development Version

To install the current development version, perform the following steps. Note that the following will create a blinkpydirectory in your home area:

$ cd ~$ git clone https://github.com/fronzbot/blinkpy.git$ cd blinkpy$ rm -rf build dist$ python3 setup.py bdist_wheel$ pip3 install --upgrade dist/*.whl

If you’d like to contribute to this library, please read the contributing instructions.

For more information on how to use this library, please read the docs.

0.2 Purpose

This library was built with the intention of allowing easy communication with Blink camera systems, specifically tosupport the Blink component in homeassistant.

1

Page 6: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

2 Contents:

Page 7: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

CHAPTER 1

Quick Start

The simplest way to use this package from a terminal is to call Blink.start() which will prompt for your Blinkusername 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.

from blinkpy.blinkpy import Blink

blink = Blink()blink.start()

This flow will prompt you for your username and password. Once entered, if you likely will need to send a 2FA key tothe blink servers (this pin is sent to your email address). When you receive this pin, enter at the prompt and the Blinklibrary will proceed with setup.

1.1 Starting blink without a prompt

In some cases, having an interactive command-line session is not desired. In this case, you will need to set the Blink.auth.no_prompt value to True. In addition, since you will not be prompted with a username and password, youmust supply the login data to the blink authentication handler. This is best done by instantiating your own auth handlerwith a dictionary containing at least your username and password.

from blinkpy.blinkpy import Blinkfrom blinkpy.auth import Auth

blink = Blink()# Can set no_prompt when initializing auth handlerauth = Auth({"username": <your username>, "password": <your password>}, no_→˓prompt=True)blink.auth = authblink.start()

Since you will not be prompted for any 2FA pin, you must call the blink.auth.send_auth_key function. Thereare two required parameters: the blink object as well as the key you received from Blink for 2FA:

3

Page 8: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

auth.send_auth_key(blink, <your key>)blink.setup_post_verify()

1.2 Supplying credentials from file

Other use cases may involved loading credentials from a file. This file must be json formatted and contain a minimumof username and password. A built in function in the blinkpy.helpers.util module can aid in loadingthis file. Note, if no_prompt is desired, a similar flow can be followed as above.

from blinkpy.blinkpy import Blinkfrom blinkpy.auth import Authfrom blinkpy.helpers.util import json_load

blink = Blink()auth = Auth(json_load("<File Location>"))blink.auth = authblink.start()

1.3 Saving credentials

This library also allows you to save your credentials to use in future sessions. Saved information includes authenti-cation tokens as well as unique ids which should allow for a more streamlined experience and limits the frequencyof login requests. This data can be saved as follows (it can then be loaded by following the instructions above forsupplying credentials from a file):

blink.save("<File location>")

1.4 Getting cameras

Cameras are instantiated as individual BlinkCamera classes within a BlinkSyncModule instance. All of yoursync modules are stored within the Blink.sync dictionary and can be accessed using the name of the sync moduleas the key (this is the name of your sync module in the Blink App).

The below code will display cameras and their available attributes:

for name, camera in blink.cameras.items():print(name) # Name of the cameraprint(camera.attributes) # Print available attributes of camera

The most recent images and videos can be accessed as a bytes-object via internal variables. These can be updated withcalls to Blink.refresh() but will only make a request if motion has been detected or other changes have beenfound. This can be overridden with the force flag, but this should be used for debugging only since it overrides theinternal request throttling.

camera = blink.cameras['SOME CAMERA NAME']blink.refresh(force=True) # force a cache update USE WITH CAUTIONcamera.image_from_cache.raw # bytes-like image object (jpg)camera.video_from_cache.raw # bytes-like video object (mp4)

4 Chapter 1. Quick Start

Page 9: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

The blinkpy api also allows for saving images and videos to a file and snapping a new picture from the cameraremotely:

camera = blink.cameras['SOME CAMERA NAME']camera.snap_picture() # Take a new picture with the camerablink.refresh() # Get new information from servercamera.image_to_file('/local/path/for/image.jpg')camera.video_to_file('/local/path/for/video.mp4')

1.5 Arming Blink

Methods exist to arm/disarm the sync module, as well as enable/disable motion detection for individual cameras. Thisis done as follows:

# Arm a sync moduleblink.sync["SYNC MODULE NAME"].arm = True

# Disarm a sync moduleblink.sync["SYNC MODULE NAME"].disarm = False

# Print arm status of a sync module - a system refresh should be performed firstblink.refresh()sync = blink.sync["SYNC MODULE NAME"]print(f"{sync.name} status: {sync.arm}")

Similar methods exist for individual cameras:

camera = blink.cameras["SOME CAMERA NAME"]

# Enable motion detection on a cameracamera.arm = True

# Disable motion detection on a cameracamera.arm = False

# Print arm status of a sync module - a system refresh should be performed firstblink.refresh()print(f"{camera.name} status: {camera.arm}")

1.6 Download videos

You can also use this library to download all videos from the server. In order to do this, you must specify a path.You may also specifiy a how far back in time to go to retrieve videos via the since= variable (a simple string such as"2017/09/21" is sufficient), as well as how many pages to traverse via the page= variable. Note that by default,the library will search the first ten pages which is sufficient in most use cases. Additionally, you can specidy one ormore cameras via the camera= property. This can be a single string indicating the name of the camera, or a list ofcamera names. By default, it is set to the string 'all' to grab videos from all cameras.

Example usage, which downloads all videos recorded since July 4th, 2018 at 9:34am to the /home/blink directory:

blink.download_videos('/home/blink', since='2018/07/04 09:34')

1.5. Arming Blink 5

Page 10: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

6 Chapter 1. Quick Start

Page 11: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

CHAPTER 2

Advanced Library Usage

Usage of this library was designed with the Home Assistant project in mind. With that said, this library is flexible tobe used in other scripts where advanced usage not covered in the Quick Start guide may be required. This usage guidewill attempt to cover as many use cases as possible.

2.1 Throttling

In general, attempting too many requests to the Blink servers will result in your account being throttled. Wherepossible, adding a delay between calls is ideal. For use cases where this is not an acceptable solution, the blinkpy.helpers.util module contains a Throttle class that can be used as a decorator for calls. There are manyexamples of usage within the blinkpy.api module. A simple example of usage is covered below, where thedecorated method is prevented from executing again until 10s has passed. Note that if the method call is throttled bythe decorator, the method will return None.

from blinkpy.helpers.util import Throttle

@Throttle(seconds=10)def my_method(*args):

"""Some method to be throttled."""return True

2.2 Custom Sessions

By default, the blink.auth.Auth class creates its own websession via its create_session method. This isdone when the class is initialized and is accessible via the Auth.session property. To override with a customwebsession, the following code can accomplish that:

from blinkpy.blinkpy import Blinkfrom blinkpy.auth import Auth

(continues on next page)

7

Page 12: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

(continued from previous page)

blink = Blink()blink.auth = Auth()blink.auth.session = YourCustomSession

2.3 Custom HTTP requests

In addition to custom sessions, custom blink server requests can be performed. This give you the ability to bypass thebuilt-in Auth.query method. It also allows flexibility by giving you the option to pass your own url, rather than belimited to what is currently implemented in the blinkpy.api module.

Send custom url This prepares a standard “GET” request.

from blinkpy.blinkpy import Blinkfrom blinkpy.auth import Auth

blink = Blink()blink.auth = Auth()url = some_api_endpoint_stringrequest = blink.auth.prepare_request(url, blink.auth.header, None, "get")response = blink.auth.session.send(request)

Overload query method Another option is to create your own Auth class with a custom query method to avoid thebuilt-in response checking. This allows you to use the built in blinkpy.api endpoints, but also gives you flexibilityto send your own urls.

from blinkpy.blinkpy import Blinkfrom blinkpy.auth import Authfrom blinkpy import api

class CustomAuth(Auth):def query(

self,url=None,data=None,headers=self.header,reqtype="get",stream=False,json_resp=True,

**kwargs):

req = self.prepare_request(url, headers, data, reqtype)return self.session.send(req, stream=stream)

blink = blink.Blink()blink.auth = CustomAuth()

# Send custom GET queryresponse = blink.auth.query(url=some_custom_url)

# Call built-in networks api endpointresponse = api.request_networks(blink)

8 Chapter 2. Advanced Library Usage

Page 13: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

CHAPTER 3

Contributing to blinkpy

Everyone is welcome to contribute to blinkpy! The process to get started is described below.

3.1 Fork the Repository

You can do this right in github: just click the ‘fork’ button at the top right.

3.2 Start Developing

1. Setup Local Repository .. code:: bash

$ git clone https://github.com/<YOUR_GIT_USERNAME>/blinkpy.git $ cd blinkpy $ git remoteadd upstream https://github.com/fronzbot/blinkpy.git

2. Create virtualenv and install dependencies

$ python -m venv venv$ source venv/bin/activate$ pip install -r requirements.txt$ pip install -r requirements_test.txt$ pre-commit install

3. Create a Local Branch

First, you will want to create a new branch to hold your changes: git checkout -b<your-branch-name>

4. Make changes

Now you can make changes to your code. It is worthwhile to test your code as you progress (see the Testingsection)

9

Page 14: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

5. Commit Your Changes

To commit changes to your branch, simply add the files you want and the commit them to the branch. After that,you can push to your fork on GitHub:

$ git add .$ git commit$ git push origin HEAD

6. Submit your pull request on GitHub

• On GitHub, navigate to the blinkpy repository.

• In the “Branch” menu, choose the branch that contains your commits (from your fork).

• To the right of the Branch menu, click New pull request.

• The base branch dropdown menu should read dev. Use the compare branch drop-down menu to choosethe branch you made your changes in.

• Type a title and complete the provided description for your pull request.

• Click Create pull request.

• More detailed instructions can be found here: Creating a Pull Request <https://help.github.com/articles/creating-a-pull-request>‘__

7. Prior to merge approval

Finally, the blinkpy repository uses continuous integration tools to run tests prior to merging. If there are anyproblems, you will see a red ‘X’ next to your pull request.

3.3 Testing

It is important to test the code to make sure your changes don’t break anything major and that they pass PEP8 styleconventions. First, you need to locally install tox

$ pip install tox

You can then run all of the tests with the following command:

$ tox

Tips

If you only want to see if you can pass the local tests, you can run tox -e py37 (or whatever python version youhave installed. Only py36, py37, and py38 will be accepted). If you just want to check for style violations, you canrun tox -e lint. Regardless, when you submit a pull request, your code MUST pass both the unit tests, and thelinters.

If you need to change anything in requirements.txt for any reason, you’ll want to regenerate the virtual envri-onments used by tox by running with the -r flag: tox -r

If you want to run a single test (perhaps you only changed a small thing in one file) you can run tox -e py37-- tests/<testname>.py -x. This will run the test <testname>.py and stop testing upon the first failure,making it easier to figure out why a particular test might be failing. The test structure mimics the library structure,so if you changed something in sync_module.py, the associated test file would be in test_sync_module.py(ie. the filename is prepended with test_.

10 Chapter 3. Contributing to blinkpy

Page 15: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

3.4 Catching Up With Reality

If your code is taking a while to develop, you may be behind the dev branch, in which case you need to catch upbefore creating your pull-request. To do this you can run git rebase as follows (running this on your local branch):

$ git fetch upstream dev$ git rebase upstream/dev

If rebase detects conflicts, repeat the following process until all changes have been resolved:

1. git status shows you the filw with a conflict. You will need to edit that file and resolve the lines between<<<< | >>>>.

2. Add the modified file: git add <file> or git add ..

3. Continue rebase: git rebase --continue.

4. Repeat until all conflicts resolved.

3.4. Catching Up With Reality 11

Page 16: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

12 Chapter 3. Contributing to blinkpy

Page 17: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

CHAPTER 4

Blinkpy Library Reference

4.1 blinkpy.py

blinkpy is an unofficial api for the Blink security camera system.

repo url: https://github.com/fronzbot/blinkpy

Original protocol hacking by MattTW : https://github.com/MattTW/BlinkMonitorProtocol

Published under the MIT license - See LICENSE file for more details. “Blink Wire-Free HS Home Monitoring &Alert Systems” is a trademark owned by Immedia Inc., see www.blinkforhome.com for more information. blinkpy isin no way affiliated with Blink, nor Immedia Inc.

class blinkpy.blinkpy.Blink(refresh_rate=30, motion_interval=1, no_owls=False)Class to initialize communication.

check_if_ok_to_update()Check if it is ok to perform an http request.

download_videos(path, since=None, camera=’all’, stop=10, debug=False)Download all videos from server since specified time.

Parameters

• path – Path to write files. /path/<cameraname>_<recorddate>.mp4

• since – Date and time to get videos from. Ex: “2018/07/28 12:33:00” to retrieve videossince July 28th 2018 at 12:33:00

• camera – Camera name to retrieve. Defaults to “all”. Use a list for multiple cameras.

• stop – Page to stop on (~25 items per page. Default page 10).

• debug – Set to TRUE to prevent downloading of items. Instead of downloading, entrieswill be printed to log.

get_homescreen()Get homecreen information.

13

Page 18: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

merge_cameras()Merge all sync camera dicts into one.

refresh(force=False)Perform a system refresh.

Parameters force – Force an update of the camera data

save(file_name)Save login data to file.

setup_camera_list()Create camera list for onboarded networks.

setup_login_ids()Retrieve login id numbers from login response.

setup_network_ids()Create the network ids for onboarded networks.

setup_networks()Get network information.

setup_owls()Check for mini cameras.

setup_post_verify()Initialize blink system after verification.

setup_prompt_2fa()Prompt for 2FA.

setup_sync_module(name, network_id, cameras)Initialize a sync module.

setup_urls()Create urls for api.

start()Perform full system setup.

exception blinkpy.blinkpy.BlinkSetupErrorClass to handle setup errors.

4.2 auth.py

Login handler for blink.

class blinkpy.auth.Auth(login_data=None, no_prompt=False)Class to handle login communication.

check_key_required()Check if 2FA key is required.

create_session()Create a session for blink communication.

headerReturn authorization header.

login(login_url=’https://rest-prod.immedia-semi.com/api/v4/account/login’)Attempt login to blink servers.

14 Chapter 4. Blinkpy Library Reference

Page 19: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

login_attributesReturn a dictionary of login attributes.

prepare_request(url, headers, data, reqtype)Prepare a request.

query(url=None, data=None, headers=None, reqtype=’get’, stream=False, json_resp=True,is_retry=False, timeout=10)

Perform server requests.

Parameters

• url – URL to perform request

• data – Data to send

• headers – Headers to send

• reqtype – Can be ‘get’ or ‘post’ (default: ‘get’)

• stream – Stream response? True/FALSE

• json_resp – Return JSON response? TRUE/False

• is_retry – Is this part of a re-auth attempt? True/FALSE

refresh_token()Refresh auth token.

send_auth_key(blink, key)Send 2FA key to blink servers.

startup()Initialize tokens for communication.

validate_login()Check login information and prompt if not available.

validate_response(response, json_resp)Check for valid response.

exception blinkpy.auth.BlinkBadResponseClass to throw bad json response exception.

exception blinkpy.auth.LoginErrorClass to throw failed login exception.

exception blinkpy.auth.TokenRefreshFailedClass to throw failed refresh exception.

exception blinkpy.auth.UnauthorizedErrorClass to throw an unauthorized access error.

4.3 sync_module.py

Defines a sync module for Blink.

class blinkpy.sync_module.BlinkOwl(blink, name, network_id, response)Representation of a sync-less device.

get_camera_info(camera_id, **kwargs)Retrieve camera information.

4.3. sync_module.py 15

Page 20: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

get_network_info()Get network info for sync-less module.

network_infoFormat owl response to resemble sync module.

sync_initialize()Initialize a sync-less module.

update_cameras(camera_type=<class ’blinkpy.camera.BlinkCameraMini’>)Update sync-less cameras.

class blinkpy.sync_module.BlinkSyncModule(blink, network_name, network_id, camera_list)Class to initialize sync module.

armReturn status of sync module: armed/disarmed.

attributesReturn sync attributes.

check_new_video_time(timestamp)Check if video has timestamp since last refresh.

check_new_videos()Check if new videos since last refresh.

get_camera_info(camera_id, **kwargs)Retrieve camera information.

get_events(**kwargs)Retrieve events from server.

get_network_info()Retrieve network status.

get_owl_info(name)Extract owl information.

onlineReturn boolean system online status.

refresh(force_cache=False)Get all blink cameras and pulls their most recent status.

start()Initialize the system.

sync_initialize()Initialize a sync module.

update_cameras(camera_type=<class ’blinkpy.camera.BlinkCamera’>)Update cameras from server.

urlsReturn device urls.

4.4 camera.py

Defines Blink cameras.

16 Chapter 4. Blinkpy Library Reference

Page 21: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

class blinkpy.camera.BlinkCamera(sync)Class to initialize individual camera.

armReturn arm status of camera.

attributesReturn dictionary of all camera attributes.

batteryReturn battery as string.

extract_config_info(config)Extract info from config.

get_liveview()Get livewview rtsps link.

get_sensor_info()Retrieve calibrated temperatue from special endpoint.

image_from_cacheReturn the most recently cached image.

image_to_file(path)Write image to file.

Parameters path – Path to write file

set_motion_detect(enable)Set motion detection.

snap_picture()Take a picture with camera to create a new thumbnail.

temperature_cReturn temperature in celcius.

update(config, force_cache=False, **kwargs)Update camera info.

update_images(config, force_cache=False)Update images for camera.

video_from_cacheReturn the most recently cached video.

video_to_file(path)Write video to file.

Parameters path – Path to write file

class blinkpy.camera.BlinkCameraMini(sync)Define a class for a Blink Mini camera.

armReturn camera arm status.

get_liveview()Get liveview link.

get_sensor_info()Get sensor info for blink mini camera.

4.4. camera.py 17

Page 22: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

snap_picture()Snap picture for a blink mini camera.

4.5 api.py

Implements known blink API calls.

blinkpy.api.http_get(blink, url, stream=False, json=True, is_retry=False, timeout=10)Perform an http get request.

Parameters

• url – URL to perform get request.

• stream – Stream response? True/FALSE

• json – Return json response? TRUE/False

• is_retry – Is this part of a re-auth attempt?

blinkpy.api.http_post(blink, url, is_retry=False, timeout=10)Perform an http post request.

Parameters

• url – URL to perfom post request.

• is_retry – Is this part of a re-auth attempt?

blinkpy.api.request_camera_info(blink, network, camera_id)Request camera info for one camera.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to request info from.

blinkpy.api.request_camera_liveview(blink, network, camera_id)Request camera liveview.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to request liveview from.

blinkpy.api.request_camera_sensors(blink, network, camera_id)Request camera sensor info for one camera.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to request sesnor info from.

blinkpy.api.request_camera_usage(blink)Request camera status.

Parameters blink – Blink instance.

18 Chapter 4. Blinkpy Library Reference

Page 23: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

blinkpy.api.request_cameras(blink, network)Request all camera information.

Parameters

• Blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_command_status(blink, network, command_id)Request command status.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• command_id – Command id to check.

blinkpy.api.request_homescreen(blink)Request homescreen info.

blinkpy.api.request_login(auth, url, login_data, is_retry=False)Login request.

Parameters

• auth – Auth instance.

• url – Login url.

Login_data Dictionary containing blink login data.

blinkpy.api.request_motion_detection_disable(blink, network, camera_id)Disable motion detection for a camera.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to disable.

blinkpy.api.request_motion_detection_enable(blink, network, camera_id)Enable motion detection for a camera.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to enable.

blinkpy.api.request_network_status(blink, network)Request network information.

Parameters

• blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_network_update(blink, network)Request network update.

Parameters

4.5. api.py 19

Page 24: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

• blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_networks(blink)Request all networks information.

blinkpy.api.request_new_image(blink, network, camera_id)Request to capture new thumbnail for camera.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to request new image from.

blinkpy.api.request_new_video(blink, network, camera_id)Request to capture new video clip.

Parameters

• blink – Blink instance.

• network – Sync module network id.

• camera_id – Camera ID of camera to request new video from.

blinkpy.api.request_sync_events(blink, network)Request events from sync module.

Parameters

• blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_syncmodule(blink, network)Request sync module info.

Parameters

• blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_system_arm(blink, network)Arm system.

Parameters

• blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_system_disarm(blink, network)Disarm system.

Parameters

• blink – Blink instance.

• network – Sync module network id.

blinkpy.api.request_user(blink)Get user information from blink servers.

20 Chapter 4. Blinkpy Library Reference

Page 25: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

blinkpy.api.request_verify(auth, blink, verify_key)Send verification key to blink servers.

blinkpy.api.request_video_count(blink)Request total video count.

blinkpy.api.request_videos(blink, time=None, page=0)Perform a request for videos.

Parameters

• blink – Blink instance.

• time – Get videos since this time. In epoch seconds.

• page – Page number to get videos from.

4.6 helpers/util.py

Useful functions for blinkpy.

exception blinkpy.helpers.util.BlinkAuthenticationException(errcode)Class to throw authentication exception.

exception blinkpy.helpers.util.BlinkException(errcode)Class to throw general blink exception.

class blinkpy.helpers.util.BlinkURLHandler(region_id)Class that handles Blink URLS.

class blinkpy.helpers.util.Throttle(seconds=10)Class for throttling api calls.

blinkpy.helpers.util.gen_uid(size)Create a random sring.

blinkpy.helpers.util.get_time(time_to_convert=None)Create blink-compatible timestamp.

blinkpy.helpers.util.json_load(file_name)Load json credentials from file.

blinkpy.helpers.util.json_save(data, file_name)Save data to file location.

blinkpy.helpers.util.merge_dicts(dict_a, dict_b)Merge two dictionaries into one.

blinkpy.helpers.util.prompt_login_data(data)Prompt user for username and password.

blinkpy.helpers.util.time_to_seconds(timestamp)Convert TIMESTAMP_FORMAT time to seconds.

blinkpy.helpers.util.validate_login_data(data)Check for missing keys.

4.6. helpers/util.py 21

Page 26: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

22 Chapter 4. Blinkpy Library Reference

Page 27: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

CHAPTER 5

Changelog

A list of changes between each release

5.1 0.15.0 (2020-05-08)

Breaking Changes:

• Removed support for Python 3.5 (3.6 is now the minimum supported version)

• Deprecated Blink.login() method. Please only use the Blink.start() method for logging in.

New Functions

• Add device_id override when logging in (for debug and to differentiate applications) (#245)

This can be used by instantiating the Blink class with the device_id parameter.

All Changes:

• Fix setup.py use of internal pip structure (#233)

• Update python-slugify requirement from ~=3.0.2 to ~=4.0.0 (#234)

• Update python-dateutil requirement from ~=2.8.0 to ~=2.8.1 (#230)

• Bump requests from 2.22.0 to 2.23.0 (#231)

• Refactor login logic in preparation for 2FA (#241)

• Add 2FA Support (#242) (fixes (#210))

• Re-set key_required and available variables after setup (#245)

• Perform system refresh after setup (#245)

• Fix typos (#244)

23

Page 28: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

5.2 0.14.3 (2020-04-22)

• Add time check on recorded videos before determining motion

• Fix motion detection variable suck to True

• Add ability to load credentials from a json file

• Only allow motion_detected variable to trigger if system was armed

• Log response message from server if not attempting a re-authorization

5.3 0.14.2 (2019-10-12)

• Update dependencies

• Dockerize (@3ch01c <https://github.com/fronzbot/blinkpy/pull/198>__)

5.4 0.14.1 (2019-06-20)

• Fix timeout problems blocking blinkpy startup

• Updated login urls using rest-region subdomain

• Removed deprecated thumbanil recovery from homescreen

5.5 0.14.0 (2019-05-23)

Breaking Changes:

• BlinkCamera.battery no longer reports a percentage, instead it returns a string representing the state ofthe battery.

• Previous logic for calculating percentage was incorrect

• raw battery voltage can be accessed via BlinkCamera.battery_voltage

Bug Fixes:

• Updated video endpoint (fixes broken motion detection)

• Removed throttling from critical api methods which prevented proper operation of multi-sync unit setups

• Slugify downloaded video names to allow for OS interoperability

• Added one minute offset (Blink.motion_interval) when checking for recent motion to allow time forevents to propagate to server prior to refresh call.

Everything else:

• Changed all urls to use rest-region rather than rest.region. Ability to revert to old method is enabledby instantiating Blink() with the legacy_subdomain variable set to True.

• Added debug mode to blinkpy.download_videos routine to simply print the videos prepped for down-load, rather than actually saving them.

• Use UTC for time conversions, rather than local timezone

24 Chapter 5. Changelog

Page 29: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

5.6 0.13.1 (2019-03-01)

• Remove throttle decorator from network status request

5.7 0.13.0 (2019-03-01)

Breaking change: Wifi status reported in dBm again, instead of bars (which is great). Also, the oldget_camera_info method has changed and requires a camera_id parameter.

• Adds throttle decorator

• Decorate following functions with 4s throttle (call method with force=True to override):

– request_network_status

– request_syncmodule

– request_system_arm

– request_system_disarm

– request_sync_events

– request_new_image

– request_new_video

– request_video_count

– request_cameras

– request_camera_info

– request_camera_sensors

– request_motion_detection_enable

– request_motion_detection_disable

• Use the updated homescreen api endpoint to retrieve camera information. The old method to retrieve all camerasat once seems to not exist, and this was the only solution I could figure out and confirm to work.

• Adds throttle decorator to refresh function to prevent too many frequent calls with force_cache flag setto True. This additional throttle can be overridden with the force=True argument passed to the refreshfunction.

• Add ability to cycle through login api endpoints to anticipate future endpoint deprecation

5.8 0.12.1 (2019-01-31)

• Remove logging improvements since they were incompatible with home-assistant logging

5.9 0.12.0 (2019-01-31)

• Fix video api endpoint, re-enables motion detection

• Add improved logging capability

5.6. 0.13.1 (2019-03-01) 25

Page 30: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

• Add download video method

• Prevent blinkpy from failing at setup due to api error

5.10 0.11.2 (2019-01-23)

• Hotfix to prevent platform from stalling due to API change

• Motion detection and video recovery broken until new API endpoint discovered

5.11 0.11.1 (2019-01-02)

• Fixed incorrect backup login url

• Added calibrated temperature property for cameras

5.12 0.11.0 (2018-11-23)

• Added support for multiple sync modules

5.13 0.10.3 (2018-11-18)

• Use networks endpoint rather than homecreen to retrieve arm/disarm status (@md-reddevil)

• Fix incorrect command status endpoint (@md-reddevil)

• Add extra debug logging

• Remove error prior to re-authorization (only log error when re-auth failed)

5.14 0.10.2 (2018-10-30)

• Set minimum required version of the requests library to 2.20.0 due to vulnerability in earlier releases.

• When multiple networks detected, changed log level to warning from error

5.15 0.10.1 (2018-10-18)

• Fix re-authorization bug (fixes #101)

• Log an error if saving video that doesn’t exist

26 Chapter 5. Changelog

Page 31: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

5.16 0.10.0 (2018-10-16)

• Moved all API calls to own module for easier maintainability

• Added network ids to sync module and cameras to allow for multi-network use

• Removed dependency on video existance prior to camera setup (fixes #93)

• Camera wifi_strength now reported in wifi “bars” rather than dBm due to API endpoint change

• Use homescreen thumbnail as fallback in case it’s not in the camera endpoint

• Removed “armed” and “status” attributes from camera (status of camera only reported by “motion_enabled”now)

• Added serial number attributes to sync module and cameras

• Check network_id from login response and verify that network is onboarded (fixes #90)

• Check if retrieved clip is “None” prior to storing in cache

5.17 0.9.0 (2018-09-27)

• Complete code refactoring to enable future multi-sync module support

• Add image and video caching to the cameras

• Add internal throttling of system refresh

• Use session for http requests

Breaking change: - Cameras now accessed through sync module Blink.sync.cameras

5.18 0.8.1 (2018-09-24)

• Update requirements_test.txt

• Update linter versions

• Fix pylint warnings - Remove object from class declarations - Remove useless returns from functions

• Fix pylint errors - change if comparison to fix (consider-using-in) - Disabled no else-if-return check

• Fix useless-import-alias

• Disable no-else-return

• Fix motion detection - Use an array of recent video clips to determine if motion has been detected. - Reset thevalue every system refresh

5.19 0.8.0 (2018-05-21)

• Added support for battery voltage level (fixes #64)

• Added motion detection per camera

• Added fully accessible camera configuration dict

• Added celcius property to camera (fixes #60)

5.16. 0.10.0 (2018-10-16) 27

Page 32: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

5.20 0.7.1 (2018-05-09)

• Fixed pip 10 import issue during setup (@fronzbot)

5.21 0.7.0 (2018-02-08)

• Fixed style errors for bumped pydocstring and pylint versions

• Changed Blink.cameras dictionary to be case-insensitive (fixes #35)

• Changed api endpoint for video extraction (fixes #35 and #41)

• Removed last_motion() function from Blink class

• Refactored code for better organization

• Moved some request calls out of @property methods (enables future CLI support)

• Renamed get_summary() method to summary and changed to @property

• Added ability to download most recent video clip

• Improved camera arm/disarm handling (@b10m)

• Added authentication to login() function and deprecated setup_system() in favor of start()

• Added attributes dictionary to camera object

5.22 0.6.0 (2017-05-12)

• Removed redundent properties that only called hidden variables

• Revised request wrapper function to be more intelligent

• Added tests to ensure exceptions are caught and handled (100% coverage!)

• Added auto-reauthorization (token refresh) when a request fails due to an expired token (@tySwift93)

• Added battery level string to reduce confusion with the way Blink reports battery level as integer from 0 to 3

5.23 0.5.2 (2017-03-12)

• Fixed packaging mishap, same as 0.5.0 otherwise

5.24 0.5.0 (2017-03-12)

• Fixed region handling problem

• Added rest.piri subdomain as a backup if region can’t be found

• Improved the file writing function

• Large test coverage increase

28 Chapter 5. Changelog

Page 33: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

5.25 0.4.4 (2017-03-06)

• Fixed bug where region id was not being set in the header

5.26 0.4.3 (2017-03-05)

• Changed to bdist_wheel release

5.27 0.4.2 (2017-01-28)

• Fixed inability to retrieve motion data due to Key Error

5.28 0.4.1 (2017-01-27)

• Fixed refresh bug (0.3.1 did not actually fix the problem)

• Image refresh routine added (per camera)

• Dictionary of thumbnails per camera added

• Improved test coverage

5.29 0.3.1 (2017-01-25)

• Fixed refresh bug (Key Error)

5.30 0.3.0 (2017-01-25)

• Added device id to camera lookup table

• Added image to file method

5.31 0.2.0 (2017-01-21)

• Initial release of blinkpy

5.25. 0.4.4 (2017-03-06) 29

Page 34: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

30 Chapter 5. Changelog

Page 35: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

CHAPTER 6

Indices and tables

• genindex

• modindex

• search

31

Page 36: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

32 Chapter 6. Indices and tables

Page 37: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

Python Module Index

bblinkpy.api, 18blinkpy.auth, 14blinkpy.blinkpy, 13blinkpy.camera, 16blinkpy.helpers.util, 21blinkpy.sync_module, 15

33

Page 38: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

34 Python Module Index

Page 39: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

Index

Aarm (blinkpy.camera.BlinkCamera attribute), 17arm (blinkpy.camera.BlinkCameraMini attribute), 17arm (blinkpy.sync_module.BlinkSyncModule attribute),

16attributes (blinkpy.camera.BlinkCamera attribute),

17attributes (blinkpy.sync_module.BlinkSyncModule

attribute), 16Auth (class in blinkpy.auth), 14

Bbattery (blinkpy.camera.BlinkCamera attribute), 17Blink (class in blinkpy.blinkpy), 13BlinkAuthenticationException, 21BlinkBadResponse, 15BlinkCamera (class in blinkpy.camera), 16BlinkCameraMini (class in blinkpy.camera), 17BlinkException, 21BlinkOwl (class in blinkpy.sync_module), 15blinkpy.api (module), 18blinkpy.auth (module), 14blinkpy.blinkpy (module), 13blinkpy.camera (module), 16blinkpy.helpers.util (module), 21blinkpy.sync_module (module), 15BlinkSetupError, 14BlinkSyncModule (class in blinkpy.sync_module), 16BlinkURLHandler (class in blinkpy.helpers.util), 21

Ccheck_if_ok_to_update() (blinkpy.blinkpy.Blink

method), 13check_key_required() (blinkpy.auth.Auth

method), 14check_new_video_time()

(blinkpy.sync_module.BlinkSyncModulemethod), 16

check_new_videos()(blinkpy.sync_module.BlinkSyncModulemethod), 16

create_session() (blinkpy.auth.Auth method), 14

Ddownload_videos() (blinkpy.blinkpy.Blink method),

13

Eextract_config_info()

(blinkpy.camera.BlinkCamera method), 17

Ggen_uid() (in module blinkpy.helpers.util), 21get_camera_info()

(blinkpy.sync_module.BlinkOwl method),15

get_camera_info()(blinkpy.sync_module.BlinkSyncModulemethod), 16

get_events() (blinkpy.sync_module.BlinkSyncModulemethod), 16

get_homescreen() (blinkpy.blinkpy.Blink method),13

get_liveview() (blinkpy.camera.BlinkCameramethod), 17

get_liveview() (blinkpy.camera.BlinkCameraMinimethod), 17

get_network_info()(blinkpy.sync_module.BlinkOwl method),15

get_network_info()(blinkpy.sync_module.BlinkSyncModulemethod), 16

get_owl_info() (blinkpy.sync_module.BlinkSyncModulemethod), 16

get_sensor_info() (blinkpy.camera.BlinkCameramethod), 17

35

Page 40: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

get_sensor_info()(blinkpy.camera.BlinkCameraMini method), 17

get_time() (in module blinkpy.helpers.util), 21

Hheader (blinkpy.auth.Auth attribute), 14http_get() (in module blinkpy.api), 18http_post() (in module blinkpy.api), 18

Iimage_from_cache (blinkpy.camera.BlinkCamera

attribute), 17image_to_file() (blinkpy.camera.BlinkCamera

method), 17

Jjson_load() (in module blinkpy.helpers.util), 21json_save() (in module blinkpy.helpers.util), 21

Llogin() (blinkpy.auth.Auth method), 14login_attributes (blinkpy.auth.Auth attribute), 14LoginError, 15

Mmerge_cameras() (blinkpy.blinkpy.Blink method), 13merge_dicts() (in module blinkpy.helpers.util), 21

Nnetwork_info (blinkpy.sync_module.BlinkOwl

attribute), 16

Oonline (blinkpy.sync_module.BlinkSyncModule at-

tribute), 16

Pprepare_request() (blinkpy.auth.Auth method), 15prompt_login_data() (in module

blinkpy.helpers.util), 21

Qquery() (blinkpy.auth.Auth method), 15

Rrefresh() (blinkpy.blinkpy.Blink method), 14refresh() (blinkpy.sync_module.BlinkSyncModule

method), 16refresh_token() (blinkpy.auth.Auth method), 15request_camera_info() (in module blinkpy.api),

18request_camera_liveview() (in module

blinkpy.api), 18

request_camera_sensors() (in moduleblinkpy.api), 18

request_camera_usage() (in module blinkpy.api),18

request_cameras() (in module blinkpy.api), 18request_command_status() (in module

blinkpy.api), 19request_homescreen() (in module blinkpy.api), 19request_login() (in module blinkpy.api), 19request_motion_detection_disable() (in

module blinkpy.api), 19request_motion_detection_enable() (in

module blinkpy.api), 19request_network_status() (in module

blinkpy.api), 19request_network_update() (in module

blinkpy.api), 19request_networks() (in module blinkpy.api), 20request_new_image() (in module blinkpy.api), 20request_new_video() (in module blinkpy.api), 20request_sync_events() (in module blinkpy.api),

20request_syncmodule() (in module blinkpy.api), 20request_system_arm() (in module blinkpy.api), 20request_system_disarm() (in module

blinkpy.api), 20request_user() (in module blinkpy.api), 20request_verify() (in module blinkpy.api), 20request_video_count() (in module blinkpy.api),

21request_videos() (in module blinkpy.api), 21

Ssave() (blinkpy.blinkpy.Blink method), 14send_auth_key() (blinkpy.auth.Auth method), 15set_motion_detect()

(blinkpy.camera.BlinkCamera method), 17setup_camera_list() (blinkpy.blinkpy.Blink

method), 14setup_login_ids() (blinkpy.blinkpy.Blink method),

14setup_network_ids() (blinkpy.blinkpy.Blink

method), 14setup_networks() (blinkpy.blinkpy.Blink method),

14setup_owls() (blinkpy.blinkpy.Blink method), 14setup_post_verify() (blinkpy.blinkpy.Blink

method), 14setup_prompt_2fa() (blinkpy.blinkpy.Blink

method), 14setup_sync_module() (blinkpy.blinkpy.Blink

method), 14setup_urls() (blinkpy.blinkpy.Blink method), 14

36 Index

Page 41: blinkpy Documentation - media.readthedocs.org · request=blink.auth.prepare_request(url, blink.auth.header, None,"get") response=blink.auth.session.send(request) Overload query method

blinkpy Documentation, Release 0.16.0-rc11

snap_picture() (blinkpy.camera.BlinkCameramethod), 17

snap_picture() (blinkpy.camera.BlinkCameraMinimethod), 17

start() (blinkpy.blinkpy.Blink method), 14start() (blinkpy.sync_module.BlinkSyncModule

method), 16startup() (blinkpy.auth.Auth method), 15sync_initialize()

(blinkpy.sync_module.BlinkOwl method),16

sync_initialize()(blinkpy.sync_module.BlinkSyncModulemethod), 16

Ttemperature_c (blinkpy.camera.BlinkCamera

attribute), 17Throttle (class in blinkpy.helpers.util), 21time_to_seconds() (in module

blinkpy.helpers.util), 21TokenRefreshFailed, 15

UUnauthorizedError, 15update() (blinkpy.camera.BlinkCamera method), 17update_cameras() (blinkpy.sync_module.BlinkOwl

method), 16update_cameras() (blinkpy.sync_module.BlinkSyncModule

method), 16update_images() (blinkpy.camera.BlinkCamera

method), 17urls (blinkpy.sync_module.BlinkSyncModule attribute),

16

Vvalidate_login() (blinkpy.auth.Auth method), 15validate_login_data() (in module

blinkpy.helpers.util), 21validate_response() (blinkpy.auth.Auth method),

15video_from_cache (blinkpy.camera.BlinkCamera

attribute), 17video_to_file() (blinkpy.camera.BlinkCamera

method), 17

Index 37