diff --git a/blinkpy/camera.py b/blinkpy/camera.py index fb54fbc1..72ddd11e 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -28,7 +28,7 @@ def __init__(self, sync): self.thumbnail = None self.serial = None self.motion_enabled = None - self.battery_voltage = None + self.battery_level = None self.clip = None # A clip remains in the recent clips list until is has # been downloaded or has been expired. @@ -56,7 +56,7 @@ def attributes(self): "temperature_c": self.temperature_c, "temperature_calibrated": self.temperature_calibrated, "battery": self.battery, - "battery_voltage": self.battery_voltage, + "battery_level": self.battery_level, "thumbnail": self.thumbnail, "video": self.clip, "recent_clips": self.recent_clips, @@ -237,12 +237,10 @@ def extract_config_info(self, config): self.temperature = config.get("temperature") if signals := config.get("signals"): self.wifi_strength = signals.get("wifi") - self.battery_voltage = signals.get("battery") + self.battery_level = signals.get("battery") self.sync_signal_strength = signals.get("lfr") else: self.wifi_strength = config.get("wifi_strength") - self.battery_voltage = config.get("battery_voltage") - self.product_type = config.get("type") async def get_sensor_info(self): diff --git a/tests/test_camera_functions.py b/tests/test_camera_functions.py index c7283d35..96e4f69f 100644 --- a/tests/test_camera_functions.py +++ b/tests/test_camera_functions.py @@ -15,15 +15,16 @@ from blinkpy.camera import BlinkCamera, BlinkCameraMini, BlinkDoorbell import tests.mock_responses as mresp -CAMERA_CFG = { - "camera": [ - { - "battery_voltage": 90, - "motion_alert": True, - "wifi_strength": -30, - "temperature": 68, - } - ] +CONFIG = { + "name": "new", + "id": 1234, + "network_id": 5678, + "serial": "12345678", + "enabled": False, + "battery_state": "ok", + "temperature": 68, + "signals": {"lfr": 5, "wifi": 4, "battery": 3}, + "thumbnail": "/thumb", } @@ -47,18 +48,6 @@ def tearDown(self): async def test_camera_update(self, mock_resp): """Test that we can properly update camera properties.""" - config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "signals": {"lfr": 5, "wifi": 4, "battery": 3}, - "thumbnail": "/thumb", - } self.camera.last_record = ["1"] self.camera.sync.last_records = { "new": [{"clip": "/test.mp4", "time": "1970-01-01T00:00:00"}] @@ -70,7 +59,7 @@ async def test_camera_update(self, mock_resp): ] self.assertIsNone(self.camera.image_from_cache) - await self.camera.update(config, expire_clips=False) + await self.camera.update(CONFIG, expire_clips=False) self.assertEqual(self.camera.name, "new") self.assertEqual(self.camera.camera_id, "1234") self.assertEqual(self.camera.network_id, "5678") @@ -107,17 +96,12 @@ async def test_no_thumbnails(self, mock_resp): mock_resp.return_value = "foobar" self.camera.last_record = ["1"] config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": "", + **CONFIG, + **{ + "thumbnail": "", + }, } + self.camera.sync.homescreen = {"devices": []} self.assertEqual(self.camera.temperature_calibrated, None) with self.assertLogs() as logrecord: @@ -144,16 +128,10 @@ async def test_no_video_clips(self, mock_resp): """Tests that we still proceed with camera setup with no videos.""" mock_resp.return_value = "foobar" config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": "/foobar", + **CONFIG, + **{ + "thumbnail": "/foobar", + }, } mock_resp.return_value = mresp.MockResponse({"test": 200}, 200, raw_data="") self.camera.sync.homescreen = {"devices": []} @@ -167,25 +145,13 @@ async def test_recent_video_clips(self, mock_resp): Tests that the last records in the sync module are added to the camera recent clips list. """ - config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": "/thumb", - } self.camera.sync.last_records["foobar"] = [] record2 = {"clip": "/clip2", "time": "2022-12-01 00:00:10+00:00"} self.camera.sync.last_records["foobar"].append(record2) record1 = {"clip": "/clip1", "time": "2022-12-01 00:00:00+00:00"} self.camera.sync.last_records["foobar"].append(record1) self.camera.sync.motion["foobar"] = True - await self.camera.update_images(config, expire_clips=False) + await self.camera.update_images(CONFIG, expire_clips=False) record1["clip"] = self.blink.urls.base_url + "/clip1" record2["clip"] = self.blink.urls.base_url + "/clip2" self.assertEqual(self.camera.recent_clips[0], record1) @@ -193,25 +159,13 @@ async def test_recent_video_clips(self, mock_resp): async def test_recent_video_clips_missing_key(self, mock_resp): """Tests that the missing key failst.""" - config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": "/thumb", - } self.camera.sync.last_records["foobar"] = [] record2 = {"clip": "/clip2"} self.camera.sync.last_records["foobar"].append(record2) self.camera.sync.motion["foobar"] = True with self.assertLogs(level="ERROR") as dl_log: - await self.camera.update_images(config, expire_clips=False) + await self.camera.update_images(CONFIG, expire_clips=False) self.assertIsNotNone(dl_log.output) @@ -412,15 +366,11 @@ async def test_save_recent_clips_exception(self, mock_clip, mock_open, mock_resp async def test_missing_keys(self, mock_resp): """Tests missing signal keys.""" config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_state": "ok", - "temperature": 68, - "signals": {"junk": 1}, - "thumbnail": "", + **CONFIG, + **{ + "signals": {"junk": 1}, + "thumbnail": "", + }, } self.camera.sync.homescreen = {"devices": []} mock_resp.side_effect = [ @@ -430,4 +380,4 @@ async def test_missing_keys(self, mock_resp): ] await self.camera.update(config, expire_clips=False, force=True) self.assertEqual(self.camera.wifi_strength, None) - self.assertEqual(self.camera.battery_voltage, None) + self.assertEqual(self.camera.battery_level, None) diff --git a/tests/test_cameras.py b/tests/test_cameras.py index 8689237f..e104d7cd 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -14,15 +14,17 @@ from blinkpy.camera import BlinkCamera, BlinkCameraMini, BlinkDoorbell import tests.mock_responses as mresp -CAMERA_CFG = { - "camera": [ - { - "battery_voltage": 90, - "motion_alert": True, - "wifi_strength": -30, - "temperature": 68, - } - ] +CONFIG = { + "name": "new", + "id": 1234, + "network_id": 5678, + "serial": "12345678", + "enabled": False, + "battery_state": "ok", + "temperature": 68, + "thumbnail": 1357924680, + "signals": {"lfr": 5, "wifi": 4, "battery": 3}, + "type": "test", } @@ -128,41 +130,21 @@ async def test_camera_stream(self, mock_resp): async def test_different_thumb_api(self, mock_resp): """Test that the correct url is created with new api.""" thumb_endpoint = "https://rest-test.immedia-semi.com/api/v3/media/accounts/9999/networks/5678/test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" - config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": 1357924680, - "type": "test", - } mock_resp.side_effect = [ {"temp": 71}, mresp.MockResponse({"test": 200}, 200, raw_data="test"), ] self.camera.sync.blink.account_id = 9999 - await self.camera.update(config, expire_clips=False) + await self.camera.update(CONFIG, expire_clips=False) self.assertEqual(self.camera.thumbnail, thumb_endpoint) async def test_thumb_return_none(self, mock_resp): """Test that a 'None" thumbnail is doesn't break system.""" config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": None, - "type": "test", + **CONFIG, + **{ + "thumbnail": None, + }, } mock_resp.side_effect = [ {"temp": 71}, @@ -178,17 +160,10 @@ async def test_new_thumb_url_returned(self, mock_resp): "test/1234/thumbnail/thumbnail.jpg?ts=1357924680&ext=" ) config = { - "name": "new", - "id": 1234, - "network_id": 5678, - "serial": "12345678", - "enabled": False, - "battery_voltage": 90, - "battery_state": "ok", - "temperature": 68, - "wifi_strength": 4, - "thumbnail": thumb_return, - "type": "test", + **CONFIG, + **{ + "thumbnail": thumb_return, + }, } mock_resp.side_effect = [ {"temp": 71},