Skip to content

Commit

Permalink
Add type param for regular cameras, add test to check for mixed camera
Browse files Browse the repository at this point in the history
usage
  • Loading branch information
fronzbot committed Jun 26, 2022
1 parent 4703c54 commit 34a1d87
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion blinkpy/blinkpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions blinkpy/sync_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions tests/test_blinkpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}],
},
)

Expand Down Expand Up @@ -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 = {
Expand Down
64 changes: 64 additions & 0 deletions tests/test_sync_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

0 comments on commit 34a1d87

Please sign in to comment.