Added battery_string property to camera
Ability to detect if battery is "OK" or "Low"
This commit is contained in:
+3
-5
@@ -3,15 +3,13 @@ Changelog
|
|||||||
|
|
||||||
A list of changes between each release
|
A list of changes between each release
|
||||||
|
|
||||||
0.6.0.dev1 (unreleased)
|
0.6.0 (unreleased)
|
||||||
^^^^^^^^^^^^^^^^^^
|
|
||||||
- Added auto-reauthorization (token refresh) when a request fails due to an expired token
|
|
||||||
|
|
||||||
0.6.0.dev0 (unreleased)
|
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
- Removed redundent properties that only called hidden variables
|
- Removed redundent properties that only called hidden variables
|
||||||
- Revised request wrapper function to be more intelligent
|
- Revised request wrapper function to be more intelligent
|
||||||
- Added tests to ensure exceptions are caught and handled (100% coverage!)
|
- Added tests to ensure exceptions are caught and handled (100% coverage!)
|
||||||
|
- Added auto-reauthorization (token refresh) when a request fails due to an expired token (@TySwift93)
|
||||||
|
- Added battery level string to reduce confusion with the way Blink reports battery level as integer from 0 to 3
|
||||||
|
|
||||||
0.5.2 (2017-03-12)
|
0.5.2 (2017-03-12)
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|||||||
+10
@@ -111,6 +111,16 @@ class BlinkCamera(object):
|
|||||||
"""Return camera arm status."""
|
"""Return camera arm status."""
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
|
@property
|
||||||
|
def battery_string(self):
|
||||||
|
"""Return string indicating battery status."""
|
||||||
|
if self.battery > 1 and self.battery <= 3:
|
||||||
|
return "OK"
|
||||||
|
elif self.battery >= 0:
|
||||||
|
return "Low"
|
||||||
|
else:
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
def snap_picture(self):
|
def snap_picture(self):
|
||||||
"""Take a picture with camera to create a new thumbnail."""
|
"""Take a picture with camera to create a new thumbnail."""
|
||||||
_request(self.blink, url=self.image_link,
|
_request(self.blink, url=self.image_link,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import os
|
|||||||
|
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 6
|
MINOR_VERSION = 6
|
||||||
PATCH_VERSION = '0.dev1'
|
PATCH_VERSION = '0.dev2'
|
||||||
|
|
||||||
__version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
|
__version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
|
||||||
|
|
||||||
|
|||||||
+107
-101
@@ -1,101 +1,107 @@
|
|||||||
"""
|
"""
|
||||||
Tests the camera initialization and attributes of
|
Tests the camera initialization and attributes of
|
||||||
individual BlinkCamera instantiations.
|
individual BlinkCamera instantiations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
import blinkpy
|
import blinkpy
|
||||||
import tests.mock_responses as mresp
|
import tests.mock_responses as mresp
|
||||||
|
|
||||||
USERNAME = 'foobar'
|
USERNAME = 'foobar'
|
||||||
PASSWORD = 'deadbeef'
|
PASSWORD = 'deadbeef'
|
||||||
|
|
||||||
|
|
||||||
class TestBlinkCameraSetup(unittest.TestCase):
|
class TestBlinkCameraSetup(unittest.TestCase):
|
||||||
"""Test the Blink class in blinkpy."""
|
"""Test the Blink class in blinkpy."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Set up Blink module."""
|
"""Set up Blink module."""
|
||||||
self.blink = blinkpy.Blink(username=USERNAME,
|
self.blink = blinkpy.Blink(username=USERNAME,
|
||||||
password=PASSWORD)
|
password=PASSWORD)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""Clean up after test."""
|
"""Clean up after test."""
|
||||||
self.blink = None
|
self.blink = None
|
||||||
|
|
||||||
@mock.patch('blinkpy.blinkpy.requests.post',
|
@mock.patch('blinkpy.blinkpy.requests.post',
|
||||||
side_effect=mresp.mocked_requests_post)
|
side_effect=mresp.mocked_requests_post)
|
||||||
@mock.patch('blinkpy.blinkpy.requests.get',
|
@mock.patch('blinkpy.blinkpy.requests.get',
|
||||||
side_effect=mresp.mocked_requests_get)
|
side_effect=mresp.mocked_requests_get)
|
||||||
def test_camera_properties(self, mock_get, mock_post):
|
def test_camera_properties(self, mock_get, mock_post):
|
||||||
"""Tests all property set/recall."""
|
"""Tests all property set/recall."""
|
||||||
test_value = 'foobar'
|
test_value = 'foobar'
|
||||||
test_region_id = list(mresp.LOGIN_RESPONSE['region'].keys())[0]
|
test_region_id = list(mresp.LOGIN_RESPONSE['region'].keys())[0]
|
||||||
self.blink.setup_system()
|
self.blink.setup_system()
|
||||||
for name in self.blink.cameras:
|
for name in self.blink.cameras:
|
||||||
camera = self.blink.cameras[name]
|
camera = self.blink.cameras[name]
|
||||||
camera.name = test_value
|
camera.name = test_value
|
||||||
camera.clip = test_value + '.mp4'
|
camera.clip = test_value + '.mp4'
|
||||||
camera.thumbnail = test_value + '.jpg'
|
camera.thumbnail = test_value + '.jpg'
|
||||||
camera.temperature = 10
|
camera.temperature = 10
|
||||||
camera.battery = 0
|
camera.battery = 0
|
||||||
camera.notifications = 100
|
camera.notifications = 100
|
||||||
camera.image_link = test_value + '/image.jpg'
|
camera.image_link = test_value + '/image.jpg'
|
||||||
camera.arm_link = test_value + '/arm'
|
camera.arm_link = test_value + '/arm'
|
||||||
camera.header = {'foo': 'bar'}
|
camera.header = {'foo': 'bar'}
|
||||||
camera.motion = {'bar': 'foo'}
|
camera.motion = {'bar': 'foo'}
|
||||||
self.assertEqual(camera.clip, test_value + '.mp4')
|
self.assertEqual(camera.clip, test_value + '.mp4')
|
||||||
self.assertEqual(camera.name, test_value)
|
self.assertEqual(camera.name, test_value)
|
||||||
self.assertEqual(camera.thumbnail, test_value + '.jpg')
|
self.assertEqual(camera.thumbnail, test_value + '.jpg')
|
||||||
self.assertEqual(camera.temperature, 10)
|
self.assertEqual(camera.temperature, 10)
|
||||||
self.assertEqual(camera.battery, 0)
|
self.assertEqual(camera.battery, 0)
|
||||||
self.assertEqual(camera.notifications, 100)
|
self.assertEqual(camera.notifications, 100)
|
||||||
self.assertEqual(camera.image_link, test_value + '/image.jpg')
|
self.assertEqual(camera.image_link, test_value + '/image.jpg')
|
||||||
self.assertEqual(camera.arm_link, test_value + '/arm')
|
self.assertEqual(camera.arm_link, test_value + '/arm')
|
||||||
self.assertEqual(camera.header, {'foo': 'bar'})
|
self.assertEqual(camera.header, {'foo': 'bar'})
|
||||||
self.assertEqual(camera.motion, {'bar': 'foo'})
|
self.assertEqual(camera.motion, {'bar': 'foo'})
|
||||||
self.assertEqual(camera.region_id, test_region_id)
|
self.assertEqual(camera.region_id, test_region_id)
|
||||||
|
|
||||||
@mock.patch('blinkpy.blinkpy.requests.post',
|
self.assertEqual(camera.battery_string, "Low")
|
||||||
side_effect=mresp.mocked_requests_post)
|
camera.battery = 3
|
||||||
@mock.patch('blinkpy.blinkpy.requests.get',
|
self.assertEqual(camera.battery_string, "OK")
|
||||||
side_effect=mresp.mocked_requests_get)
|
camera.battery = -10
|
||||||
def test_camera_values_from_setup(self, mock_get, mock_post):
|
self.assertEqual(camera.battery_string, "Unknown")
|
||||||
"""Tests all property values after camera setup."""
|
|
||||||
self.blink.setup_system()
|
@mock.patch('blinkpy.blinkpy.requests.post',
|
||||||
|
side_effect=mresp.mocked_requests_post)
|
||||||
# Get expected test values
|
@mock.patch('blinkpy.blinkpy.requests.get',
|
||||||
test_network_id = str(mresp.NETWORKS_RESPONSE['networks'][0]['id'])
|
side_effect=mresp.mocked_requests_get)
|
||||||
# pylint: disable=unused-variable
|
def test_camera_values_from_setup(self, mock_get, mock_post):
|
||||||
(region_id, region), = mresp.LOGIN_RESPONSE['region'].items()
|
"""Tests all property values after camera setup."""
|
||||||
# pylint: disable=protected-access
|
self.blink.setup_system()
|
||||||
expected_header = self.blink._auth_header
|
|
||||||
test_urls = blinkpy.BlinkURLHandler(region_id)
|
# Get expected test values
|
||||||
|
test_network_id = str(mresp.NETWORKS_RESPONSE['networks'][0]['id'])
|
||||||
test_cameras = mresp.get_test_cameras(test_urls.base_url)
|
# pylint: disable=unused-variable
|
||||||
test_net_id_url = test_urls.network_url + test_network_id
|
(region_id, region), = mresp.LOGIN_RESPONSE['region'].items()
|
||||||
for name in self.blink.cameras:
|
# pylint: disable=protected-access
|
||||||
camera = self.blink.cameras[name]
|
expected_header = self.blink._auth_header
|
||||||
self.assertEqual(name, camera.name)
|
test_urls = blinkpy.BlinkURLHandler(region_id)
|
||||||
if name in test_cameras:
|
|
||||||
self.assertEqual(camera.id,
|
test_cameras = mresp.get_test_cameras(test_urls.base_url)
|
||||||
test_cameras[name]['device_id'])
|
test_net_id_url = test_urls.network_url + test_network_id
|
||||||
self.assertEqual(camera.armed,
|
for name in self.blink.cameras:
|
||||||
test_cameras[name]['armed'])
|
camera = self.blink.cameras[name]
|
||||||
self.assertEqual(camera.thumbnail,
|
self.assertEqual(name, camera.name)
|
||||||
test_cameras[name]['thumbnail'])
|
if name in test_cameras:
|
||||||
self.assertEqual(camera.temperature,
|
self.assertEqual(camera.id,
|
||||||
test_cameras[name]['temperature'])
|
test_cameras[name]['device_id'])
|
||||||
self.assertEqual(camera.battery,
|
self.assertEqual(camera.armed,
|
||||||
test_cameras[name]['battery'])
|
test_cameras[name]['armed'])
|
||||||
self.assertEqual(camera.notifications,
|
self.assertEqual(camera.thumbnail,
|
||||||
test_cameras[name]['notifications'])
|
test_cameras[name]['thumbnail'])
|
||||||
else:
|
self.assertEqual(camera.temperature,
|
||||||
self.fail("Camera wasn't initialized: " + name)
|
test_cameras[name]['temperature'])
|
||||||
|
self.assertEqual(camera.battery,
|
||||||
expected_arm_link = test_net_id_url + '/camera/' + camera.id + '/'
|
test_cameras[name]['battery'])
|
||||||
expected_image_link = expected_arm_link + 'thumbnail'
|
self.assertEqual(camera.notifications,
|
||||||
self.assertEqual(camera.image_link, expected_image_link)
|
test_cameras[name]['notifications'])
|
||||||
self.assertEqual(camera.arm_link, expected_arm_link)
|
else:
|
||||||
self.assertEqual(camera.header, expected_header)
|
self.fail("Camera wasn't initialized: " + name)
|
||||||
|
|
||||||
|
expected_arm_link = test_net_id_url + '/camera/' + camera.id + '/'
|
||||||
|
expected_image_link = expected_arm_link + 'thumbnail'
|
||||||
|
self.assertEqual(camera.image_link, expected_image_link)
|
||||||
|
self.assertEqual(camera.arm_link, expected_arm_link)
|
||||||
|
self.assertEqual(camera.header, expected_header)
|
||||||
|
|||||||
Reference in New Issue
Block a user