Skip to content

Commit

Permalink
Merge pull request #549 from fronzbot/dev
Browse files Browse the repository at this point in the history
0.19.0
  • Loading branch information
fronzbot authored Mar 21, 2022
2 parents d78d7e1 + 100d8fa commit 0b60976
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ on:
branches: [ master, dev ]

jobs:
build:
coverage:
runs-on: ${{ matrix.platform }}
strategy:
max-parallel: 4
matrix:
platform:
- ubuntu-latest
python-version: [3.8]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ on:
branches: [ master, dev ]

jobs:
build:

lint:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
platform:
- ubuntu-latest
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
repos:
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 22.1.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((blinkpy|tests)/.+)?[^/]+\.py$
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.9.1
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.5.0
- pydocstyle==5.1.1
- flake8-docstrings==1.6.0
- pydocstyle==6.0.0
files: ^(blinkpy|tests)/.+\.py$
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.0
Expand Down
27 changes: 27 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ Changelog

A list of changes between each release

0.19.0 (2022-03-20)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Bugfixes:**

- Debug log in prase download method fix (`@tieum <https://github.com/fronzbot/blinkpy/pull/540>`__)
- Fix issue with malformed thumbnails (`#550 <https://github.com/fronzbot/blinkpy/pull/550>`__)
- Fully support new thumbnail API (`@gdoermann <https://github.com/fronzbot/blinkpy/pull/552>`__)

**New Features:**

- Support for arm/disarm of Blink Mini cameras (`@mstratford <https://github.com/fronzbot/blinkpy/pull/546>`__)
- Add product_type to BlinkCamera class to report type of camera (`#553 <https://github.com/fronzbot/blinkpy/pull/553>`__)
- Remove python 3.6 support, add python 3.10 support (`#554 <https://github.com/fronzbot/blinkpy/pull/554>`__)

**Other:**

- Make code that determines need for unique class (Mini + Doorbells) generic (`#553 <https://github.com/fronzbot/blinkpy/pull/553>`__)
- Bump pre-commit to 2.17.0
- Bump pytest-timeout to 2.1.0
- Bump pygments to 2.11.2
- Bump black to 22.1.0
- Bump coverage to 6.3.2
- Bump pytest to 7.1.1
- Bump restructuredtext-lint to 1.4.0


0.18.0 (2021-12-11)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VOLUME /media
RUN python -m pip install --upgrade pip
RUN pip3 install blinkpy

COPY app/ .
COPY blinkapp/ .

ENTRYPOINT ["python", "./app.py"]
ENTRYPOINT ["python", "./blinkapp.py"]
CMD []
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
blinkpy |Build Status| |Coverage Status| |Docs| |PyPi Version| |Codestyle|
=============================================================================================
A Python library for the Blink Camera system (Python 3.6+)
A Python library for the Blink Camera system (Python 3.7+)

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

Expand Down
1 change: 0 additions & 1 deletion app/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions blinkapp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Python init file for blinkapp.py."""
4 changes: 2 additions & 2 deletions app/app.py → blinkapp/blinkapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Script to run blinkpy as an app."""
"""Script to run blinkpy as an blinkapp."""
from os import environ
from datetime import datetime, timedelta
from blinkpy.blinkpy import Blink
Expand Down Expand Up @@ -29,7 +29,7 @@ def start():


def main():
"""Run the app."""
"""Run the blink app."""
blink = start()
download_videos(blink)
blink.save(CREDFILE)
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 18 additions & 4 deletions blinkpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


def request_login(
auth, url, login_data, is_retry=False,
auth,
url,
login_data,
is_retry=False,
):
"""
Login request.
Expand Down Expand Up @@ -51,7 +54,11 @@ def request_verify(auth, blink, verify_key):
url = f"{blink.urls.base_url}/api/v4/account/{blink.account_id}/client/{blink.client_id}/pin/verify"
data = dumps({"pin": verify_key})
return auth.query(
url=url, headers=auth.header, data=data, json_resp=False, reqtype="post",
url=url,
headers=auth.header,
data=data,
json_resp=False,
reqtype="post",
)


Expand Down Expand Up @@ -309,14 +316,21 @@ def http_get(blink, url, stream=False, json=True, is_retry=False, timeout=TIMEOU
)


def http_post(blink, url, is_retry=False, timeout=TIMEOUT):
def http_post(blink, url, is_retry=False, data=None, json=True, timeout=TIMEOUT):
"""
Perform an http post request.
:param url: URL to perfom post request.
:param is_retry: Is this part of a re-auth attempt?
:param data: str body for post request
:param json: Return json response? TRUE/False
"""
_LOGGER.debug("Making POST request to %s", url)
return blink.auth.query(
url=url, headers=blink.auth.header, reqtype="post", is_retry=is_retry
url=url,
headers=blink.auth.header,
reqtype="post",
is_retry=is_retry,
json_resp=json,
data=data,
)
10 changes: 8 additions & 2 deletions blinkpy/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ def login(self, login_url=LOGIN_ENDPOINT):
"""Attempt login to blink servers."""
self.validate_login()
_LOGGER.info("Attempting login with %s", login_url)
response = api.request_login(self, login_url, self.data, is_retry=False,)
response = api.request_login(
self,
login_url,
self.data,
is_retry=False,
)
try:
if response.status_code == 200:
return response.json()
Expand Down Expand Up @@ -193,7 +198,8 @@ def query(
return self.validate_response(response, json_resp)
except (exceptions.ConnectionError, exceptions.Timeout):
_LOGGER.error(
"Connection error. Endpoint %s possibly down or throttled.", url,
"Connection error. Endpoint %s possibly down or throttled.",
url,
)
except BlinkBadResponse:
code = None
Expand Down
2 changes: 1 addition & 1 deletion blinkpy/blinkpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def _parse_downloaded_items(self, result, camera, path, delay, debug):
print(
(
f"Camera: {camera_name}, Timestamp: {created_at}, "
"Address: {address}, Filename: {filename}"
f"Address: {address}, Filename: {filename}"
)
)
if delay > 0:
Expand Down
38 changes: 31 additions & 7 deletions blinkpy/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from shutil import copyfileobj
import logging
from json import dumps
from requests.compat import urljoin
from blinkpy import api
from blinkpy.helpers.constants import TIMEOUT_MEDIA

Expand Down Expand Up @@ -31,6 +33,7 @@ def __init__(self, sync):
self._cached_image = None
self._cached_video = None
self.camera_type = ""
self.product_type = None

@property
def attributes(self):
Expand All @@ -52,6 +55,7 @@ def attributes(self):
"network_id": self.sync.network_id,
"sync_module": self.sync.name,
"last_record": self.last_record,
"type": self.product_type,
}
return attributes

Expand Down Expand Up @@ -108,7 +112,11 @@ def get_media(self, media_type="image"):
if media_type.lower() == "video":
url = self.clip
return api.http_get(
self.sync.blink, url=url, stream=True, json=False, timeout=TIMEOUT_MEDIA,
self.sync.blink,
url=url,
stream=True,
json=False,
timeout=TIMEOUT_MEDIA,
)

def snap_picture(self):
Expand Down Expand Up @@ -145,6 +153,7 @@ def extract_config_info(self, config):
self.battery_state = config.get("battery_state", None)
self.temperature = config.get("temperature", None)
self.wifi_strength = config.get("wifi_strength", None)
self.product_type = config.get("type", None)

def get_sensor_info(self):
"""Retrieve calibrated temperatue from special endpoint."""
Expand All @@ -161,14 +170,29 @@ def update_images(self, config, force_cache=False):
"""Update images for camera."""
new_thumbnail = None
thumb_addr = None
thumb_string = None
if config.get("thumbnail", False):
thumb_addr = config["thumbnail"]
try:
# API update only returns the timestamp!
int(thumb_addr)
thumb_string = f"/api/v3/media/accounts/{self.sync.blink.account_id}/networks/{self.network_id}/{self.product_type}/{self.camera_id}/thumbnail/thumbnail.jpg?ts={thumb_addr}&ext="
except ValueError:
# This is the old API and has the full url
thumb_string = f"{thumb_addr}.jpg"
# Check that new full api url has not been returned:
if thumb_addr.endswith("&ext="):
thumb_string = thumb_addr
except TypeError:
# Thumb address is None
pass

if thumb_string is not None:
new_thumbnail = urljoin(self.sync.urls.base_url, thumb_string)

else:
_LOGGER.warning("Could not find thumbnail for camera %s", self.name)

if thumb_addr is not None:
new_thumbnail = f"{self.sync.urls.base_url}{thumb_addr}.jpg"

try:
self.motion_detected = self.sync.motion[self.name]
except KeyError:
Expand Down Expand Up @@ -252,9 +276,9 @@ def arm(self):
@arm.setter
def arm(self, value):
"""Set camera arm status."""
_LOGGER.warning(
"Individual camera motion detection enable/disable for Blink Mini cameras is unsupported at this time."
)
url = f"{self.sync.urls.base_url}/api/v1/accounts/{self.sync.blink.account_id}/networks/{self.network_id}/owls/{self.camera_id}/config"
data = dumps({"enabled": value})
return api.http_post(self.sync.blink, url, json=False, data=data)

def snap_picture(self):
"""Snap picture for a blink mini camera."""
Expand Down
6 changes: 3 additions & 3 deletions blinkpy/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import os

MAJOR_VERSION = 0
MINOR_VERSION = 18
MINOR_VERSION = 19
PATCH_VERSION = 0

__version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"

REQUIRED_PYTHON_VER = (3, 6, 0)
REQUIRED_PYTHON_VER = (3, 7, 0)

PROJECT_NAME = "blinkpy"
PROJECT_PACKAGE_NAME = "blinkpy"
Expand All @@ -31,10 +31,10 @@
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Home Automation",
]

Expand Down
Loading

0 comments on commit 0b60976

Please sign in to comment.