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

Commit

Permalink
Returning camera base_station as property for cameras ArloCamera (#60)
Browse files Browse the repository at this point in the history
* Returning camera base_station as property for cameras ArloCamera

* Updated README
  • Loading branch information
tchellomello authored Oct 25, 2017
1 parent d8a32ce commit 2e0092a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ Usage
cam.unseen_videos
# get brightness value of camera
cam.get_brightness
cam.brightness
# get signal strength of camera with base station
cam.get_signal_strength
cam.signal_strength
# get flip property from camera
cam.get_flip_state
cam.flip_state
# get mirror property from camera
cam.get_mirror_state
cam.mirror_state
# get power save mode value from camera
cam.get_powersave_mode
cam.powersave_mode
# get current battery level of camera
cam.get_battery_level
cam.battery_level
92
# get boolean result if motion detection
Expand All @@ -96,10 +96,10 @@ Usage
# get battery levels of all cameras
# prints serial number and battery level of each camera
base.get_camera_battery_level # {'4N71235T12345': 92, '4N71235T12345': 90}
base.get_cameras_battery_level # {'4N71235T12345': 92, '4N71235T12345': 90}
# get base station properties
base.get_basestation_properties
base.properties
# get camera properties
base.get_camera_properties
Expand Down
32 changes: 19 additions & 13 deletions pyarlo/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def hw_version(self):
"""Return hardware version."""
return self._attrs.get('properties').get('hwVersion')

@property
def parent_id(self):
"""Return camera parentID."""
return self._attrs.get('parentId')

@property
def timezone(self):
"""Return timezone."""
Expand Down Expand Up @@ -125,17 +130,21 @@ def xcloud_id(self):
"""Return X-Cloud-ID attribute."""
return self._attrs.get('xCloudId')

@property
def base_station(self):
"""Return the base_station assigned for the given camera."""
try:
return list(filter(lambda x: x.device_id == self.parent_id,
self._session.base_stations))[0]
except IndexError:
return None

def _get_camera_properties(self):
"""Lookup camera properties from base station."""
base_stations = self._session.base_stations

if base_stations:
base = base_stations[0]

if base.camera_properties:
for cam in base.camera_properties:
if cam["serialNumber"] == self.device_id:
return cam
if self.base_station and self.base_station.camera_properties:
for cam in self.base_station.camera_properties:
if cam["serialNumber"] == self.device_id:
return cam
return None

@property
Expand Down Expand Up @@ -274,9 +283,6 @@ def update(self):
self._attrs = self._session.refresh_attributes(self.name)

# force base_state to update properties
base_stations = self._session.base_stations
if base_stations:
base = base_stations[0]
base.update()
self.base_station.update()

# vim:sw=4:ts=4:et:
4 changes: 4 additions & 0 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def test_camera_properties(self, mock):
basestation.update()
self.assertEqual(len(cameras), 2)
for camera in cameras:

camera.update()

self.assertTrue(camera.__repr__().startswith("<ArloCamera:"))
self.assertIsNone(arlo.refresh_attributes(camera))
self.assertIsInstance(camera, ArloCamera)
Expand All @@ -61,11 +63,13 @@ def test_camera_properties(self, mock):
self.assertEqual(camera.user_role, "ADMIN")
self.assertTrue(len(camera.captured_today), 1)
self.assertIsNotNone(camera.properties)
self.assertEqual(camera.base_station, basestation)

if camera.name == "Front Door":
self.assertTrue(camera.device_id, "48B14CAAAAAAA")
self.assertEqual(camera.unique_id, "235-48B14CAAAAAAA")
self.assertEqual(camera.unseen_videos, 39)
self.assertEqual(camera.parent_id, "48B14CBBBBBBB")
self.assertEqual(camera.xcloud_id, "1005-123-999999")
self.assertEqual(camera.serial_number, camera.device_id)

Expand Down

0 comments on commit 2e0092a

Please sign in to comment.