<<

blinkpy Documentation Release 0.18.0.dev0

Kevin Fronczak

Sep 12, 2021

Contents:

1 Quick Start 3

2 Advanced Library Usage 7

3 Contributing to blinkpy 11

4 Blinkpy Library Reference 15

5 Changelog 25

6 Indices and tables 35

Python Module Index 37

Index 39

i ii 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. “ -Free HS Home Monitoring & Alert Systems” is a trademark owned by Immedia Inc., see www.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 module responsibly.

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 blinkpy directory 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 to support the Blink component in homeassistant.

1 blinkpy Documentation, Release 0.18.0.dev0

2 Contents: CHAPTER 1

Quick Start

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. 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 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.

1.1 Starting blink without a prompt

In some cases, having an interactive command- 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, you must supply the login data to the blink authentication handler. This is best done by instantiating your own auth handler with a dictionary containing at least your username and password. from blinkpy.blinkpy import Blink from blinkpy.auth import Auth blink= Blink() # Can set no_prompt when initializing auth handler auth= Auth({"username":,"password":}, no_

˓→prompt=True) blink.auth= auth blink.start()

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:

3 blinkpy Documentation, Release 0.18.0.dev0

auth.send_auth_key(blink,) 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 minimum of username and password. A built in function in the blinkpy.helpers.util module can aid in loading this file. Note, if no_prompt is desired, a similar flow can be followed as above.

from blinkpy.blinkpy import Blink from blinkpy.auth import Auth from blinkpy.helpers.util import json_load

blink= Blink() auth= Auth(json_load("")) blink.auth= auth blink.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 frequency of login requests. This data can be saved as follows (it can then be loaded by following the instructions above for supplying credentials from a file):

blink.save("")

1.4 Getting cameras

Cameras are instantiated as individual BlinkCamera classes within a BlinkSyncModule instance. All of your sync modules are stored within the Blink.sync dictionary and can be accessed using the name of the sync module as 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 camera print(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 with calls to Blink.refresh() but will only make a request if motion has been detected or other changes have been found. This can be overridden with the force flag, but this should be used for debugging only since it overrides the internal request throttling.

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

4 Chapter 1. Quick Start blinkpy Documentation, Release 0.18.0.dev0

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

camera= blink.cameras['SOME CAMERA NAME'] camera.snap_picture() # Take a new picture with the camera blink.refresh() # Get new information from server camera.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. This is done as follows:

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

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

# Print arm status of a sync module - a system refresh should be performed first blink.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 camera camera.arm= True

# Disable motion detection on a camera camera.arm= False

# Print arm status of a sync module - a system refresh should be performed first blink.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 stop= variable. Note that by default, the library will search the first ten pages which is sufficient in most use cases. Additionally, you can specify one or more cameras via the camera= property. This can be a single string indicating the name of the camera, or a list of camera names. By default, it is set to the string 'all' to grab videos from all cameras. If you are downloading many items, setting the delay parameter is advised in order to throttle sequential calls to the API. By default this is set to 1 but can be any integer representing the number of seconds to delay between calls. Example usage, which downloads all videos recorded since July 4th, 2018 at 9:34am to the /home/blink directory with a 2s delay between calls:

1.5. Arming Blink 5 blinkpy Documentation, Release 0.18.0.dev0

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

6 Chapter 1. Quick Start 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 to be used in other scripts where advanced usage not covered in the Quick Start guide may be required. This usage guide will 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. Where possible, 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 many examples of usage within the blinkpy.api module. A simple example of usage is covered below, where the decorated method is prevented from executing again until 10s has passed. Note that if the method call is throttled by the 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 is done when the class is initialized and is accessible via the Auth.session property. To override with a custom websession, the following code can accomplish that: from blinkpy.blinkpy import Blink from blinkpy.auth import Auth

(continues on next page)

7 blinkpy Documentation, Release 0.18.0.dev0

(continued from previous page) blink= Blink() blink.auth= Auth() blink.auth.session= YourCustomSession

2.3 Custom Retry Logic

The built-in auth session via the create_session method allows for customizable retry intervals and conditions. These parameters are: • retries • backoff • retry_list retries is the total number of retry attempts that each http request can do before timing out. backoff is a parame- ter that allows for non-linear retry times such that the time between retries is backoff*(2^(retries) - 1). retry_list is simply a list of status codes to force a retry. By default retries=3, backoff=1, and retry_list=[429, 500, 502, 503, 504]. To override them, you need to add you overrides to a dictionary and use that to create a new session with the opts variable in the create_session method. The following example can serve as a guide where only the number of retries and backoff factor are overridden:

from blinkpy.blinkpy import Blink from blinkpy.auth import Auth

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

opts={"retries": 10,"backoff":2} blink.auth.session= blink.auth.create_session(opts=opts)

2.4 Custom HTTP requests

In addition to custom sessions, custom blink server requests can be performed. This give you the ability to bypass the built-in Auth.query method. It also allows flexibility by giving you the option to pass your own url, rather than be limited to what is currently implemented in the blinkpy.api module. Send custom url This prepares a standard “GET” request.

from blinkpy.blinkpy import Blink from blinkpy.auth import Auth

blink= Blink() blink.auth= Auth() url= some_api_endpoint_string request= 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 the built-in response checking. This allows you to use the built in blinkpy.api endpoints, but also gives you flexibility to send your own urls.

8 Chapter 2. Advanced Library Usage blinkpy Documentation, Release 0.18.0.dev0

from blinkpy.blinkpy import Blink from blinkpy.auth import Auth from 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 query response= blink.auth.query(url=some_custom_url)

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

2.4. Custom HTTP requests 9 blinkpy Documentation, Release 0.18.0.dev0

10 Chapter 2. Advanced Library Usage 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//blinkpy.git $ cd blinkpy $ git remote add 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 4. Make changes Now you can make changes to your code. It is worthwhile to test your code as you progress (see the Testing section)

11 blinkpy Documentation, Release 0.18.0.dev0

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 choose the 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 ‘__ 7. Prior to merge approval Finally, the blinkpy repository uses continuous integration tools to run tests prior to merging. If there are any problems, 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 style conventions. First, you need to locally install

$ 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 you have installed. Only py36, py37, and py38 will be accepted). If you just want to check for style violations, you can run tox -e lint. Regardless, when you submit a pull request, your code MUST pass both the unit tests, and the linters. 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/.py -x. This will run the test .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_.

12 Chapter 3. Contributing to blinkpy blinkpy Documentation, Release 0.18.0.dev0

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 up before 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 or git add .. 3. Continue rebase: git rebase --continue. 4. Repeat until all conflicts resolved.

3.4. Catching Up With Reality 13 blinkpy Documentation, Release 0.18.0.dev0

14 Chapter 3. Contributing to blinkpy 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 is in 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, delay=1, debug=False) Download all videos from server since specified time. Parameters • path – Path to write files. /path/_.mp4 • since – Date and time to get videos from. Ex: “2018/07/28 12:33:00” to retrieve videos since 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). • delay – Number of seconds to wait in between subsequent video downloads. • debug – Set to TRUE to prevent downloading of items. Instead of downloading, entries will be printed to log.

15 blinkpy Documentation, Release 0.18.0.dev0

get_homescreen() Get homecreen information. merge_cameras() Merge all sync camera dicts into one. refresh(force=False, force_cache=False) Perform a system refresh. Parameters • force – Used to override throttle, resets refresh • force_cache – Used to force update without overriding throttle 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.BlinkSetupError Class 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.

16 Chapter 4. Blinkpy Library Reference blinkpy Documentation, Release 0.18.0.dev0

create_session(opts=None) Create a session for blink communication. extract_login_info() Extract login info from login response. header Return authorization header. login(login_url=’https://rest-prod.immedia-semi.com/api/v5/account/login’) Attempt login to blink servers. login_attributes Return a dictionary of login attributes. logout(blink) Log out. 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.BlinkBadResponse Class to throw bad json response exception. exception blinkpy.auth.LoginError Class to throw failed login exception. exception blinkpy.auth.TokenRefreshFailed Class to throw failed refresh exception.

4.2. auth.py 17 blinkpy Documentation, Release 0.18.0.dev0 exception blinkpy.auth.UnauthorizedError Class 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. get_network_info() Get network info for sync-less module. network_info Format owl response to resemble sync module. sync_initialize() Initialize a sync-less module. update_cameras(camera_type=) Update sync-less cameras. class blinkpy.sync_module.BlinkSyncModule(blink, network_name, network_id, camera_list) Class to initialize sync module. arm Return status of sync module: armed/disarmed. attributes Return 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. online Return boolean system online status. refresh(force_cache=False) Get all blink cameras and pulls their most recent status. start() Initialize the system.

18 Chapter 4. Blinkpy Library Reference blinkpy Documentation, Release 0.18.0.dev0

sync_initialize() Initialize a sync module. update_cameras(camera_type=) Update cameras from server. urls Return device urls.

4.4 camera.py

Defines Blink cameras. class blinkpy.camera.BlinkCamera(sync) Class to initialize individual camera. arm Return arm status of camera. attributes Return dictionary of all camera attributes. battery Return battery as string. extract_config_info(config) Extract info from config. get_liveview() Get livewview rtsps link. get_media(media_type=’image’) Download media (image or video). get_sensor_info() Retrieve calibrated temperatue from special endpoint. image_from_cache Return the most recently cached image. image_to_file(path) Write image to file. Parameters path – Path to write file record() Initiate clip recording. set_motion_detect(enable) Set motion detection. snap_picture() Take a picture with camera to create a new thumbnail. temperature_c Return temperature in celcius. update(config, force_cache=False, **kwargs) Update camera info. update_images(config, force_cache=False) Update images for camera.

4.4. camera.py 19 blinkpy Documentation, Release 0.18.0.dev0

video_from_cache Return 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. arm Return camera arm status. get_liveview() Get liveview link. get_sensor_info() Get sensor info for blink mini camera. 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

20 Chapter 4. Blinkpy Library Reference blinkpy Documentation, Release 0.18.0.dev0

• 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. 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_logout(blink) Logout of blink servers. 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.

4.5. api.py 21 blinkpy Documentation, Release 0.18.0.dev0

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 • 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.

22 Chapter 4. Blinkpy Library Reference blinkpy Documentation, Release 0.18.0.dev0

• 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. 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, uid_format=False) 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.

4.6. helpers/util.py 23 blinkpy Documentation, Release 0.18.0.dev0 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.

24 Chapter 4. Blinkpy Library Reference CHAPTER 5

Changelog

A list of changes between each release

5.1 0.17.1 (2021-02-18)

• Add delay parameter to Blink.download_videos method in order to throttle API during video retrieval (#437) • Bump pylint to 2.6.2

5.2 0.17.0 (2021-02-15)

Bugfixes: - Fix video downloading bug (#424) - Fix repeated authorization email bug (#432 and #428) New Features: - Add logout method (#429) - Add camera record method (#430) Other: - Add debug script to main repo to help with general debug - Upgrade login endpoint from v4 to v5 - Add python 3.9 support - Bump coverage to 5.4 - Bump pytest to 6.2.2 - Bump pytest-cov to 2.11.1 - Bump pygments to 2.8.0 - Bump pre-commit to 2.10.1 - Bump restructuredtext-lint to 1.3.2

5.3 0.16.4 (2020-11-22)

Bugfixes: • Updated liveview endpoint (#389) • Fixed mini thumbnail not updating (#388) • Add exception catch to prevent NoneType error on refresh, added test to check behavior as well (#401) - Unre- lated: had to add two force methods to refresh for testing purposes. Should not change normal usage. • Fix malformed stream url (#395)

25 blinkpy Documentation, Release 0.18.0.dev0

All: • Moved testtools to requirements_test.txt (#387) • Bumped pytest to 6.1.1 • Bumped flake8 to 3.8.4 • Fixed README spelling ((#381) via @rohitsud) • Bumped pygments to 2.7.1 • Bumped coverage to 5.3 • Bumped pydocstyle to 5.1.1 • Bumped pre-commit to 2.7.1 • Bumped pylint to 2.6.0 • Bumped pytest-cov to 2.10.1

5.4 0.16.3 (2020-08-02)

• Add user-agent to all headers

5.5 0.16.2 (2020-08-01)

• Add user-agent to header at login • Remove extra data parameters at login (not-needed) • Bump pytest to 6.0.1

5.6 0.16.1 (2020-07-29)

• Unpin requirements, set minimum version instead • Bump coverage to 5.2.1 • Bump pytest to 6.0.0

5.7 0.16.0 (2020-07-20)

Breaking Changes: • Add arm property to camera, deprecate motion enable method (#273) • Complete refactoring of auth logic (breaks all pre-0.16.0 setups!) (#261) New Features: • Add is_errored property to Auth class (#275) • Add new endpoint to get user infor (#280) • Add get_liveview command to camera module (#289)

26 Chapter 5. Changelog blinkpy Documentation, Release 0.18.0.dev0

• Add blink Mini Camera support (#290) • Add option to skip homescreen check (#305) • Add different timeout for video and image retrieval (#323) • Modifiy session to use HTTPAdapter and handle retries (#324) • Add retry option overrides (#339) All changes: Please see the change list in the (Release Notes)

5.8 0.15.1 (2020-07-11)

• Bugfix: remove “Host” from auth header (#330)

5.9 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)

5.10 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

5.8. 0.15.1 (2020-07-11) 27 blinkpy Documentation, Release 0.18.0.dev0

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

5.11 0.14.2 (2019-10-12)

• Update dependencies • Dockerize (@3ch01c __)

5.12 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.13 0.14.0 (2019-05-23)

Breaking Changes: • BlinkCamera.battery no longer reports a percentage, instead it returns a string representing the state of the 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 for events 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 enabled by 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

5.14 0.13.1 (2019-03-01)

• Remove throttle decorator from network status request

28 Chapter 5. Changelog blinkpy Documentation, Release 0.18.0.dev0

5.15 0.13.0 (2019-03-01)

Breaking change: Wifi status reported in dBm again, instead of bars (which is great). Also, the old get_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 cameras at 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 set to True. This additional throttle can be overridden with the force=True argument passed to the refresh function. • Add ability to cycle through login api endpoints to anticipate future endpoint deprecation

5.16 0.12.1 (2019-01-31)

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

5.17 0.12.0 (2019-01-31)

• Fix video api endpoint, re-enables motion detection • Add improved logging capability • Add download video method • Prevent blinkpy from failing at setup due to api error

5.15. 0.13.0 (2019-03-01) 29 blinkpy Documentation, Release 0.18.0.dev0

5.18 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.19 0.11.1 (2019-01-02)

• Fixed incorrect backup login url • Added calibrated temperature property for cameras

5.20 0.11.0 (2018-11-23)

• Added support for multiple sync modules

5.21 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.22 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.23 0.10.1 (2018-10-18)

• Fix re-authorization bug (fixes #101) • Log an error if saving video that doesn’t exist

5.24 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

30 Chapter 5. Changelog blinkpy Documentation, Release 0.18.0.dev0

• 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.25 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.26 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 the value every system refresh

5.27 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.28 0.7.1 (2018-05-09)

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

5.25. 0.9.0 (2018-09-27) 31 blinkpy Documentation, Release 0.18.0.dev0

5.29 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.30 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.31 0.5.2 (2017-03-12)

• Fixed packaging mishap, same as 0.5.0 otherwise

5.32 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

5.33 0.4.4 (2017-03-06)

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

32 Chapter 5. Changelog blinkpy Documentation, Release 0.18.0.dev0

5.34 0.4.3 (2017-03-05)

• Changed to bdist_wheel release

5.35 0.4.2 (2017-01-28)

• Fixed inability to retrieve motion data due to Key Error

5.36 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.37 0.3.1 (2017-01-25)

• Fixed refresh bug (Key Error)

5.38 0.3.0 (2017-01-25)

• Added device id to camera lookup table • Added image to file method

5.39 0.2.0 (2017-01-21)

• Initial release of blinkpy

5.34. 0.4.3 (2017-03-05) 33 blinkpy Documentation, Release 0.18.0.dev0

34 Chapter 5. Changelog CHAPTER 6

Indices and tables

• genindex • modindex • search

35 blinkpy Documentation, Release 0.18.0.dev0

36 Chapter 6. Indices and tables Python Module Index

b blinkpy.api, 20 blinkpy.auth, 16 blinkpy.blinkpy, 15 blinkpy.camera, 19 blinkpy.helpers.util, 23 blinkpy.sync_module, 18

37 blinkpy Documentation, Release 0.18.0.dev0

38 Python Module Index Index

A check_new_videos() arm (blinkpy.camera.BlinkCamera attribute), 19 (blinkpy.sync_module.BlinkSyncModule arm (blinkpy.camera.BlinkCameraMini attribute), 20 method), 18 arm (blinkpy.sync_module.BlinkSyncModule attribute), create_session() (blinkpy.auth.Auth method), 16 18 attributes (blinkpy.camera.BlinkCamera attribute), D 19 download_videos() (blinkpy.blinkpy.Blink method), attributes (blinkpy.sync_module.BlinkSyncModule 15 attribute), 18 Auth (class in blinkpy.auth), 16 E extract_config_info() B (blinkpy.camera.BlinkCamera method), 19 battery (blinkpy.camera.BlinkCamera attribute), 19 extract_login_info() (blinkpy.auth.Auth Blink (class in blinkpy.blinkpy), 15 method), 17 BlinkAuthenticationException, 23 BlinkBadResponse, 17 G BlinkCamera (class in blinkpy.camera), 19 gen_uid() (in module blinkpy.helpers.util), 23 BlinkCameraMini (class in blinkpy.camera), 20 get_camera_info() BlinkException, 23 (blinkpy.sync_module.BlinkOwl method), BlinkOwl (class in blinkpy.sync_module), 18 18 blinkpy.api (module), 20 get_camera_info() blinkpy.auth (module), 16 (blinkpy.sync_module.BlinkSyncModule blinkpy.blinkpy (module), 15 method), 18 blinkpy.camera (module), 19 get_events() (blinkpy.sync_module.BlinkSyncModule blinkpy.helpers.util (module), 23 method), 18 blinkpy.sync_module (module), 18 get_homescreen() (blinkpy.blinkpy.Blink method), BlinkSetupError, 16 15 BlinkSyncModule (class in blinkpy.sync_module), 18 get_liveview() (blinkpy.camera.BlinkCamera BlinkURLHandler (class in blinkpy.helpers.util), 23 method), 19 get_liveview() (blinkpy.camera.BlinkCameraMini C method), 20 check_if_ok_to_update() (blinkpy.blinkpy.Blink get_media() (blinkpy.camera.BlinkCamera method), method), 15 19 check_key_required() (blinkpy.auth.Auth get_network_info() method), 16 (blinkpy.sync_module.BlinkOwl method), check_new_video_time() 18 (blinkpy.sync_module.BlinkSyncModule get_network_info() method), 18 (blinkpy.sync_module.BlinkSyncModule method), 18

39 blinkpy Documentation, Release 0.18.0.dev0

get_owl_info() (blinkpy.sync_module.BlinkSyncModulerefresh() (blinkpy.sync_module.BlinkSyncModule method), 18 method), 18 get_sensor_info() (blinkpy.camera.BlinkCamera refresh_token() (blinkpy.auth.Auth method), 17 method), 19 request_camera_info() (in module blinkpy.api), get_sensor_info() 20 (blinkpy.camera.BlinkCameraMini method), 20 request_camera_liveview() (in module get_time() (in module blinkpy.helpers.util), 23 blinkpy.api), 20 request_camera_sensors() (in module H blinkpy.api), 21 header (blinkpy.auth.Auth attribute), 17 request_camera_usage() (in module blinkpy.api), http_get() (in module blinkpy.api), 20 21 http_post() (in module blinkpy.api), 20 request_cameras() (in module blinkpy.api), 21 request_command_status() (in module I blinkpy.api), 21 image_from_cache (blinkpy.camera.BlinkCamera request_homescreen() (in module blinkpy.api), 21 attribute), 19 request_login() (in module blinkpy.api), 21 image_to_file() (blinkpy.camera.BlinkCamera request_logout() (in module blinkpy.api), 21 method), 19 request_motion_detection_disable() (in module blinkpy.api), 21 J request_motion_detection_enable() (in module blinkpy.api), 21 json_load() (in module blinkpy.helpers.util), 23 request_network_status() (in module json_save() (in module blinkpy.helpers.util), 23 blinkpy.api), 22 L request_network_update() (in module blinkpy.api), 22 login() (blinkpy.auth.Auth method), 17 request_networks() (in module blinkpy.api), 22 login_attributes (blinkpy.auth.Auth attribute), 17 request_new_image() (in module blinkpy.api), 22 LoginError, 17 request_new_video() (in module blinkpy.api), 22 logout() (blinkpy.auth.Auth method), 17 request_sync_events() (in module blinkpy.api), 22 M request_syncmodule() (in module blinkpy.api), 22 merge_cameras() (blinkpy.blinkpy.Blink method), 16 request_system_arm() (in module blinkpy.api), 23 merge_dicts() (in module blinkpy.helpers.util), 24 request_system_disarm() (in module blinkpy.api), 23 N request_user() (in module blinkpy.api), 23 network_info (blinkpy.sync_module.BlinkOwl request_verify() (in module blinkpy.api), 23 attribute), 18 request_video_count() (in module blinkpy.api), 23 O request_videos() (in module blinkpy.api), 23 online (blinkpy.sync_module.BlinkSyncModule at- tribute), 18 S save() (blinkpy.blinkpy.Blink method), 16 P send_auth_key() (blinkpy.auth.Auth method), 17 prepare_request() (blinkpy.auth.Auth method), 17 set_motion_detect() prompt_login_data() (in module (blinkpy.camera.BlinkCamera method), 19 blinkpy.helpers.util), 24 setup_camera_list() (blinkpy.blinkpy.Blink method), 16 Q setup_login_ids() (blinkpy.blinkpy.Blink method), query() (blinkpy.auth.Auth method), 17 16 setup_network_ids() (blinkpy.blinkpy.Blink R method), 16 setup_networks() (blinkpy.blinkpy.Blink method), record() (blinkpy.camera.BlinkCamera method), 19 16 refresh() (blinkpy.blinkpy.Blink method), 16 setup_owls() (blinkpy.blinkpy.Blink method), 16

40 Index blinkpy Documentation, Release 0.18.0.dev0 setup_post_verify() (blinkpy.blinkpy.Blink method), 16 setup_prompt_2fa() (blinkpy.blinkpy.Blink method), 16 setup_sync_module() (blinkpy.blinkpy.Blink method), 16 setup_urls() (blinkpy.blinkpy.Blink method), 16 snap_picture() (blinkpy.camera.BlinkCamera method), 19 snap_picture() (blinkpy.camera.BlinkCameraMini method), 20 start() (blinkpy.blinkpy.Blink method), 16 start() (blinkpy.sync_module.BlinkSyncModule method), 18 startup() (blinkpy.auth.Auth method), 17 sync_initialize() (blinkpy.sync_module.BlinkOwl method), 18 sync_initialize() (blinkpy.sync_module.BlinkSyncModule method), 18 T temperature_c (blinkpy.camera.BlinkCamera attribute), 19 Throttle (class in blinkpy.helpers.util), 23 time_to_seconds() (in module blinkpy.helpers.util), 24 TokenRefreshFailed, 17 U UnauthorizedError, 17 update() (blinkpy.camera.BlinkCamera method), 19 update_cameras() (blinkpy.sync_module.BlinkOwl method), 18 update_cameras() (blinkpy.sync_module.BlinkSyncModule method), 19 update_images() (blinkpy.camera.BlinkCamera method), 19 urls (blinkpy.sync_module.BlinkSyncModule attribute), 19 V validate_login() (blinkpy.auth.Auth method), 17 validate_login_data() (in module blinkpy.helpers.util), 24 validate_response() (blinkpy.auth.Auth method), 17 video_from_cache (blinkpy.camera.BlinkCamera attribute), 19 video_to_file() (blinkpy.camera.BlinkCamera method), 20

Index 41