diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index 41f3220e..049f78ed 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -221,7 +221,7 @@ def setup_camera_list(self): all_cameras[camera_network] = [] for camera in network["cameras"]: all_cameras[camera_network].append( - {"name": camera["name"], "id": camera["id"]} + {"name": camera["name"], "id": camera["id"], "type": "default"} ) mini_cameras = self.setup_owls() lotus_cameras = self.setup_lotus() diff --git a/blinkpy/sync_module.py b/blinkpy/sync_module.py index 1873a7bd..64ea61ad 100644 --- a/blinkpy/sync_module.py +++ b/blinkpy/sync_module.py @@ -125,6 +125,7 @@ def update_cameras(self, camera_type=BlinkCamera): type_map = { "mini": BlinkCameraMini, "lotus": BlinkDoorbell, + "default": BlinkCamera, } try: for camera_config in self.camera_list: diff --git a/tests/test_blinkpy.py b/tests/test_blinkpy.py index 82d1c211..e7fba3ad 100644 --- a/tests/test_blinkpy.py +++ b/tests/test_blinkpy.py @@ -103,8 +103,11 @@ def test_setup_cameras(self, mock_home, mock_req): self.assertEqual( result, { - "1234": [{"name": "foo", "id": 5678}, {"name": "bar", "id": 5679}], - "4321": [{"name": "test", "id": 0000}], + "1234": [ + {"name": "foo", "id": 5678, "type": "default"}, + {"name": "bar", "id": 5679, "type": "default"}, + ], + "4321": [{"name": "test", "id": 0000, "type": "default"}], }, ) @@ -483,7 +486,7 @@ def test_blink_camera_mix(self, mock_usage): {"name": "bar", "id": "1234", "type": "doorbell"}, {"name": "dead", "id": "1234", "type": "mini"}, {"name": "beef", "id": "1234", "type": "mini"}, - {"name": "normal", "id": "1234"}, + {"name": "normal", "id": "1234", "type": "default"}, ] } mock_usage.return_value = { diff --git a/tests/test_sync_module.py b/tests/test_sync_module.py index 67d52061..39d1b67e 100644 --- a/tests/test_sync_module.py +++ b/tests/test_sync_module.py @@ -2,6 +2,8 @@ import unittest from unittest import mock +from random import shuffle + from blinkpy.blinkpy import Blink from blinkpy.helpers.util import BlinkURLHandler from blinkpy.sync_module import BlinkSyncModule, BlinkOwl, BlinkLotus @@ -309,3 +311,65 @@ def test_lotus_start(self, mock_resp): self.assertTrue(lotus.start()) self.assertTrue("doo" in lotus.cameras) self.assertEqual(lotus.cameras["doo"].__class__, BlinkDoorbell) + + def test_sync_with_mixed_cameras(self, mock_resp): + """Test sync module with mixed cameras attached.""" + resp_sync = { + "syncmodule": { + "network_id": 1234, + "id": 1, + "serial": 456, + "status": "onboarded", + } + } + resp_network_info = {"network": {"sync_module_error": False}} + resp_videos = {"media": []} + resp_empty = {} + + self.blink.sync["test"].camera_list = [ + {"name": "foo", "id": 10, "type": "default"}, + {"name": "bar", "id": 11, "type": "mini"}, + {"name": "fake", "id": 12, "type": "lotus"}, + ] + + self.blink.homescreen = { + "owls": [{"name": "bar", "id": 3}], + "doorbells": [{"name": "fake", "id": 12}], + } + + side_effect = [ + resp_sync, + resp_network_info, + resp_videos, + resp_empty, + resp_empty, + resp_empty, + resp_empty, + resp_empty, + resp_empty, + ] + + mock_resp.side_effect = side_effect + + test_sync = self.blink.sync["test"] + + self.assertTrue(test_sync.start()) + self.assertEqual(test_sync.cameras["foo"].__class__, BlinkCamera) + self.assertEqual(test_sync.cameras["bar"].__class__, BlinkCameraMini) + self.assertEqual(test_sync.cameras["fake"].__class__, BlinkDoorbell) + + # Now shuffle the cameras and see if it still works + for i in range(0, 10): + shuffle(test_sync.camera_list) + mock_resp.side_effect = side_effect + self.assertTrue(test_sync.start()) + debug_msg = f"Iteration: {i}, {test_sync.camera_list}" + self.assertEqual( + test_sync.cameras["foo"].__class__, BlinkCamera, msg=debug_msg + ) + self.assertEqual( + test_sync.cameras["bar"].__class__, BlinkCameraMini, msg=debug_msg + ) + self.assertEqual( + test_sync.cameras["fake"].__class__, BlinkDoorbell, msg=debug_msg + )