From 21f29ad302072d16efdc8205aaba826013e69176 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 11 Dec 2021 22:40:48 -0500 Subject: [PATCH 01/42] dev version bump --- blinkpy/helpers/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 7bb48508..cdb3c205 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -3,8 +3,8 @@ import os MAJOR_VERSION = 0 -MINOR_VERSION = 18 -PATCH_VERSION = 0 +MINOR_VERSION = 19 +PATCH_VERSION = "0.dev0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From 6d7503c4dfd5c54d253d35363eb0661752466d79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Jan 2022 18:13:27 +0000 Subject: [PATCH 02/42] Bump pygments from 2.10.0 to 2.11.2 Bumps [pygments](https://github.com/pygments/pygments) from 2.10.0 to 2.11.2. - [Release notes](https://github.com/pygments/pygments/releases) - [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES) - [Commits](https://github.com/pygments/pygments/compare/2.10.0...2.11.2) --- updated-dependencies: - dependency-name: pygments dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index c10bab75..16f3c8d8 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -10,5 +10,5 @@ pytest-cov==3.0.0 pytest-sugar==0.9.4 pytest-timeout==1.4.2 restructuredtext-lint==1.3.2 -pygments==2.10.0 +pygments==2.11.2 testtools>=2.4.0 From be53c959519acd0b026fd41775bfb251f1f5d3c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jan 2022 18:10:28 +0000 Subject: [PATCH 03/42] Bump pre-commit from 2.15.0 to 2.17.0 Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 2.15.0 to 2.17.0. - [Release notes](https://github.com/pre-commit/pre-commit/releases) - [Changelog](https://github.com/pre-commit/pre-commit/blob/master/CHANGELOG.md) - [Commits](https://github.com/pre-commit/pre-commit/compare/v2.15.0...v2.17.0) --- updated-dependencies: - dependency-name: pre-commit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index c10bab75..148ccd40 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -2,7 +2,7 @@ black==19.10b0 coverage==5.5 flake8==3.9.1 flake8-docstrings==1.6.0 -pre-commit==2.15.0 +pre-commit==2.17.0 pylint==2.10.2 pydocstyle==6.0.0 pytest==6.2.5 From fa07fefd9d68c827f16d193ca8af4dd7095167f8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jan 2022 18:10:32 +0000 Subject: [PATCH 04/42] Bump pytest-timeout from 1.4.2 to 2.1.0 Bumps [pytest-timeout](https://github.com/pytest-dev/pytest-timeout) from 1.4.2 to 2.1.0. - [Release notes](https://github.com/pytest-dev/pytest-timeout/releases) - [Commits](https://github.com/pytest-dev/pytest-timeout/compare/1.4.2...2.1.0) --- updated-dependencies: - dependency-name: pytest-timeout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index c10bab75..c7bb4b3a 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -8,7 +8,7 @@ pydocstyle==6.0.0 pytest==6.2.5 pytest-cov==3.0.0 pytest-sugar==0.9.4 -pytest-timeout==1.4.2 +pytest-timeout==2.1.0 restructuredtext-lint==1.3.2 pygments==2.10.0 testtools>=2.4.0 From 5a79d191744d5a4cb04f407ebb4bfd75d2735982 Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Wed, 19 Jan 2022 16:29:14 -0700 Subject: [PATCH 05/42] Renamed ./app and ./app/app.py to ./blinkapp and ./blinkapp/blinkapp.py respectively. All tests passed. Have a top level app.py causes massive issues with Chalice, which imports and uses a top level app to handle all routing. --- Dockerfile | 4 ++-- app/__init__.py | 1 - blinkapp/__init__.py | 1 + app/app.py => blinkapp/blinkapp.py | 4 ++-- {app => blinkapp}/build.sh | 0 {app => blinkapp}/run.sh | 0 tox.ini | 26 +++++++++++++------------- 7 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 app/__init__.py create mode 100644 blinkapp/__init__.py rename app/app.py => blinkapp/blinkapp.py (91%) rename {app => blinkapp}/build.sh (100%) rename {app => blinkapp}/run.sh (100%) diff --git a/Dockerfile b/Dockerfile index 02ccf085..1a40c5d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 [] diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index 099ec593..00000000 --- a/app/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Python init file for app.py.""" diff --git a/blinkapp/__init__.py b/blinkapp/__init__.py new file mode 100644 index 00000000..15586a6f --- /dev/null +++ b/blinkapp/__init__.py @@ -0,0 +1 @@ +"""Python init file for blinkapp.py.""" diff --git a/app/app.py b/blinkapp/blinkapp.py similarity index 91% rename from app/app.py rename to blinkapp/blinkapp.py index 081bcdfc..af6c5018 100644 --- a/app/app.py +++ b/blinkapp/blinkapp.py @@ -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 @@ -29,7 +29,7 @@ def start(): def main(): - """Run the app.""" + """Run the blink app.""" blink = start() download_videos(blink) blink.save(CREDFILE) diff --git a/app/build.sh b/blinkapp/build.sh similarity index 100% rename from app/build.sh rename to blinkapp/build.sh diff --git a/app/run.sh b/blinkapp/run.sh similarity index 100% rename from app/run.sh rename to blinkapp/run.sh diff --git a/tox.ini b/tox.ini index dcc71120..3669f624 100644 --- a/tox.ini +++ b/tox.ini @@ -7,40 +7,40 @@ skipsdist = True setenv = LANG=en_US.UTF-8 PYTHONPATH = {toxinidir} -commands = +commands = pytest --timeout=9 --durations=10 --cov=blinkpy --cov-report term-missing {posargs} -deps = +deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt [testenv:cov] -setenv = +setenv = LANG=en_US.UTF-8 PYTHONPATH = {toxinidir} -commands = +commands = pytest --timeout=9 --durations=10 --cov=blinkpy --cov-report=xml {posargs} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt [testenv:pylint] -deps = +deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt basepython = python3 ignore_errors = True -commands = - pylint --rcfile={toxinidir}/pylintrc blinkpy tests app +commands = + pylint --rcfile={toxinidir}/pylintrc blinkpy tests blinkapp [testenv:lint] -deps = +deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt basepython = python3 -commands = - flake8 blinkpy tests app - pydocstyle blinkpy tests app - black --check --diff blinkpy tests app +commands = + flake8 blinkpy tests blinkapp + pydocstyle blinkpy tests blinkapp + black --check --diff blinkpy tests blinkapp rst-lint README.rst CHANGES.rst CONTRIBUTING.rst [testenv:build] @@ -51,7 +51,7 @@ whitelist_externals = /bin/rm deps = -r{toxinidir}/requirements_test.txt -commands = +commands = /bin/rm -rf build dist python setup.py bdist_wheel /bin/sh -c "pip install --upgrade dist/*.whl" From 441b95033a01337a878bc68d7e3d7f3db4cf714a Mon Sep 17 00:00:00 2001 From: Matthieu Simon Date: Sat, 22 Jan 2022 12:45:13 +0100 Subject: [PATCH 06/42] fix debug message in _parse_downloaded_items --- blinkpy/blinkpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index c3168751..41f3220e 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -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: From 4c749d2e677e5057da459aa4c0749513028f8285 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Jan 2022 18:13:03 +0000 Subject: [PATCH 07/42] Bump black from 19.10b0 to 22.1.0 Bumps [black](https://github.com/psf/black) from 19.10b0 to 22.1.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/commits/22.1.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index d49d7cb2..13043eac 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,4 +1,4 @@ -black==19.10b0 +black==22.1.0 coverage==5.5 flake8==3.9.1 flake8-docstrings==1.6.0 From 1416fcbff353191ac7e3e61fa68a8777fd5e8cbd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 18:13:24 +0000 Subject: [PATCH 08/42] Bump pytest from 6.2.5 to 7.0.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.5 to 7.0.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.2.5...7.0.1) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index d49d7cb2..6bce1a0b 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -5,7 +5,7 @@ flake8-docstrings==1.6.0 pre-commit==2.17.0 pylint==2.10.2 pydocstyle==6.0.0 -pytest==6.2.5 +pytest==7.0.1 pytest-cov==3.0.0 pytest-sugar==0.9.4 pytest-timeout==2.1.0 From a07e19c252c34eb74aa658ba06928a615d6db985 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 18 Feb 2022 20:51:33 +0000 Subject: [PATCH 09/42] Add @macleajb 's Blink Mini arm command with refactor. --- blinkpy/api.py | 5 +++-- blinkpy/camera.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/blinkpy/api.py b/blinkpy/api.py index 3df449a4..cce2e193 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -309,14 +309,15 @@ 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 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 ) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 29ceec8e..0c8721ef 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -4,7 +4,7 @@ import logging from blinkpy import api from blinkpy.helpers.constants import TIMEOUT_MEDIA - +from json import dumps _LOGGER = logging.getLogger(__name__) @@ -252,9 +252,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.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.""" From 436c29297adfbee329b7bc32f070aa4b7fd3862d Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 18 Feb 2022 21:10:41 +0000 Subject: [PATCH 10/42] Fix typo --- blinkpy/camera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 0c8721ef..d696fb93 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -252,7 +252,7 @@ def arm(self): @arm.setter def arm(self, value): """Set camera arm status.""" - url = f"{self.sync.urls.base_url}/api/v1/accounts/{self.sync.account_id}/networks/{self.network_id}/owls/{self.camera_id}/config" + 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) From 4d180e1742bb9d217e99920da1aa9615279106cb Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 18 Feb 2022 21:11:30 +0000 Subject: [PATCH 11/42] Add another param. --- blinkpy/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/blinkpy/api.py b/blinkpy/api.py index cce2e193..d62a93cc 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -315,6 +315,7 @@ def http_post(blink, url, is_retry=False, data=None, json=True, timeout=TIMEOUT) :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) From bf452111e48dba7416ed6ff8e484aa6ab3c4b214 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 18 Feb 2022 21:22:40 +0000 Subject: [PATCH 12/42] Tox fixes --- blinkpy/api.py | 7 ++++++- blinkpy/camera.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/blinkpy/api.py b/blinkpy/api.py index d62a93cc..cce74706 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -320,5 +320,10 @@ def http_post(blink, url, is_retry=False, data=None, json=True, timeout=TIMEOUT) """ _LOGGER.debug("Making POST request to %s", url) return blink.auth.query( - url=url, headers=blink.auth.header, reqtype="post", is_retry=is_retry, json_resp=json, data=data + url=url, + headers=blink.auth.header, + reqtype="post", + is_retry=is_retry, + json_resp=json, + data=data, ) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index d696fb93..893332b2 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -5,6 +5,7 @@ from blinkpy import api from blinkpy.helpers.constants import TIMEOUT_MEDIA from json import dumps + _LOGGER = logging.getLogger(__name__) From 519bcecfc20286ed331606f0c26113dd3a2275b1 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 5 Mar 2022 18:59:56 -0500 Subject: [PATCH 13/42] Use urljoin to create thumbnail string --- blinkpy/camera.py | 5 +++-- tests/test_cameras.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 893332b2..9e7f598b 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -2,9 +2,10 @@ 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 -from json import dumps _LOGGER = logging.getLogger(__name__) @@ -168,7 +169,7 @@ def update_images(self, config, force_cache=False): _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" + new_thumbnail = urljoin(self.sync.urls.base_url, f"{thumb_addr}.jpg") try: self.motion_detected = self.sync.motion[self.name] diff --git a/tests/test_cameras.py b/tests/test_cameras.py index e482a72a..73d9839f 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -87,6 +87,14 @@ def test_camera_update(self, mock_resp): self.assertEqual(self.camera.image_from_cache, "test") self.assertEqual(self.camera.video_from_cache, "foobar") + # Check that thumbnail without slash processed properly + mock_resp.side_effect = [None] + self.camera.update_images({"thumbnail": "thumb_no_slash"}) + self.assertEqual( + self.camera.thumbnail, + "https://rest-test.immedia-semi.com/thumb_no_slash.jpg", + ) + def test_no_thumbnails(self, mock_resp): """Tests that thumbnail is 'None' if none found.""" mock_resp.return_value = "foobar" From 18a57b39e7230411f898779b126e28952c980681 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 5 Mar 2022 19:08:56 -0500 Subject: [PATCH 14/42] Version bump for RC0 --- blinkpy/helpers/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index cdb3c205..dd7bfce6 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "0.dev0" +PATCH_VERSION = "0.rc0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From bd8b206a2927bde37856bf4154529e9dd7a2b19f Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 5 Mar 2022 19:14:07 -0500 Subject: [PATCH 15/42] Update CHANGES.rst --- CHANGES.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 3678aa38..043d5bf8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,26 @@ Changelog A list of changes between each release +0.19.0 (pre-release) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**Bugfixes:** + +- Debug log in prase download method fix (`@tieum `__) +- Fix issue with malformed thumbnails (`#550 `__) + +**New Features:** + +- Support for arm/disarm of Blink Mini cameras (`@mstratford `__) + +**Other:** + +- Bump pre-commit to 2.17.0 +- Bump pytest to 7.0.1 +- Bump pytest-timeout to 2.1.0 +- Bump pygments to 2.11.2 + + 0.18.0 (2021-12-11) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 989589e72e987f5d0f6057d4eb159e24f29daf68 Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Fri, 11 Mar 2022 14:49:27 -0700 Subject: [PATCH 16/42] Figured out the blink lambda api changes. We need to resolve the URL from the timestamp because they no longer send the full url to the thumbnail in the camera config. --- blinkpy/camera.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 9e7f598b..9c54cda1 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -10,6 +10,10 @@ _LOGGER = logging.getLogger(__name__) +THUMBNAIL_URL = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/thumbnail.jpg?" \ + "ts={thumbnail}&ext=" + + class BlinkCamera: """Class to initialize individual camera.""" @@ -167,6 +171,13 @@ def update_images(self, config, force_cache=False): thumb_addr = config["thumbnail"] else: _LOGGER.warning("Could not find thumbnail for camera %s", self.name) + try: + # API update only returns the timestamp! + int(thumb_addr) + thumb_addr = THUMBNAIL_URL.format(**config) + except TypeError: + # This is the old API and has the full url + pass if thumb_addr is not None: new_thumbnail = urljoin(self.sync.urls.base_url, f"{thumb_addr}.jpg") From 56ce8e2bd13b446f76232a2853cb486d79cac73f Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Fri, 11 Mar 2022 15:33:00 -0700 Subject: [PATCH 17/42] Version bump and moved thumbnail endpoint to helper constants --- blinkpy/camera.py | 6 ++---- blinkpy/helpers/constants.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 9c54cda1..a962c809 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -5,13 +5,11 @@ from json import dumps from requests.compat import urljoin from blinkpy import api -from blinkpy.helpers.constants import TIMEOUT_MEDIA +from blinkpy.helpers.constants import TIMEOUT_MEDIA, THUMBNAIL_ENDPOINT _LOGGER = logging.getLogger(__name__) -THUMBNAIL_URL = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/thumbnail.jpg?" \ - "ts={thumbnail}&ext=" class BlinkCamera: @@ -174,7 +172,7 @@ def update_images(self, config, force_cache=False): try: # API update only returns the timestamp! int(thumb_addr) - thumb_addr = THUMBNAIL_URL.format(**config) + thumb_addr = THUMBNAIL_ENDPOINT.format(**config) except TypeError: # This is the old API and has the full url pass diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index dd7bfce6..8c44d6ef 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "0.rc0" +PATCH_VERSION = "1.rc0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" @@ -50,6 +50,8 @@ DEFAULT_URL = f"rest-prod.{BLINK_URL}" BASE_URL = f"https://{DEFAULT_URL}" LOGIN_ENDPOINT = f"{BASE_URL}/api/v5/account/login" +THUMBNAIL_ENDPOINT = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/" \ + "thumbnail.jpg?ts={thumbnail}&ext=" """ Dictionaries From 8ac095c6d8f9939b3ebd34675f9194d21bb9d2c5 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:00:25 -0500 Subject: [PATCH 18/42] Refactored code to extract doorbell/owl and added product_type attribute to cameras --- blinkpy/camera.py | 3 +++ blinkpy/sync_module.py | 54 ++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 9e7f598b..cd28097d 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -33,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): @@ -54,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 @@ -147,6 +149,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.""" diff --git a/blinkpy/sync_module.py b/blinkpy/sync_module.py index 2730de5a..ce6d6386 100644 --- a/blinkpy/sync_module.py +++ b/blinkpy/sync_module.py @@ -37,6 +37,10 @@ def __init__(self, blink, network_name, network_id, camera_list): self.last_record = {} self.camera_list = camera_list self.available = False + self.type_key_map = { + "mini": "owls", + "lotus": "doorbell", + } @property def attributes(self): @@ -118,6 +122,10 @@ def sync_initialize(self): def update_cameras(self, camera_type=BlinkCamera): """Update cameras from server.""" + type_map = { + "mini": BlinkCameraMini, + "lotus": BlinkDoorbell, + } try: for camera_config in self.camera_list: if "name" not in camera_config: @@ -125,15 +133,12 @@ def update_cameras(self, camera_type=BlinkCamera): blink_camera_type = camera_config.get("type", "") name = camera_config["name"] self.motion[name] = False - owl_info = self.get_owl_info(name) - lotus_info = self.get_lotus_info(name) - if blink_camera_type == "mini": - camera_type = BlinkCameraMini - if blink_camera_type == "lotus": - camera_type = BlinkDoorbell + unique_info = self.get_unique_info(name) + if blink_camera_type in type_map.keys(): + camera_type = type_map[blink_camera_type] self.cameras[name] = camera_type(self) camera_info = self.get_camera_info( - camera_config["id"], owl_info=owl_info, lotus_info=lotus_info + camera_config["id"], unique_info=unique_info ) self.cameras[name].update(camera_info, force_cache=True, force=True) @@ -142,22 +147,14 @@ def update_cameras(self, camera_type=BlinkCamera): return False return True - def get_owl_info(self, name): - """Extract owl information.""" + def get_unique_info(self, name): + """Extract unique information for Minis and Doorbells.""" try: - for owl in self.blink.homescreen["owls"]: - if owl["name"] == name: - return owl - except (TypeError, KeyError): - pass - return None - - def get_lotus_info(self, name): - """Extract lotus information.""" - try: - for doorbell in self.blink.homescreen["doorbells"]: - if doorbell["name"] == name: - return doorbell + for camera_type in self.type_key_map: + type_key = self.type_key_map[camera_type] + for device in self.blink.homescreen[type_key]: + if device["name"] == name: + return device except (TypeError, KeyError): pass return None @@ -174,12 +171,9 @@ def get_events(self, **kwargs): def get_camera_info(self, camera_id, **kwargs): """Retrieve camera information.""" - owl = kwargs.get("owl_info", None) - if owl is not None: - return owl - lotus = kwargs.get("lotus_info", None) - if lotus is not None: - return lotus + unique = kwargs.get("unique_info", None) + if unique is not None: + return unique response = api.request_camera_info(self.blink, self.network_id, camera_id) try: return response["camera"][0] @@ -206,9 +200,7 @@ def refresh(self, force_cache=False): for camera_name in self.cameras.keys(): camera_id = self.cameras[camera_name].camera_id camera_info = self.get_camera_info( - camera_id, - owl_info=self.get_owl_info(camera_name), - lotus_info=self.get_lotus_info(camera_name), + camera_id, unique_info=self.get_unique_info(camera_name), ) self.cameras[camera_name].update(camera_info, force_cache=force_cache) self.available = True From 5bd10584f372add237afdb95771d5938e0018a76 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:17:50 -0500 Subject: [PATCH 19/42] Updated files based on new black version --- .pre-commit-config.yaml | 8 ++++---- blinkpy/api.py | 11 +++++++++-- blinkpy/auth.py | 10 ++++++++-- blinkpy/camera.py | 6 +++++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 98d80a3a..bebf31fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.1.0 hooks: - id: black args: @@ -8,12 +8,12 @@ repos: - --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 diff --git a/blinkpy/api.py b/blinkpy/api.py index 3df449a4..ba9fb109 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -11,7 +11,10 @@ def request_login( - auth, url, login_data, is_retry=False, + auth, + url, + login_data, + is_retry=False, ): """ Login request. @@ -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", ) diff --git a/blinkpy/auth.py b/blinkpy/auth.py index 3e78c134..a7e11f85 100644 --- a/blinkpy/auth.py +++ b/blinkpy/auth.py @@ -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() @@ -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 diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 29ceec8e..f3acd17f 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -108,7 +108,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): From b4eed430cd8c8fdbf34877bb383e2305af48d75e Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:30:32 -0500 Subject: [PATCH 20/42] Split out black into own action, rename workflows --- .github/workflows/black.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/coverage.yml | 2 +- .github/workflows/lint.yml | 3 +-- tox.ini | 11 +++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 00000000..028c7215 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,32 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Black + +on: + push: + branches: [ master, dev ] + pull_request: + branches: [ master, dev ] + +jobs: + black: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_test.txt + pip install tox + - name: Black + run: | + tox -r -e black diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ddb7c9ce..44f093fa 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -7,7 +7,7 @@ on: branches: [ master, dev ] jobs: - build: + coverage: runs-on: ${{ matrix.platform }} strategy: max-parallel: 4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b19ea603..9ab94725 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,8 +10,7 @@ on: branches: [ master, dev ] jobs: - build: - + lint: runs-on: ubuntu-latest strategy: matrix: diff --git a/tox.ini b/tox.ini index dcc71120..9f82162a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = build, py36, py37, py38, py39, lint +envlist = build, py36, py37, py38, py39, lint, black skip_missing_interpreters = True skipsdist = True @@ -40,9 +40,16 @@ basepython = python3 commands = flake8 blinkpy tests app pydocstyle blinkpy tests app - black --check --diff blinkpy tests app rst-lint README.rst CHANGES.rst CONTRIBUTING.rst +[testenv:black] +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/requirements_test.txt +basepython = python3 +commands = + black --check --diff blinkpy tests app + [testenv:build] recreate = True skip_install = True From 3d99f41930879d74a8762473dbebf7224fb3cdbd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Jan 2022 18:13:03 +0000 Subject: [PATCH 21/42] Bump black from 19.10b0 to 22.1.0 Bumps [black](https://github.com/psf/black) from 19.10b0 to 22.1.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/commits/22.1.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 6bce1a0b..362c8770 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,4 +1,4 @@ -black==19.10b0 +black==22.1.0 coverage==5.5 flake8==3.9.1 flake8-docstrings==1.6.0 From 7eb2068cec6f22e282b256daa1d6dcae11bf33f3 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:17:50 -0500 Subject: [PATCH 22/42] Updated files based on new black version --- .pre-commit-config.yaml | 8 ++++---- blinkpy/api.py | 11 +++++++++-- blinkpy/auth.py | 10 ++++++++-- blinkpy/camera.py | 6 +++++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 98d80a3a..bebf31fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.1.0 hooks: - id: black args: @@ -8,12 +8,12 @@ repos: - --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 diff --git a/blinkpy/api.py b/blinkpy/api.py index cce74706..ac6dfe90 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -11,7 +11,10 @@ def request_login( - auth, url, login_data, is_retry=False, + auth, + url, + login_data, + is_retry=False, ): """ Login request. @@ -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", ) diff --git a/blinkpy/auth.py b/blinkpy/auth.py index 3e78c134..a7e11f85 100644 --- a/blinkpy/auth.py +++ b/blinkpy/auth.py @@ -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() @@ -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 diff --git a/blinkpy/camera.py b/blinkpy/camera.py index cd28097d..c7953f74 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -112,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): From 9e4a30a570e9a6fd557ac6c0c00086f86e91395d Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:30:32 -0500 Subject: [PATCH 23/42] Split out black into own action, rename workflows --- .github/workflows/black.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/coverage.yml | 2 +- .github/workflows/lint.yml | 3 +-- tox.ini | 11 +++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 00000000..028c7215 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,32 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Black + +on: + push: + branches: [ master, dev ] + pull_request: + branches: [ master, dev ] + +jobs: + black: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_test.txt + pip install tox + - name: Black + run: | + tox -r -e black diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ddb7c9ce..44f093fa 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -7,7 +7,7 @@ on: branches: [ master, dev ] jobs: - build: + coverage: runs-on: ${{ matrix.platform }} strategy: max-parallel: 4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b19ea603..9ab94725 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,8 +10,7 @@ on: branches: [ master, dev ] jobs: - build: - + lint: runs-on: ubuntu-latest strategy: matrix: diff --git a/tox.ini b/tox.ini index dcc71120..9f82162a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = build, py36, py37, py38, py39, lint +envlist = build, py36, py37, py38, py39, lint, black skip_missing_interpreters = True skipsdist = True @@ -40,9 +40,16 @@ basepython = python3 commands = flake8 blinkpy tests app pydocstyle blinkpy tests app - black --check --diff blinkpy tests app rst-lint README.rst CHANGES.rst CONTRIBUTING.rst +[testenv:black] +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/requirements_test.txt +basepython = python3 +commands = + black --check --diff blinkpy tests app + [testenv:build] recreate = True skip_install = True From 5f7479f037310f49aecc209ce8ef1f37176bc938 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:36:44 -0500 Subject: [PATCH 24/42] Reverted workflows, finally fixed file black was complaining about --- .github/workflows/black.yml | 32 -------------------------------- blinkpy/sync_module.py | 3 ++- tox.ini | 11 ++--------- 3 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 028c7215..00000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Black - -on: - push: - branches: [ master, dev ] - pull_request: - branches: [ master, dev ] - -jobs: - black: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.9] - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements_test.txt - pip install tox - - name: Black - run: | - tox -r -e black diff --git a/blinkpy/sync_module.py b/blinkpy/sync_module.py index ce6d6386..0e37702a 100644 --- a/blinkpy/sync_module.py +++ b/blinkpy/sync_module.py @@ -200,7 +200,8 @@ def refresh(self, force_cache=False): for camera_name in self.cameras.keys(): camera_id = self.cameras[camera_name].camera_id camera_info = self.get_camera_info( - camera_id, unique_info=self.get_unique_info(camera_name), + camera_id, + unique_info=self.get_unique_info(camera_name), ) self.cameras[camera_name].update(camera_info, force_cache=force_cache) self.available = True diff --git a/tox.ini b/tox.ini index 9f82162a..dcc71120 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = build, py36, py37, py38, py39, lint, black +envlist = build, py36, py37, py38, py39, lint skip_missing_interpreters = True skipsdist = True @@ -40,15 +40,8 @@ basepython = python3 commands = flake8 blinkpy tests app pydocstyle blinkpy tests app - rst-lint README.rst CHANGES.rst CONTRIBUTING.rst - -[testenv:black] -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/requirements_test.txt -basepython = python3 -commands = black --check --diff blinkpy tests app + rst-lint README.rst CHANGES.rst CONTRIBUTING.rst [testenv:build] recreate = True From 5b332295e56edaae06cf0cfe4b4fb3ef50f7cf13 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 12:39:14 -0500 Subject: [PATCH 25/42] Put black back into lint flow --- .github/workflows/black.yml | 32 -------------------------------- tox.ini | 11 ++--------- 2 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 028c7215..00000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Black - -on: - push: - branches: [ master, dev ] - pull_request: - branches: [ master, dev ] - -jobs: - black: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.9] - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements_test.txt - pip install tox - - name: Black - run: | - tox -r -e black diff --git a/tox.ini b/tox.ini index 9f82162a..dcc71120 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = build, py36, py37, py38, py39, lint, black +envlist = build, py36, py37, py38, py39, lint skip_missing_interpreters = True skipsdist = True @@ -40,15 +40,8 @@ basepython = python3 commands = flake8 blinkpy tests app pydocstyle blinkpy tests app - rst-lint README.rst CHANGES.rst CONTRIBUTING.rst - -[testenv:black] -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/requirements_test.txt -basepython = python3 -commands = black --check --diff blinkpy tests app + rst-lint README.rst CHANGES.rst CONTRIBUTING.rst [testenv:build] recreate = True From 8a3262b18908782c73f31f163d0cc0503721f257 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 13:13:21 -0500 Subject: [PATCH 26/42] Remove python 3.6 support, add 3.10 --- .github/workflows/coverage.yml | 2 +- .github/workflows/tests.yml | 2 +- README.rst | 2 +- blinkpy/helpers/constants.py | 5 +++-- tox.ini | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 44f093fa..8715bf2d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -14,7 +14,7 @@ jobs: matrix: platform: - ubuntu-latest - python-version: [3.8] + python-version: [3.9] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e64154b..c9452ecb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/README.rst b/README.rst index 7fcd6d96..f52b8606 100644 --- a/README.rst +++ b/README.rst @@ -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! diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index dd7bfce6..7946a508 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -8,7 +8,7 @@ __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" @@ -31,10 +31,11 @@ "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", + "Programming Language :: Python :: 3.11", "Topic :: Home Automation", ] diff --git a/tox.ini b/tox.ini index dcc71120..f24f7748 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = build, py36, py37, py38, py39, lint +envlist = build, py37, py38, py39, py310, lint skip_missing_interpreters = True skipsdist = True From 4990b384f654c6ca9efc0e1bff9b6cd2da08e6e5 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 13:14:31 -0500 Subject: [PATCH 27/42] Update constants.py --- blinkpy/helpers/constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 7946a508..85a3a40a 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -35,7 +35,6 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", "Topic :: Home Automation", ] From af8aa191913b6d1451fe57692601676d435c73df Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 13:16:03 -0500 Subject: [PATCH 28/42] Wrap versions in strings --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c9452ecb..9880c996 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: matrix: platform: - ubuntu-latest - python-version: [3.7, 3.8, 3.9, 3.10] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 From c88f8a47e226a6bb0778345cdb3e88f317a4c772 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 13:31:04 -0500 Subject: [PATCH 29/42] Use assertListEqual instead of assertEqual --- tests/test_blink_functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_blink_functions.py b/tests/test_blink_functions.py index c4c7d7c6..33b7c2a1 100644 --- a/tests/test_blink_functions.py +++ b/tests/test_blink_functions.py @@ -65,7 +65,7 @@ def test_download_video_exit(self, mock_req): ] with self.assertLogs() as dl_log: blink.download_videos("/tmp") - self.assertEqual(dl_log.output, expected_log) + self.assertListEqual(dl_log.output, expected_log) @mock.patch("blinkpy.blinkpy.api.request_videos") def test_parse_downloaded_items(self, mock_req): @@ -90,7 +90,7 @@ def test_parse_downloaded_items(self, mock_req): ] with self.assertLogs() as dl_log: blink.download_videos("/tmp", stop=2, delay=0) - self.assertEqual(dl_log.output, expected_log) + self.assertListEqual(dl_log.output, expected_log) @mock.patch("blinkpy.blinkpy.api.request_videos") def test_parse_downloaded_throttle(self, mock_req): @@ -139,7 +139,7 @@ def test_parse_camera_not_in_list(self, mock_req): ] with self.assertLogs() as dl_log: blink.download_videos("/tmp", camera="bar", stop=2, delay=0) - self.assertEqual(dl_log.output, expected_log) + self.assertListEqual(dl_log.output, expected_log) @mock.patch("blinkpy.blinkpy.api.request_network_update") @mock.patch("blinkpy.auth.Auth.query") From cb404d19effa5d50ee86a7b6dd6ec33876bcf0c6 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 12 Mar 2022 13:54:14 -0500 Subject: [PATCH 30/42] Use assertLogs with level --- tests/test_blink_functions.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/test_blink_functions.py b/tests/test_blink_functions.py index 33b7c2a1..2879bb74 100644 --- a/tests/test_blink_functions.py +++ b/tests/test_blink_functions.py @@ -1,7 +1,6 @@ """Tests camera and system functions.""" import unittest from unittest import mock -import logging import time from blinkpy import blinkpy @@ -53,8 +52,6 @@ def test_merge_cameras(self): def test_download_video_exit(self, mock_req): """Test we exit method when provided bad response.""" 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) @@ -63,7 +60,7 @@ def test_download_video_exit(self, mock_req): "DEBUG:blinkpy.blinkpy:Processing page 1", "INFO:blinkpy.blinkpy:No videos found on page 1. Exiting.", ] - with self.assertLogs() as dl_log: + with self.assertLogs(level="DEBUG") as dl_log: blink.download_videos("/tmp") self.assertListEqual(dl_log.output, expected_log) @@ -71,8 +68,6 @@ def test_download_video_exit(self, mock_req): def test_parse_downloaded_items(self, mock_req): """Test ability to parse downloaded items list.""" blink = blinkpy.Blink() - # pylint: disable=protected-access - blinkpy._LOGGER.setLevel(logging.DEBUG) generic_entry = { "created_at": "1970", "device_name": "foo", @@ -88,7 +83,7 @@ def test_parse_downloaded_items(self, mock_req): "DEBUG:blinkpy.blinkpy:Processing page 1", "DEBUG:blinkpy.blinkpy:foo: /bar.mp4 is marked as deleted.", ] - with self.assertLogs() as dl_log: + with self.assertLogs(level="DEBUG") as dl_log: blink.download_videos("/tmp", stop=2, delay=0) self.assertListEqual(dl_log.output, expected_log) @@ -120,8 +115,6 @@ def test_parse_downloaded_throttle(self, mock_req): def test_parse_camera_not_in_list(self, mock_req): """Test ability to parse downloaded items list.""" blink = blinkpy.Blink() - # pylint: disable=protected-access - blinkpy._LOGGER.setLevel(logging.DEBUG) generic_entry = { "created_at": "1970", "device_name": "foo", @@ -137,7 +130,7 @@ def test_parse_camera_not_in_list(self, mock_req): "DEBUG:blinkpy.blinkpy:Processing page 1", "DEBUG:blinkpy.blinkpy:Skipping videos for foo.", ] - with self.assertLogs() as dl_log: + with self.assertLogs(level="DEBUG") as dl_log: blink.download_videos("/tmp", camera="bar", stop=2, delay=0) self.assertListEqual(dl_log.output, expected_log) From 5063d16cc362a7b3a7859908a4b1dd2d6783f8d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 12 Mar 2022 19:15:45 +0000 Subject: [PATCH 31/42] Bump coverage from 5.5 to 6.3.2 Bumps [coverage](https://github.com/nedbat/coveragepy) from 5.5 to 6.3.2. - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](https://github.com/nedbat/coveragepy/compare/coverage-5.5...6.3.2) --- updated-dependencies: - dependency-name: coverage dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 362c8770..fd7488b3 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,5 +1,5 @@ black==22.1.0 -coverage==5.5 +coverage==6.3.2 flake8==3.9.1 flake8-docstrings==1.6.0 pre-commit==2.17.0 From e282dbc16751a89954e8c977e483985f77200343 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 12 Mar 2022 19:25:45 +0000 Subject: [PATCH 32/42] Bump restructuredtext-lint from 1.3.2 to 1.4.0 Bumps [restructuredtext-lint](https://github.com/twolfson/restructuredtext-lint) from 1.3.2 to 1.4.0. - [Release notes](https://github.com/twolfson/restructuredtext-lint/releases) - [Changelog](https://github.com/twolfson/restructuredtext-lint/blob/master/CHANGELOG.rst) - [Commits](https://github.com/twolfson/restructuredtext-lint/compare/1.3.2...1.4.0) --- updated-dependencies: - dependency-name: restructuredtext-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index fd7488b3..465288a3 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -9,6 +9,6 @@ pytest==7.0.1 pytest-cov==3.0.0 pytest-sugar==0.9.4 pytest-timeout==2.1.0 -restructuredtext-lint==1.3.2 +restructuredtext-lint==1.4.0 pygments==2.11.2 testtools>=2.4.0 From 2ba5b6f7cdf7bc12cf9467bff9cd308f251b58f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 18 Mar 2022 18:09:40 +0000 Subject: [PATCH 33/42] Bump pytest from 7.0.1 to 7.1.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.0.1 to 7.1.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.0.1...7.1.1) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index fd7488b3..ffec7c2a 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -5,7 +5,7 @@ flake8-docstrings==1.6.0 pre-commit==2.17.0 pylint==2.10.2 pydocstyle==6.0.0 -pytest==7.0.1 +pytest==7.1.1 pytest-cov==3.0.0 pytest-sugar==0.9.4 pytest-timeout==2.1.0 From 2760fc33572eebbc315f0e853dd60c32e4693579 Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Wed, 19 Jan 2022 16:29:14 -0700 Subject: [PATCH 34/42] Renamed ./app and ./app/app.py to ./blinkapp and ./blinkapp/blinkapp.py respectively. All tests passed. Have a top level app.py causes massive issues with Chalice, which imports and uses a top level app to handle all routing. --- Dockerfile | 4 ++-- app/__init__.py | 1 - blinkapp/__init__.py | 1 + app/app.py => blinkapp/blinkapp.py | 4 ++-- {app => blinkapp}/build.sh | 0 {app => blinkapp}/run.sh | 0 tox.ini | 26 +++++++++++++------------- 7 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 app/__init__.py create mode 100644 blinkapp/__init__.py rename app/app.py => blinkapp/blinkapp.py (91%) rename {app => blinkapp}/build.sh (100%) rename {app => blinkapp}/run.sh (100%) diff --git a/Dockerfile b/Dockerfile index 02ccf085..1a40c5d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 [] diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index 099ec593..00000000 --- a/app/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Python init file for app.py.""" diff --git a/blinkapp/__init__.py b/blinkapp/__init__.py new file mode 100644 index 00000000..15586a6f --- /dev/null +++ b/blinkapp/__init__.py @@ -0,0 +1 @@ +"""Python init file for blinkapp.py.""" diff --git a/app/app.py b/blinkapp/blinkapp.py similarity index 91% rename from app/app.py rename to blinkapp/blinkapp.py index 081bcdfc..af6c5018 100644 --- a/app/app.py +++ b/blinkapp/blinkapp.py @@ -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 @@ -29,7 +29,7 @@ def start(): def main(): - """Run the app.""" + """Run the blink app.""" blink = start() download_videos(blink) blink.save(CREDFILE) diff --git a/app/build.sh b/blinkapp/build.sh similarity index 100% rename from app/build.sh rename to blinkapp/build.sh diff --git a/app/run.sh b/blinkapp/run.sh similarity index 100% rename from app/run.sh rename to blinkapp/run.sh diff --git a/tox.ini b/tox.ini index f24f7748..47a3ba0e 100644 --- a/tox.ini +++ b/tox.ini @@ -7,40 +7,40 @@ skipsdist = True setenv = LANG=en_US.UTF-8 PYTHONPATH = {toxinidir} -commands = +commands = pytest --timeout=9 --durations=10 --cov=blinkpy --cov-report term-missing {posargs} -deps = +deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt [testenv:cov] -setenv = +setenv = LANG=en_US.UTF-8 PYTHONPATH = {toxinidir} -commands = +commands = pytest --timeout=9 --durations=10 --cov=blinkpy --cov-report=xml {posargs} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt [testenv:pylint] -deps = +deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt basepython = python3 ignore_errors = True -commands = - pylint --rcfile={toxinidir}/pylintrc blinkpy tests app +commands = + pylint --rcfile={toxinidir}/pylintrc blinkpy tests blinkapp [testenv:lint] -deps = +deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt basepython = python3 -commands = - flake8 blinkpy tests app - pydocstyle blinkpy tests app - black --check --diff blinkpy tests app +commands = + flake8 blinkpy tests blinkapp + pydocstyle blinkpy tests blinkapp + black --check --diff blinkpy tests blinkapp rst-lint README.rst CHANGES.rst CONTRIBUTING.rst [testenv:build] @@ -51,7 +51,7 @@ whitelist_externals = /bin/rm deps = -r{toxinidir}/requirements_test.txt -commands = +commands = /bin/rm -rf build dist python setup.py bdist_wheel /bin/sh -c "pip install --upgrade dist/*.whl" From 5e9583919157e596219734a2aaca31e5a1ecc16f Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Fri, 11 Mar 2022 14:49:27 -0700 Subject: [PATCH 35/42] Figured out the blink lambda api changes. We need to resolve the URL from the timestamp because they no longer send the full url to the thumbnail in the camera config. --- blinkpy/camera.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index c7953f74..c6d28878 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -10,6 +10,10 @@ _LOGGER = logging.getLogger(__name__) +THUMBNAIL_URL = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/thumbnail.jpg?" \ + "ts={thumbnail}&ext=" + + class BlinkCamera: """Class to initialize individual camera.""" @@ -174,6 +178,13 @@ def update_images(self, config, force_cache=False): thumb_addr = config["thumbnail"] else: _LOGGER.warning("Could not find thumbnail for camera %s", self.name) + try: + # API update only returns the timestamp! + int(thumb_addr) + thumb_addr = THUMBNAIL_URL.format(**config) + except TypeError: + # This is the old API and has the full url + pass if thumb_addr is not None: new_thumbnail = urljoin(self.sync.urls.base_url, f"{thumb_addr}.jpg") From 6f9a2fed2526d3e1d4dfaa6b5b1609bbb156d332 Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Fri, 11 Mar 2022 15:33:00 -0700 Subject: [PATCH 36/42] Version bump and moved thumbnail endpoint to helper constants --- blinkpy/camera.py | 6 ++---- blinkpy/helpers/constants.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index c6d28878..bee7250b 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -5,13 +5,11 @@ from json import dumps from requests.compat import urljoin from blinkpy import api -from blinkpy.helpers.constants import TIMEOUT_MEDIA +from blinkpy.helpers.constants import TIMEOUT_MEDIA, THUMBNAIL_ENDPOINT _LOGGER = logging.getLogger(__name__) -THUMBNAIL_URL = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/thumbnail.jpg?" \ - "ts={thumbnail}&ext=" class BlinkCamera: @@ -181,7 +179,7 @@ def update_images(self, config, force_cache=False): try: # API update only returns the timestamp! int(thumb_addr) - thumb_addr = THUMBNAIL_URL.format(**config) + thumb_addr = THUMBNAIL_ENDPOINT.format(**config) except TypeError: # This is the old API and has the full url pass diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 85a3a40a..a992a3f6 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "0.rc0" +PATCH_VERSION = "1.rc0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" @@ -50,6 +50,8 @@ DEFAULT_URL = f"rest-prod.{BLINK_URL}" BASE_URL = f"https://{DEFAULT_URL}" LOGIN_ENDPOINT = f"{BASE_URL}/api/v5/account/login" +THUMBNAIL_ENDPOINT = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/" \ + "thumbnail.jpg?ts={thumbnail}&ext=" """ Dictionaries From 6628ccb9d195b0b2bf4e300a790072821367ec08 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 20 Mar 2022 15:43:05 -0400 Subject: [PATCH 37/42] Fixed items from review, added tests --- blinkpy/camera.py | 32 +++++++++------- blinkpy/helpers/constants.py | 4 +- tests/test_cameras.py | 73 +++++++++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index bee7250b..af6c58b2 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -5,13 +5,11 @@ from json import dumps from requests.compat import urljoin from blinkpy import api -from blinkpy.helpers.constants import TIMEOUT_MEDIA, THUMBNAIL_ENDPOINT +from blinkpy.helpers.constants import TIMEOUT_MEDIA _LOGGER = logging.getLogger(__name__) - - class BlinkCamera: """Class to initialize individual camera.""" @@ -172,20 +170,28 @@ 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.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) - try: - # API update only returns the timestamp! - int(thumb_addr) - thumb_addr = THUMBNAIL_ENDPOINT.format(**config) - except TypeError: - # This is the old API and has the full url - pass - - if thumb_addr is not None: - new_thumbnail = urljoin(self.sync.urls.base_url, f"{thumb_addr}.jpg") try: self.motion_detected = self.sync.motion[self.name] diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index a992a3f6..85a3a40a 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "1.rc0" +PATCH_VERSION = "0.rc0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" @@ -50,8 +50,6 @@ DEFAULT_URL = f"rest-prod.{BLINK_URL}" BASE_URL = f"https://{DEFAULT_URL}" LOGIN_ENDPOINT = f"{BASE_URL}/api/v5/account/login" -THUMBNAIL_ENDPOINT = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/" \ - "thumbnail.jpg?ts={thumbnail}&ext=" """ Dictionaries diff --git a/tests/test_cameras.py b/tests/test_cameras.py index 73d9839f..a0b933f3 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -13,7 +13,6 @@ from blinkpy.sync_module import BlinkSyncModule from blinkpy.camera import BlinkCamera, BlinkCameraMini, BlinkDoorbell - CAMERA_CFG = { "camera": [ { @@ -202,3 +201,75 @@ def test_camera_stream(self, mock_resp): self.assertEqual(self.camera.get_liveview(), "rtsps://foo.bar") self.assertEqual(mini_camera.get_liveview(), "rtsps://foo.bar") self.assertEqual(doorbell_camera.get_liveview(), "rtsps://foo.bar") + + def test_different_thumb_api(self, mock_resp): + """Test that the correct url is created with new api.""" + thumb_endpoint = "https://rest-test.immedia-semi.com/api/v3/media/accounts/9999/networks/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" + config = { + "name": "new", + "id": 1234, + "network_id": 5678, + "serial": "12345678", + "enabled": False, + "battery_voltage": 90, + "battery_state": "ok", + "temperature": 68, + "wifi_strength": 4, + "thumbnail": 1357924680, + "type": "test", + } + mock_resp.side_effect = [ + {"temp": 71}, + "test", + ] + self.camera.sync.blink.account_id = 9999 + self.camera.update(config) + self.assertEqual(self.camera.thumbnail, thumb_endpoint) + + def test_thumb_return_none(self, mock_resp): + """Test that a 'None" thumbnail is doesn't break system.""" + config = { + "name": "new", + "id": 1234, + "network_id": 5678, + "serial": "12345678", + "enabled": False, + "battery_voltage": 90, + "battery_state": "ok", + "temperature": 68, + "wifi_strength": 4, + "thumbnail": None, + "type": "test", + } + mock_resp.side_effect = [ + {"temp": 71}, + "test", + ] + self.camera.update(config) + self.assertEqual(self.camera.thumbnail, None) + + def test_new_thumb_url_returned(self, mock_resp): + """Test that thumb handled properly if new url returned.""" + thumb_return = "/api/v3/media/accounts/9999/networks/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" + config = { + "name": "new", + "id": 1234, + "network_id": 5678, + "serial": "12345678", + "enabled": False, + "battery_voltage": 90, + "battery_state": "ok", + "temperature": 68, + "wifi_strength": 4, + "thumbnail": thumb_return, + "type": "test", + } + mock_resp.side_effect = [ + {"temp": 71}, + "test", + ] + self.camera.sync.blink.account_id = 9999 + self.camera.update(config) + self.assertEqual( + self.camera.thumbnail, f"https://rest-test.immedia-semi.com{thumb_return}" + ) From 2765c06a4bc4da0e75a76fe8b44bfeff89b6467c Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 20 Mar 2022 15:47:35 -0400 Subject: [PATCH 38/42] Fix after merge --- blinkpy/camera.py | 11 +---------- blinkpy/helpers/constants.py | 4 +--- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 1ecc1881..af6c58b2 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -5,13 +5,11 @@ from json import dumps from requests.compat import urljoin from blinkpy import api -from blinkpy.helpers.constants import TIMEOUT_MEDIA, THUMBNAIL_ENDPOINT +from blinkpy.helpers.constants import TIMEOUT_MEDIA _LOGGER = logging.getLogger(__name__) - - class BlinkCamera: """Class to initialize individual camera.""" @@ -194,13 +192,6 @@ def update_images(self, config, force_cache=False): else: _LOGGER.warning("Could not find thumbnail for camera %s", self.name) - try: - # API update only returns the timestamp! - int(thumb_addr) - thumb_addr = THUMBNAIL_ENDPOINT.format(**config) - except TypeError: - # This is the old API and has the full url - pass try: self.motion_detected = self.sync.motion[self.name] diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index a992a3f6..85a3a40a 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "1.rc0" +PATCH_VERSION = "0.rc0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" @@ -50,8 +50,6 @@ DEFAULT_URL = f"rest-prod.{BLINK_URL}" BASE_URL = f"https://{DEFAULT_URL}" LOGIN_ENDPOINT = f"{BASE_URL}/api/v5/account/login" -THUMBNAIL_ENDPOINT = "/api/v3/media/accounts/{account_id}/networks/{network_id}/catalina/{id}/thumbnail/" \ - "thumbnail.jpg?ts={thumbnail}&ext=" """ Dictionaries From 688eb6aeec8fcda30b68d2f5b17e681d84767e37 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 20 Mar 2022 15:58:21 -0400 Subject: [PATCH 39/42] 0.19.0rc1 --- CHANGES.rst | 8 ++++++++ blinkpy/helpers/constants.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 043d5bf8..7c26b578 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,17 +11,25 @@ A list of changes between each release - Debug log in prase download method fix (`@tieum `__) - Fix issue with malformed thumbnails (`#550 `__) +- Fully support new thumbnail API (`@gdoermann `__) **New Features:** - Support for arm/disarm of Blink Mini cameras (`@mstratford `__) +- Add product_type to BlinkCamera class to report type of camera (`#553 `__) +- Remove python 3.6 support, add python 3.10 support (`#554 `__) **Other:** +- Make code that determines need for unique class (Mini + Doorbells) generic (`#553 `__) - Bump pre-commit to 2.17.0 - Bump pytest to 7.0.1 - 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) diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 85a3a40a..11166bab 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "0.rc0" +PATCH_VERSION = "0.rc1" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From 28f91e542abc520b9d1a381c7c052d780143223c Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 20 Mar 2022 17:43:37 -0400 Subject: [PATCH 40/42] Missing network_id in thumbnail url --- blinkpy/camera.py | 2 +- tests/test_cameras.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index af6c58b2..1212f508 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -176,7 +176,7 @@ def update_images(self, config, force_cache=False): try: # API update only returns the timestamp! int(thumb_addr) - thumb_string = f"/api/v3/media/accounts/{self.sync.blink.account_id}/networks/{self.product_type}/{self.camera_id}/thumbnail/thumbnail.jpg?ts={thumb_addr}&ext=" + 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" diff --git a/tests/test_cameras.py b/tests/test_cameras.py index a0b933f3..c752f530 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -204,7 +204,7 @@ def test_camera_stream(self, mock_resp): def test_different_thumb_api(self, mock_resp): """Test that the correct url is created with new api.""" - thumb_endpoint = "https://rest-test.immedia-semi.com/api/v3/media/accounts/9999/networks/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" + thumb_endpoint = "https://rest-test.immedia-semi.com/api/v3/media/accounts/9999/networks/5678/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" config = { "name": "new", "id": 1234, @@ -250,7 +250,7 @@ def test_thumb_return_none(self, mock_resp): def test_new_thumb_url_returned(self, mock_resp): """Test that thumb handled properly if new url returned.""" - thumb_return = "/api/v3/media/accounts/9999/networks/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" + thumb_return = "/api/v3/media/accounts/9999/networks/5678/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" config = { "name": "new", "id": 1234, From 2c9df5282f5aa53d73e7fd15aacc6dfab372aac1 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 20 Mar 2022 17:44:49 -0400 Subject: [PATCH 41/42] RC version bump --- blinkpy/helpers/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 11166bab..5db021ca 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "0.rc1" +PATCH_VERSION = "0.rc2" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From 4aaeecdef6c6c3733d41d09392f53a4d34ccfb23 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 20 Mar 2022 22:22:52 -0400 Subject: [PATCH 42/42] Version bump --- CHANGES.rst | 3 +-- blinkpy/helpers/constants.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7c26b578..68ef3de3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog A list of changes between each release -0.19.0 (pre-release) +0.19.0 (2022-03-20) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Bugfixes:** @@ -23,7 +23,6 @@ A list of changes between each release - Make code that determines need for unique class (Mini + Doorbells) generic (`#553 `__) - Bump pre-commit to 2.17.0 -- Bump pytest to 7.0.1 - Bump pytest-timeout to 2.1.0 - Bump pygments to 2.11.2 - Bump black to 22.1.0 diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 5db021ca..e2326e1b 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 19 -PATCH_VERSION = "0.rc2" +PATCH_VERSION = 0 __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"