Skip to content

Commit

Permalink
Merge pull request #154 from fronzbot/dev
Browse files Browse the repository at this point in the history
0.12.1
  • Loading branch information
fronzbot committed Feb 1, 2019
2 parents 77e200f + 2835ccf commit ff8f091
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 93 deletions.
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ Changelog

A list of changes between each release

0.12.1 (2019-01-31)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Remove logging improvements since they were incompatible with home-assistant logging

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


0.11.2 (2019-01-23)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Hotfix to prevent platform from stalling due to API change
Expand Down
17 changes: 0 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ The simplest way to use this package from a terminal is to call ``Blink.start()`
If you would like to log in without setting up the cameras or system, you can simply call the ``Blink.login()`` function which will prompt for a username and password and then authenticate with the server. This is useful if you want to avoid use of the ``start()`` function which simply acts as a wrapper for more targeted API methods.

At initialization, you may also set the logging level of the ``blinkpy`` library like so (default is ``INFO``:

.. code:: python
import logging
from blinkpy import blinkpy
blink = blinkpy.Blink(..., loglevel=logging.<LEVEL>)
blink.start()
You can also disable logging of duplicate entries via the ``allow_duplicate_logs`` flag (default is ``True``):

.. code:: python
from blinkpy import blinkpy
blink = blinkpy.Blink(..., allow_duplicate_logs=False)
blink.start()
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:
Expand Down
33 changes: 3 additions & 30 deletions blinkpy/blinkpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from blinkpy import api
from blinkpy.sync_module import BlinkSyncModule
from blinkpy.helpers import errors as ERROR
from blinkpy.helpers import log
from blinkpy.helpers.util import (
create_session, merge_dicts, get_time, BlinkURLHandler,
BlinkAuthenticationException)
Expand All @@ -35,25 +34,21 @@

REFRESH_RATE = 30

_LOGGER = log.create_logger('blinkpy')
_LOGGER = logging.getLogger(__name__)


class Blink():
"""Class to initialize communication."""

def __init__(self, username=None, password=None,
refresh_rate=REFRESH_RATE, loglevel=logging.INFO,
allow_duplicate_logs=True):
refresh_rate=REFRESH_RATE):
"""
Initialize Blink system.
:param username: Blink username (usually email address)
:param password: Blink password
:param refresh_rate: Refresh rate of blink information.
Defaults to 15 (seconds)
:param loglevel: Sets the log level for the logger.
:param allow_duplicate_logs: Set to 'False' to only allow a log
message to be logged once.
"""
self._username = username
self._password = password
Expand All @@ -74,10 +69,6 @@ def __init__(self, username=None, password=None,
self.video_list = CaseInsensitiveDict({})
self._login_url = LOGIN_URL
self.version = __version__
self.allow_duplicate_logs = allow_duplicate_logs

self.loglevel = loglevel
self._reset_logger()

@property
def auth_header(self):
Expand All @@ -91,8 +82,6 @@ def start(self):
Method logs in and sets auth token, urls, and ids for future requests.
Essentially this is just a wrapper function for ease of use.
"""
self._reset_logger()

if self._username is None or self._password is None:
if not self.login():
return
Expand All @@ -111,7 +100,7 @@ def login(self):
self._username = input("Username:")
self._password = getpass.getpass("Password:")
if self.get_auth_token():
_LOGGER.info("Login successful!")
_LOGGER.debug("Login successful!")
return True
_LOGGER.warning("Unable to login with %s.", self._username)
return False
Expand Down Expand Up @@ -285,19 +274,3 @@ def _parse_downloaded_items(self, result, camera, path):
copyfileobj(response.raw, vidfile)

_LOGGER.info("Downloaded video to %s", filename)

# pylint: disable=no-self-use
def _reset_logger(self):
"""Reset the log handler."""
for handler in _LOGGER.handlers:
_LOGGER.removeHandler(handler)
handler.close()
_LOGGER.setLevel(self.loglevel)
if self.allow_duplicate_logs:
handler = logging.StreamHandler()
handler.setFormatter(log.log_formatter())
else:
handler = log.RepeatLogHandler()
handler.setFormatter(log.log_formatter())

_LOGGER.addHandler(handler)
2 changes: 1 addition & 1 deletion blinkpy/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

MAJOR_VERSION = 0
MINOR_VERSION = 12
PATCH_VERSION = 0
PATCH_VERSION = 1

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

Expand Down
33 changes: 0 additions & 33 deletions blinkpy/helpers/log.py

This file was deleted.

33 changes: 21 additions & 12 deletions tests/test_blink_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ def test_merge_cameras(self, mock_sess):
@mock.patch('blinkpy.blinkpy.api.request_videos')
def test_download_video_exit(self, mock_req, mock_sess):
"""Test we exit method when provided bad response."""
blink = blinkpy.Blink(loglevel=logging.DEBUG)
blink = blinkpy.Blink()
# pylint: disable=protected-access
blinkpy._LOGGER.setLevel(logging.DEBUG)
blink.last_refresh = 0
mock_req.return_value = {}
formatted_date = get_time(blink.last_refresh)
expected_log = [
"INFO:blinkpy:Retrieving videos since {}".format(formatted_date),
"DEBUG:blinkpy:Processing page 1",
"INFO:blinkpy:No videos found on page 1. Exiting."
"INFO:blinkpy.blinkpy:Retrieving videos since {}".format(
formatted_date),
"DEBUG:blinkpy.blinkpy:Processing page 1",
"INFO:blinkpy.blinkpy:No videos found on page 1. Exiting."
]
with self.assertLogs() as dl_log:
blink.download_videos('/tmp')
Expand All @@ -106,7 +109,9 @@ def test_download_video_exit(self, mock_req, mock_sess):
@mock.patch('blinkpy.blinkpy.api.request_videos')
def test_parse_downloaded_items(self, mock_req, mock_sess):
"""Test ability to parse downloaded items list."""
blink = blinkpy.Blink(loglevel=logging.DEBUG)
blink = blinkpy.Blink()
# pylint: disable=protected-access
blinkpy._LOGGER.setLevel(logging.DEBUG)
generic_entry = {
'created_at': '1970',
'camera_name': 'foo',
Expand All @@ -118,9 +123,10 @@ def test_parse_downloaded_items(self, mock_req, mock_sess):
blink.last_refresh = 0
formatted_date = get_time(blink.last_refresh)
expected_log = [
"INFO:blinkpy:Retrieving videos since {}".format(formatted_date),
"DEBUG:blinkpy:Processing page 1",
"DEBUG:blinkpy:foo: /bar.mp4 is marked as deleted."
"INFO:blinkpy.blinkpy:Retrieving videos since {}".format(
formatted_date),
"DEBUG:blinkpy.blinkpy:Processing page 1",
"DEBUG:blinkpy.blinkpy:foo: /bar.mp4 is marked as deleted."
]
with self.assertLogs() as dl_log:
blink.download_videos('/tmp', stop=2)
Expand All @@ -129,7 +135,9 @@ def test_parse_downloaded_items(self, mock_req, mock_sess):
@mock.patch('blinkpy.blinkpy.api.request_videos')
def test_parse_camera_not_in_list(self, mock_req, mock_sess):
"""Test ability to parse downloaded items list."""
blink = blinkpy.Blink(loglevel=logging.DEBUG)
blink = blinkpy.Blink()
# pylint: disable=protected-access
blinkpy._LOGGER.setLevel(logging.DEBUG)
generic_entry = {
'created_at': '1970',
'camera_name': 'foo',
Expand All @@ -141,9 +149,10 @@ def test_parse_camera_not_in_list(self, mock_req, mock_sess):
blink.last_refresh = 0
formatted_date = get_time(blink.last_refresh)
expected_log = [
"INFO:blinkpy:Retrieving videos since {}".format(formatted_date),
"DEBUG:blinkpy:Processing page 1",
"DEBUG:blinkpy:Skipping videos for foo."
"INFO:blinkpy.blinkpy:Retrieving videos since {}".format(
formatted_date),
"DEBUG:blinkpy.blinkpy:Processing page 1",
"DEBUG:blinkpy.blinkpy:Skipping videos for foo."
]
with self.assertLogs() as dl_log:
blink.download_videos('/tmp', camera='bar', stop=2)
Expand Down

0 comments on commit ff8f091

Please sign in to comment.