diff --git a/README.rst b/README.rst index 01d548e..b128058 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 diff --git a/pyarlo/camera.py b/pyarlo/camera.py index 80f33b4..b2d2e9f 100644 --- a/pyarlo/camera.py +++ b/pyarlo/camera.py @@ -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.""" @@ -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 @@ -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: diff --git a/tests/test_camera.py b/tests/test_camera.py index fdbf0de..cf8145e 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -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("