Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #76 from tchellomello/fix_nonetype
Browse files Browse the repository at this point in the history
Fixes AttributerError when requests failed to get a response
  • Loading branch information
tchellomello authored Jun 5, 2018
2 parents 5bdc358 + c846f4f commit 763116e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pyarlo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ def lookup_camera_by_id(self, device_id):
def refresh_attributes(self, name):
"""Refresh attributes from a given Arlo object."""
url = DEVICES_ENDPOINT
data = self.query(url).get('data')
for device in data:
response = self.query(url)

if not response or not isinstance(response, dict):
return None

for device in response.get('data'):
if device.get('deviceName') == name:
return device
return None
Expand Down Expand Up @@ -244,9 +248,12 @@ def update(self, update_cameras=False, update_base_station=False):
# update attributes in all cameras to avoid duped queries
if update_cameras:
url = DEVICES_ENDPOINT
data = self.query(url).get('data')
response = self.query(url)
if not response or not isinstance(response, dict):
return

for camera in self.cameras:
for dev_info in data:
for dev_info in response.get('data'):
if dev_info.get('deviceName') == camera.name:
_LOGGER.debug("Refreshing %s attributes", camera.name)
camera.attrs = dev_info
Expand Down

0 comments on commit 763116e

Please sign in to comment.