Skip to content

Commit

Permalink
Merge pull request #550 from fronzbot/fix-broken-thumb
Browse files Browse the repository at this point in the history
Use urljoin to create thumbnail string
  • Loading branch information
fronzbot authored Mar 6, 2022
2 parents 0a03836 + 519bcec commit dc492ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions blinkpy/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dc492ed

Please sign in to comment.