Merge pull request #56 from fronzbot/camera-attributes

Camera attributes
This commit is contained in:
Kevin Fronczak
2018-02-08 16:22:14 -05:00
committed by GitHub
4 changed files with 47 additions and 8 deletions
+1
View File
@@ -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 <https://github.com/fronzbot/blinkpy/pull/50>`_)
- 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)
^^^^^^^^^^^^^^^^^^
+1 -8
View File
@@ -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
+17
View File
@@ -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."""
+28
View File
@@ -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')