From ed4450778d6802990006dd9fb1b14e2c98520018 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 2 Aug 2020 03:35:42 +0000 Subject: [PATCH 01/22] Dev 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 bf43b5c2..596fd0cb 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -3,8 +3,8 @@ import os MAJOR_VERSION = 0 -MINOR_VERSION = 16 -PATCH_VERSION = 3 +MINOR_VERSION = 17 +PATCH_VERSION = "0.dev0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From 141fea542c9f0d91b7a1f25b92ff7930d8351565 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2020 08:14:22 +0000 Subject: [PATCH 02/22] Bump pytest-cov from 2.10.0 to 2.10.1 Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 2.10.0 to 2.10.1. - [Release notes](https://github.com/pytest-dev/pytest-cov/releases) - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v2.10.0...v2.10.1) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index b0f58b02..32e823d6 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -6,7 +6,7 @@ pre-commit==2.6.0 pylint==2.5.3 pydocstyle==5.0.2 pytest==6.0.1 -pytest-cov==2.10.0 +pytest-cov==2.10.1 pytest-sugar==0.9.4 pytest-timeout==1.4.2 restructuredtext-lint==1.3.1 From e00600c955c8426568f32a003f2c50cdbcf28e92 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2020 06:38:09 +0000 Subject: [PATCH 03/22] Bump coverage from 5.2.1 to 5.3 Bumps [coverage](https://github.com/nedbat/coveragepy) from 5.2.1 to 5.3. - [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.2.1...coverage-5.3) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index b0f58b02..d6cbe5eb 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,5 +1,5 @@ black==19.10b0 -coverage==5.2.1 +coverage==5.3 flake8==3.8.3 flake8-docstrings==1.5.0 pre-commit==2.6.0 From 9a9501635fe75a0e78feff4b42bbca3d90f9b7cf Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 18 Sep 2020 06:32:37 +0000 Subject: [PATCH 04/22] Bump pygments from 2.6.1 to 2.7.1 Bumps [pygments](https://github.com/pygments/pygments) from 2.6.1 to 2.7.1. - [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.6.1...2.7.1) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index b0f58b02..c60df654 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -10,4 +10,4 @@ pytest-cov==2.10.0 pytest-sugar==0.9.4 pytest-timeout==1.4.2 restructuredtext-lint==1.3.1 -pygments==2.6.1 +pygments==2.7.1 From a374009835230f66b9c74337ce7c2e3cc6283999 Mon Sep 17 00:00:00 2001 From: rohitsud Date: Sun, 27 Sep 2020 13:06:24 -0700 Subject: [PATCH 05/22] Fix readme param and spelling --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 25e8221a..32d867c6 100644 --- a/README.rst +++ b/README.rst @@ -174,7 +174,7 @@ Similar methods exist for individual cameras: Download videos ---------------- -You can also use this library to download all videos from the server. In order to do this, you must specify a ``path``. You may also specifiy a how far back in time to go to retrieve videos via the ``since=`` variable (a simple string such as ``"2017/09/21"`` is sufficient), as well as how many pages to traverse via the ``page=`` variable. Note that by default, the library will search the first ten pages which is sufficient in most use cases. Additionally, you can specidy one or more cameras via the ``camera=`` property. This can be a single string indicating the name of the camera, or a list of camera names. By default, it is set to the string ``'all'`` to grab videos from all cameras. +You can also use this library to download all videos from the server. In order to do this, you must specify a ``path``. You may also specifiy a how far back in time to go to retrieve videos via the ``since=`` variable (a simple string such as ``"2017/09/21"`` is sufficient), as well as how many pages to traverse via the ``stop=`` variable. Note that by default, the library will search the first ten pages which is sufficient in most use cases. Additionally, you can specify one or more cameras via the ``camera=`` property. This can be a single string indicating the name of the camera, or a list of camera names. By default, it is set to the string ``'all'`` to grab videos from all cameras. Example usage, which downloads all videos recorded since July 4th, 2018 at 9:34am to the ``/home/blink`` directory: From 8c23087f89f1c8e273b2828dd50b136b90d9eb78 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 28 Sep 2020 15:10:49 +0000 Subject: [PATCH 06/22] Bump pre-commit from 2.6.0 to 2.7.1 Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 2.6.0 to 2.7.1. - [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.6.0...v2.7.1) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 0de9e164..32dba1e2 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -2,7 +2,7 @@ black==19.10b0 coverage==5.3 flake8==3.8.3 flake8-docstrings==1.5.0 -pre-commit==2.6.0 +pre-commit==2.7.1 pylint==2.5.3 pydocstyle==5.0.2 pytest==6.0.1 From 1b1c30bff0f54fe555629f8d20dbff819cb21df2 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 5 Oct 2020 09:08:15 -0400 Subject: [PATCH 07/22] Add codecov token to workflow to fix upload issue --- .github/workflows/coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 570efdce..c260f405 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,6 +34,8 @@ jobs: tox -r -e cov - name: Codecov uses: codecov/codecov-action@v1.0.6 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: flags: unittests file: ./coverage.xml From 7aef8570a574a0a2d2a59d3084e1730e8d189481 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:24:47 +0000 Subject: [PATCH 08/22] Bump pylint from 2.5.3 to 2.6.0 Bumps [pylint](https://github.com/PyCQA/pylint) from 2.5.3 to 2.6.0. - [Release notes](https://github.com/PyCQA/pylint/releases) - [Changelog](https://github.com/PyCQA/pylint/blob/master/ChangeLog) - [Commits](https://github.com/PyCQA/pylint/compare/pylint-2.5.3...pylint-2.6.0) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 0de9e164..a1f09f5b 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -3,7 +3,7 @@ coverage==5.3 flake8==3.8.3 flake8-docstrings==1.5.0 pre-commit==2.6.0 -pylint==2.5.3 +pylint==2.6.0 pydocstyle==5.0.2 pytest==6.0.1 pytest-cov==2.10.1 From 190cef875ec34522435aeb0ed2643b0798771b90 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 5 Oct 2020 09:38:15 -0400 Subject: [PATCH 09/22] Attempt to fix coverage --- .github/workflows/coverage.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c260f405..ddb7c9ce 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -33,10 +33,9 @@ jobs: run: | tox -r -e cov - name: Codecov - uses: codecov/codecov-action@v1.0.6 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + uses: codecov/codecov-action@v1 with: + token: ${{ secrets.CODECOV_TOKEN }} flags: unittests file: ./coverage.xml name: blinkpy From f619b20e2af6d85f69ef495e683fcdc179030610 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:44:52 +0000 Subject: [PATCH 10/22] Bump flake8 from 3.8.3 to 3.8.4 Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.8.3 to 3.8.4. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.8.3...3.8.4) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index a1f09f5b..e6b6ad09 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,6 +1,6 @@ black==19.10b0 coverage==5.3 -flake8==3.8.3 +flake8==3.8.4 flake8-docstrings==1.5.0 pre-commit==2.6.0 pylint==2.6.0 From bdcb3f62033d2a6b545030a0f8a38d7e7ca6cef8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:44:53 +0000 Subject: [PATCH 11/22] Bump pydocstyle from 5.0.2 to 5.1.1 Bumps [pydocstyle](https://github.com/PyCQA/pydocstyle) from 5.0.2 to 5.1.1. - [Release notes](https://github.com/PyCQA/pydocstyle/releases) - [Changelog](https://github.com/PyCQA/pydocstyle/blob/master/docs/release_notes.rst) - [Commits](https://github.com/PyCQA/pydocstyle/compare/5.0.2...5.1.1) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index a1f09f5b..914c006b 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -4,7 +4,7 @@ flake8==3.8.3 flake8-docstrings==1.5.0 pre-commit==2.6.0 pylint==2.6.0 -pydocstyle==5.0.2 +pydocstyle==5.1.1 pytest==6.0.1 pytest-cov==2.10.1 pytest-sugar==0.9.4 From 59ef398452bb1d37ec89a6cacf994ad4bdb3b7d9 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:49:12 +0000 Subject: [PATCH 12/22] Bump pytest from 6.0.1 to 6.1.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.0.1 to 6.1.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.0.1...6.1.1) Signed-off-by: dependabot-preview[bot] --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 29c1a3d7..508f9b71 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -5,7 +5,7 @@ flake8-docstrings==1.5.0 pre-commit==2.6.0 pylint==2.6.0 pydocstyle==5.1.1 -pytest==6.0.1 +pytest==6.1.1 pytest-cov==2.10.1 pytest-sugar==0.9.4 pytest-timeout==1.4.2 From e8e9d4e3cdfd2d32cd3cc978e6a78fa78a579b93 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 5 Oct 2020 09:49:16 -0400 Subject: [PATCH 13/22] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5f3a324b..98d80a3a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,12 +8,12 @@ repos: - --quiet files: ^((blinkpy|tests)/.+)?[^/]+\.py$ - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.2 + rev: 3.8.3 hooks: - id: flake8 additional_dependencies: - flake8-docstrings==1.5.0 - - pydocstyle==5.0.2 + - pydocstyle==5.1.1 files: ^(blinkpy|tests)/.+\.py$ - repo: https://github.com/Lucas-C/pre-commit-hooks-markup rev: v1.0.0 From b0fed670b9c150a68a46c9a4bdf9505c9c203ca9 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 5 Oct 2020 20:29:13 +0000 Subject: [PATCH 14/22] Move testtools to requirements_test.txt --- requirements.txt | 1 - requirements_test.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 384d3bda..47ea4e01 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ python-dateutil>=2.8.1 requests>=2.24.0 python-slugify>=4.0.1 -testtools>=2.4.0 diff --git a/requirements_test.txt b/requirements_test.txt index 444c892d..2cb1cc7a 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -11,3 +11,4 @@ pytest-sugar==0.9.4 pytest-timeout==1.4.2 restructuredtext-lint==1.3.1 pygments==2.7.1 +testtools>=2.4.0 From b5b749804149de585078e9acf4ab9697844eb4a8 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Tue, 6 Oct 2020 13:16:05 +0000 Subject: [PATCH 15/22] Generalized image/video download, fixed non-updating image for minis --- blinkpy/blinkpy.py | 1 + blinkpy/camera.py | 30 ++++++++++++++---------------- tests/test_blinkpy.py | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index 913aa407..70abd8de 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -86,6 +86,7 @@ def refresh(self, force=False): if not self.available: self.setup_post_verify() + self.get_homescreen() for sync_name, sync_module in self.sync.items(): _LOGGER.debug("Attempting refresh of sync %s", sync_name) sync_module.refresh(force_cache=force) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 1715feee..87797b2b 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -98,6 +98,15 @@ def arm(self, value): self.sync.blink, self.network_id, self.camera_id ) + def get_media(self, media_type="image"): + """Download media (image or video).""" + url = self.thumbnail + if media_type.lower() == "video": + url = self.clip + return api.http_get( + self.sync.blink, url=url, stream=True, json=False, timeout=TIMEOUT_MEDIA, + ) + def snap_picture(self): """Take a picture with camera to create a new thumbnail.""" return api.request_new_image(self.sync.blink, self.network_id, self.camera_id) @@ -180,21 +189,10 @@ def update_images(self, config, force_cache=False): update_cached_video = True if new_thumbnail is not None and (update_cached_image or force_cache): - self._cached_image = api.http_get( - self.sync.blink, - url=self.thumbnail, - stream=True, - json=False, - timeout=TIMEOUT_MEDIA, - ) + self._cached_image = self.get_media() + if clip_addr is not None and (update_cached_video or force_cache): - self._cached_video = api.http_get( - self.sync.blink, - url=self.clip, - stream=True, - json=False, - timeout=TIMEOUT_MEDIA, - ) + self._cached_video = self.get_media(media_type="video") def get_liveview(self): """Get livewview rtsps link.""" @@ -210,7 +208,7 @@ def image_to_file(self, path): :param path: Path to write file """ _LOGGER.debug("Writing image from %s to %s", self.name, path) - response = self._cached_image + response = self.get_media() if response.status_code == 200: with open(path, "wb") as imgfile: copyfileobj(response.raw, imgfile) @@ -226,7 +224,7 @@ def video_to_file(self, path): :param path: Path to write file """ _LOGGER.debug("Writing video from %s to %s", self.name, path) - response = self._cached_video + response = self.get_media(media_type="video") if response is None: _LOGGER.error("No saved video exist for %s.", self.name) return diff --git a/tests/test_blinkpy.py b/tests/test_blinkpy.py index 821edf05..aed2edbd 100644 --- a/tests/test_blinkpy.py +++ b/tests/test_blinkpy.py @@ -68,7 +68,7 @@ def test_throttle(self, mock_time): self.assertEqual(self.blink.last_refresh, None) with mock.patch( "blinkpy.sync_module.BlinkSyncModule.refresh", return_value=True - ): + ), mock.patch("blinkpy.blinkpy.Blink.get_homescreen", return_value=True): self.blink.refresh() self.assertEqual(self.blink.last_refresh, now) From eb1fbe90d1b25d3ce48a5a4ac7cedffbc7c98736 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Tue, 6 Oct 2020 13:20:56 +0000 Subject: [PATCH 16/22] Updated liveview endpoint --- blinkpy/api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/blinkpy/api.py b/blinkpy/api.py index 642e8af0..d72ca0d7 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -244,9 +244,7 @@ def request_camera_liveview(blink, network, camera_id): :param network: Sync module network id. :param camera_id: Camera ID of camera to request liveview from. """ - url = ( - f"{blink.urls.base_url}/api/v3/networks/{network}/cameras/{camera_id}/liveview" - ) + url = f"{blink.urls.base_url}/api/v5/accounts/{blink.account_id}/networks/{network}/cameras/{camera_id}/liveview" return http_post(blink, url) From 88984365fef1bed688f0555341c37d97f1bc5efb Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Tue, 6 Oct 2020 09:31:45 -0400 Subject: [PATCH 17/22] Update constants.py --- 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 596fd0cb..4f24adca 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -3,8 +3,8 @@ import os MAJOR_VERSION = 0 -MINOR_VERSION = 17 -PATCH_VERSION = "0.dev0" +MINOR_VERSION = 16 +PATCH_VERSION = "4-rc0" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From f09a66c083862a15d0a3f86bb1cacda53e9f339f Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 25 Oct 2020 14:01:03 +0000 Subject: [PATCH 18/22] Fix malformatted stream url for blink mini --- blinkpy/camera.py | 2 +- blinkpy/helpers/constants.py | 4 ++-- tests/test_cameras.py | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 87797b2b..186b8559 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -266,6 +266,6 @@ def get_liveview(self): response = api.http_post(self.sync.blink, url) server = response["server"] server_split = server.split(":") - server_split[0] = "rtsps" + server_split[0] = "rtsps:" link = "".join(server_split) return link diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 4f24adca..29948e2c 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -3,8 +3,8 @@ import os MAJOR_VERSION = 0 -MINOR_VERSION = 16 -PATCH_VERSION = "4-rc0" +MINOR_VERSION = 17 +PATCH_VERSION = "0.dev1" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" diff --git a/tests/test_cameras.py b/tests/test_cameras.py index 25bdaf06..8cf7d76f 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -176,3 +176,10 @@ def test_mini_missing_attributes(self, mock_resp): attr = camera.attributes for key in attr: self.assertEqual(attr[key], None) + + def test_camera_stream(self, mock_resp): + """Test that camera stream returns correct url.""" + mock_resp.return_value = {"server": "rtsps://foo.bar"} + mini_camera = BlinkCameraMini(self.blink.sync["test"]) + self.assertEqual(self.camera.get_liveview(), "rtsps://foo.bar") + self.assertEqual(mini_camera.get_liveview(), "rtsps://foo.bar") From 92a2cc2d9ab7ffadf2e562d9b4b3f31db4c633a9 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 23 Nov 2020 03:30:15 +0000 Subject: [PATCH 19/22] Added test to catch NoneType error on refresh, fixed offending code --- blinkpy/blinkpy.py | 11 +++++----- blinkpy/sync_module.py | 4 ++-- tests/test_blink_functions.py | 39 +++++++++++++++++++++-------------- tests/test_blinkpy.py | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index 70abd8de..82054589 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -76,21 +76,22 @@ def __init__( self.no_owls = no_owls @util.Throttle(seconds=MIN_THROTTLE_TIME) - def refresh(self, force=False): + def refresh(self, force=False, force_cache=False): """ Perform a system refresh. - :param force: Force an update of the camera data + :param force: Used to override throttle, resets refresh + :param force_cache: Used to force update without overriding throttle """ - if self.check_if_ok_to_update() or force: + if self.check_if_ok_to_update() or force or force_cache: if not self.available: self.setup_post_verify() self.get_homescreen() for sync_name, sync_module in self.sync.items(): _LOGGER.debug("Attempting refresh of sync %s", sync_name) - sync_module.refresh(force_cache=force) - if not force: + sync_module.refresh(force_cache=(force or force_cache)) + if not force_cache: # Prevents rapid clearing of motion detect property self.last_refresh = int(time.time()) return True diff --git a/blinkpy/sync_module.py b/blinkpy/sync_module.py index ad780a16..4e317569 100644 --- a/blinkpy/sync_module.py +++ b/blinkpy/sync_module.py @@ -145,7 +145,7 @@ def get_owl_info(self, name): for owl in self.blink.homescreen["owls"]: if owl["name"] == name: return owl - except KeyError: + except (TypeError, KeyError): pass return None @@ -270,7 +270,7 @@ def get_camera_info(self, camera_id, **kwargs): if owl["name"] == self.name: self.status = owl["enabled"] return owl - except KeyError: + except (TypeError, KeyError): pass return None diff --git a/tests/test_blink_functions.py b/tests/test_blink_functions.py index 89a45dc6..8a71294b 100644 --- a/tests/test_blink_functions.py +++ b/tests/test_blink_functions.py @@ -5,29 +5,23 @@ from blinkpy import blinkpy from blinkpy.sync_module import BlinkSyncModule +from blinkpy.camera import BlinkCamera from blinkpy.helpers.util import get_time, BlinkURLHandler class MockSyncModule(BlinkSyncModule): - """Mock http requests from sync module.""" + """Mock blink sync module object.""" - def __init__(self, blink, header): - """Create mock sync module instance.""" - super().__init__(blink, header, network_id=None, camera_list=None) - self.blink = blink - self.header = header - self.return_value = None - self.return_value2 = None + def get_network_info(self): + """Mock network info method.""" + return True - def http_get(self, url, stream=False, json=True): - """Mock get request.""" - if stream and self.return_value2 is not None: - return self.return_value2 - return self.return_value - def http_post(self, url): - """Mock post request.""" - return self.return_value +class MockCamera(BlinkCamera): + """Mock blink camera object.""" + + def update(self, config, force_cache=False, **kwargs): + """Mock camera update method.""" class TestBlinkFunctions(unittest.TestCase): @@ -121,3 +115,16 @@ def test_parse_camera_not_in_list(self, mock_req): with self.assertLogs() as dl_log: blink.download_videos("/tmp", camera="bar", stop=2) self.assertEqual(dl_log.output, expected_log) + + @mock.patch("blinkpy.blinkpy.api.request_network_update") + @mock.patch("blinkpy.auth.Auth.query") + def test_refresh(self, mock_req, mock_update): + """Test ability to refresh system.""" + mock_update.return_value = {"network": {"sync_module_error": False}} + mock_req.return_value = None + self.blink.last_refresh = 0 + self.blink.available = True + self.blink.sync["foo"] = MockSyncModule(self.blink, "foo", 1, []) + self.blink.cameras = {"bar": MockCamera(self.blink.sync)} + self.blink.sync["foo"].cameras = self.blink.cameras + self.assertTrue(self.blink.refresh()) diff --git a/tests/test_blinkpy.py b/tests/test_blinkpy.py index aed2edbd..c632215d 100644 --- a/tests/test_blinkpy.py +++ b/tests/test_blinkpy.py @@ -69,7 +69,7 @@ def test_throttle(self, mock_time): with mock.patch( "blinkpy.sync_module.BlinkSyncModule.refresh", return_value=True ), mock.patch("blinkpy.blinkpy.Blink.get_homescreen", return_value=True): - self.blink.refresh() + self.blink.refresh(force=True) self.assertEqual(self.blink.last_refresh, now) self.assertEqual(self.blink.check_if_ok_to_update(), False) From ab38afa105d90dc5116847cf661801731b1742f6 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 23 Nov 2020 04:06:19 +0000 Subject: [PATCH 20/22] 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 29948e2c..40635180 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -3,8 +3,8 @@ import os MAJOR_VERSION = 0 -MINOR_VERSION = 17 -PATCH_VERSION = "0.dev1" +MINOR_VERSION = 16 +PATCH_VERSION = "4.rc1" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From c01a6ce16b3d8e40f3a373b8f117f68a64adf87d Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Mon, 23 Nov 2020 04:25:16 +0000 Subject: [PATCH 21/22] dev 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 40635180..1862d3dc 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 16 -PATCH_VERSION = "4.rc1" +PATCH_VERSION = 4 __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" From a2555a6c40c906bca0095428d8c59a2ccd056796 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sun, 22 Nov 2020 23:31:13 -0500 Subject: [PATCH 22/22] Update for 0.16.4 --- CHANGES.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 9646499b..d8171ab8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,31 @@ Changelog A list of changes between each release +0.16.4 (2020-11-22) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**Bugfixes:** + +- Updated liveview endpoint (`#389 `__) +- Fixed mini thumbnail not updating (`#388 `__) +- Add exception catch to prevent NoneType error on refresh, added test to check behavior as well (`#401 `__) + - Unrelated: had to add two force methods to refresh for testing purposes. Should not change normal usage. +- Fix malformed stream url (`#395 `__) + +**All:** + +- Moved testtools to requirements_test.txt (`#387 `__) +- Bumped pytest to 6.1.1 +- Bumped flake8 to 3.8.4 +- Fixed README spelling ((`#381 `__) via @rohitsud) +- Bumped pygments to 2.7.1 +- Bumped coverage to 5.3 +- Bumped pydocstyle to 5.1.1 +- Bumped pre-commit to 2.7.1 +- Bumped pylint to 2.6.0 +- Bumped pytest-cov to 2.10.1 + + 0.16.3 (2020-08-02) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~