Skip to content

Commit

Permalink
Merge pull request #738 from mkmer/handle-None-response
Browse files Browse the repository at this point in the history
Handle None response in camera.py
  • Loading branch information
fronzbot authored Aug 16, 2023
2 parents 9129e76 + 5756dc4 commit 50b395d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions blinkpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,14 @@ async def http_get(
:param is_retry: Is this part of a re-auth attempt?
"""
_LOGGER.debug("Making GET request to %s", url)
response = await blink.auth.query(
return await blink.auth.query(
url=url,
headers=blink.auth.header,
reqtype="get",
stream=stream,
json_resp=json,
is_retry=is_retry,
)
return response


async def http_post(blink, url, is_retry=False, data=None, json=True, timeout=TIMEOUT):
Expand Down
17 changes: 8 additions & 9 deletions blinkpy/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import copy
import string
import os
from aiofiles import open
import logging
import datetime
from json import dumps
import aiohttp
import traceback
import aiohttp
from aiofiles import open
from requests.compat import urljoin
from blinkpy import api
from blinkpy.helpers.constants import TIMEOUT_MEDIA
Expand Down Expand Up @@ -148,7 +148,7 @@ async def async_set_night_vision(self, value):
product_type=self.product_type,
data=data,
)
if res.status == 200:
if res and res.status == 200:
return await res.json()
return None

Expand Down Expand Up @@ -186,14 +186,13 @@ async def get_video_clip(self, url=None):
if not url:
_LOGGER.warning(f"Video clip URL not available: self.clip={url}")
return None
response = await api.http_get(
return await api.http_get(
self.sync.blink,
url=url,
stream=True,
json=False,
timeout=TIMEOUT_MEDIA,
)
return response

async def snap_picture(self):
"""Take a picture with camera to create a new thumbnail."""
Expand Down Expand Up @@ -326,12 +325,12 @@ def timest(record):

if new_thumbnail is not None and (update_cached_image or force_cache):
response = await self.get_media()
if response.status == 200:
if response and response.status == 200:
self._cached_image = await response.read()

if clip_addr is not None and (update_cached_video or force_cache):
response = await self.get_media(media_type="video")
if response.status == 200:
if response and response.status == 200:
self._cached_video = await response.read()

# Don't let the recent clips list grow without bound.
Expand Down Expand Up @@ -374,7 +373,7 @@ async def image_to_file(self, path):
"""
_LOGGER.debug("Writing image from %s to %s", self.name, path)
response = await self.get_media()
if response.status == 200:
if response and response.status == 200:
async with open(path, "wb") as imgfile:
await imgfile.write(await response.read())
else:
Expand Down Expand Up @@ -418,7 +417,7 @@ async def save_recent_clips(
path = os.path.join(output_dir, file_name)
_LOGGER.debug(f"Saving {clip_addr} to {path}")
media = await self.get_video_clip(clip_addr)
if media.status == 200:
if media and media.status == 200:
async with open(path, "wb") as clip_file:
await clip_file.write(await media.read())
num_saved += 1
Expand Down

0 comments on commit 50b395d

Please sign in to comment.