From 623b694c7876d8c830dcdab7629e2202f72b3dfb Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Thu, 8 Feb 2018 16:16:23 -0500 Subject: [PATCH] Added attributes property to camera object --- CHANGES.rst | 1 + README.rst | 9 +-------- blinkpy/blinkpy.py | 17 +++++++++++++++++ tests/test_blink_cameras.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7499e44..c547168 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,7 @@ A list of changes between each release - Added ability to download most recent video clip - Improved camera arm/disarm handling (`@b10m `_) - Added authentication to ``login()`` function and deprecated ``setup_system()`` in favor of ``start()`` +- Added ``attributes`` dictionary to camera object 0.6.0 (2017-05-12) ^^^^^^^^^^^^^^^^^^ diff --git a/README.rst b/README.rst index c16bac5..52b765d 100644 --- a/README.rst +++ b/README.rst @@ -59,14 +59,7 @@ The cameras are of a BlinkCamera class, of which the following parameters can be for name, camera in blink.cameras.items(): print(name) # Name of the camera - print(camera.id) # Integer id of the camera (assigned by Blink) - print(camera.armed) # Whether the device is armed/disarmed (ie. detecting motion) - print(camera.clip) # Link to last motion clip captured - print(camera.thumbnail) # Link to current camera thumbnail - print(camera.temperature) # Current camera temperature (not super accurate, but might be useful for someone) - print(camera.battery) # Current battery level... I think the value ranges from 0-3, but not quite sure yet. - print(camera.battery_string) # Gives battery level as a string ("OK" or "Low"). Returns "Unknown" if value is... well, unknown - print(camera.notifications) # Number of unread notifications (ie. motion alerts that haven't been viewed) + print(camera.attributes) # Print available attributes of camera .. |Build Status| image:: https://travis-ci.org/fronzbot/blinkpy.svg?branch=dev diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index 84231b1..f8b7396 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -115,6 +115,23 @@ class BlinkCamera(object): self.arm_link = None self.region_id = config['region_id'] + @property + def attributes(self): + """Return dictionary of all camera attributes.""" + attributes = { + 'name': self.name, + 'device_id': self.id, + 'status': self._status, + 'armed': self.armed, + 'temperature': self.temperature, + 'battery': self.battery, + 'thumbnail': self.thumbnail, + 'video': self.clip, + 'notifications': self.notifications, + 'network_id': self.blink.network_id + } + return attributes + @property def status(self): """Return camera status.""" diff --git a/tests/test_blink_cameras.py b/tests/test_blink_cameras.py index 475509c..859a2cf 100644 --- a/tests/test_blink_cameras.py +++ b/tests/test_blink_cameras.py @@ -36,6 +36,7 @@ class TestBlinkCameraSetup(unittest.TestCase): 'region_id': 'test' } self.blink.urls = blinkpy.BlinkURLHandler('test') + self.blink.network_id = '0000' def tearDown(self): """Clean up after test.""" @@ -105,3 +106,30 @@ class TestBlinkCameraSetup(unittest.TestCase): camera_object = blinkpy.BlinkCamera(self.camera_config, self.blink) self.blink.cameras['foobar'] = camera_object self.assertEqual(camera_object, self.blink.cameras['fOoBaR']) + + def test_camera_attributes(self): + """Tests camera attributes.""" + self.blink.urls = blinkpy.BlinkURLHandler('test') + + self.blink.cameras = { + 'foobar': blinkpy.BlinkCamera(self.camera_config, self.blink) + } + + for name in self.blink.cameras: + camera = self.blink.cameras[name] + camera_attr = camera.attributes + self.assertEqual(camera_attr['device_id'], '1111') + self.assertEqual(camera_attr['name'], 'foobar') + self.assertEqual(camera_attr['armed'], False) + self.assertEqual( + camera_attr['thumbnail'], + "https://rest.test.{}/test/image.jpg".format(BLINK_URL) + ) + self.assertEqual( + camera_attr['video'], + "https://rest.test.{}/test/clip/clip.mp4".format(BLINK_URL) + ) + self.assertEqual(camera_attr['temperature'], 70) + self.assertEqual(camera_attr['battery'], 3) + self.assertEqual(camera_attr['notifications'], 2) + self.assertEqual(camera_attr['network_id'], '0000')